Friday, June 20, 2014

sbt: Compile Using non-default JDK in Mac OS X

sbt uses the default JDK when compiling projects. In OSX that means the value returned from calling
/usr/libexec/java_home

I use jenv to manage Java versions on OSX. Note that changing the default java version using "jenv local" or "jenv global" does not work. Although you control the version of Java used to launched sbt, during compilation sbt will still use the version of java from /usr/libexec/java_home

Set JAVA_HOME

The trick is to set the JAVA_HOME environment variable


$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/HOME

When you start sbt, make sure you prepend your chosen JVM directory's bin/ directory into $PATH


$ PATH=$JAVA_HOME/bin:$PATH sbt  


No comments:

Post a Comment