Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass JVM options to SBT to use when running the app or test cases?

Tags:

I would like to specify JVM options when running my app or the tests for the app through SBT. Specifically, I need to be able to give the JVM the -Djava.security.policy parameter so that my policy is loaded and used for the test.

How can I do this with SBT?

like image 874
David Eagen Avatar asked Aug 19 '11 12:08

David Eagen


People also ask

Where do I put JVM options?

The directory server provides a means of configuring the Java Virtual Machine (JVM) and Java options for each command-line utility and for the directory server itself. The Java configuration is provided in a properties file, located at instance-dir /OUD/config/java.

Does sbt test compile?

We have a build. sbt file that is used for multiple projects. Doing sbt test:compile compiled the tests for every single project and took over 30 minutes.


1 Answers

With xsbt, you could run your test in a forked JVM (because of one of the reasons mentioned in "Running Project Code".

If you are using a forked jvm:

specify the configuration to affect only the main or test run tasks:

scala javaOptions in (Test,run) += "-Xmx8G" 

You should be able to specify any other options to that JVM through javaOptions.


The OP David Eagen reports that the following configuration didn't work at first, not because of the sbt options, but because of the path:

lazy val escacheServer = 
  Project( "escache-server", 
           file("server"), 
           settings = buildSettings ++ Seq(resolvers ++= 
                        Seq(scala_tools_snapshots, typesafe_repo), 
                        libraryDependencies ++= escacheServerDeps, 
                        javaOptions in run += "-Djava.security.policy=jini.policy", 
                        fork in run := true 
                      ) 
         ).dependsOn(escache) }

It looks like my problem was that jini.policy wasn't found in the current directory.
I set the full path and now it runs.

like image 77
VonC Avatar answered Sep 30 '22 18:09

VonC