thesamet
thesamet

Reputation: 6582

How to pass javaOptions to "play run" through Build.scala

I would like to pass a -Dconfig.file=conf/dev.conf parameter to my application through Build.scala when I use the run command.

I am trying to put something like in this in my Build.scala:

val mySettings = Seq(
  (javaOptions in run) ++= Seq("-Dconfig.file=conf/dev.conf")
)

val main = play.Project(appName, appVersion, appDependencies).settings(
  mySettings: _*
)

But it doesn't - from what I've gathered this is because SBT doesn't fork a new JVM when I use run. Any workarounds except of setting an environment variable?

Upvotes: 8

Views: 3234

Answers (2)

Eugene Yokota
Eugene Yokota

Reputation: 95624

As @Sebastien Lorber has answered,

fork in run := true

should do the trick. Also see How can I create a custom run task, in addition to run? in FAQ.

Upvotes: 0

Sebastien Lorber
Sebastien Lorber

Reputation: 92150

The matter seems to be that Play runs in the same JVM as the SBT JVM so the Java options set in SBT are not used.

You can try something like:

  • Use fork in run := true so that a new JVM is spawn, using the Java options you give

  • Launch SBT with -Dconfig.file=conf/dev.conf

  • Set system property manually before running the app in the same JVM: System.setProperty("config.file","conf/dev.conf")

I'm not sure all these solutions work but it's worth trying them

Upvotes: 2

Related Questions