Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use javaOptions from build.sbt during runtime

I've put some javaOptions in build.sbt which are used while running tests. These are working as expected.

javaOptions in Test += "-Dconfig.file=conf/test.conf"
javaOptions in Test += "-Duser.timezone=UTC"

I want to use something similar during runtime as well. I've tried the following and they don't work at all:

javaOptions in Runtime += "-Duser.timezone=UTC"
javaOptions in run += "-Duser.timezone=UTC"

I'm running the tests/application from command line using "activator test" and "activator run". Since the javaOptions are not working, the only other option is to pass them in the command line as: "activator run -Duser.timezone=UTC". I prefer not passing the command line arguments.

like image 471
WarLord Avatar asked Jun 15 '16 06:06

WarLord


1 Answers

javaOptions are only applied to a forked JVM.

> help javaOptions
Options passed to a new JVM when forking.

The reason why it is working in your tests is that Playframework by default runs your test in a forked JVM in parallel.

> show test:fork
[info] true

If you want to achieve this for the run task as well you can use a forked JVM as well. Add the following to build.sbt file:

 fork in run := true

See chapter on Forking in SBT documentation for further details: http://www.scala-sbt.org/0.13/docs/Forking.html

like image 74
Alexander B Avatar answered Oct 10 '22 21:10

Alexander B