I have a Scala 2.10.3 project that uses Swing. I have the following catch-22 situation:
I can compile with
$ sbt -java-home /usr/lib/jvm/java-6-openjdk-amd64/ test:products
But when I try to run:
$ sbt run
sbt
figures that the JVM version changes, and tries to recompile everything, thus throwing a compile error due to the first problem.
How can I convince sbt
to run my project that was already compiled, although using a different JVM? Using assembly
is not an option, because that takes several minutes, and I need to do this a lot.
I also tried to switch using export JAVA_HOME
, but this has the same effect, sbt will try to recompile upon run
.
You can use the javaHome
key, scoped to the run
task, to control the JDK used when running.
Assuming you run SBT with JDK6, as in:
sbt -java-home /usr/lib/jvm/java-6-openjdk-amd64/
Add a custom location for javaHome
in your build.sbt
:
// no custom Java_HOME without forking
fork in run := true
// your JDK7 install
javaHome in run := Some(file("/usr/lib/jvm/java-7-openjdk-amd64/"))
compile
will then use JDK6, and run
JDK7. You can also remove in run
in the above definitions to have it apply to both run
and test
.
See the Forking section of the SBT documentation for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With