Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

scala - Setting up sbt to use Java 7 for compilation?

I'm getting compile errors when running the compile task as the sources reference new classes in java.nio.file package that only appeared in Java 7.

I have the following in build.sbt:

javaHome := Some(file("/opt/jdk/jdk1.7.0"))

fork := true

In sbt:

> show java-home
[info] Some(/opt/jdk/jdk1.7.0)

It compiles and runs fine in Eclipse. How can I set up sbt to use Java 7 for compilation?

question from:https://stackoverflow.com/questions/7701692/setting-up-sbt-to-use-java-7-for-compilation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The most reliable (perhaps only) way to do this at the moment it to start SBT with java in the JDK7 folder.

Modify your sbt launcher script; or use this one that allows you to specify Java Home (and so much more!) as command line options.

~/code/scratch/20111009 sbt -java-home /Library/Java/JavaVirtualMachines/openjdk-1.7-x86_64/Contents/Home
Starting sbt: invoke with -help for other options
[info] Loading global plugins from /Users/jason/.sbt/plugins
[info] Set current project to default-3e990a (in build file:/Users/jason/code/scratch/20111009/)
> console
[info] Compiling 1 Scala source to /Users/jason/code/scratch/20111009/target/scala-2.9.1/classes...
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.9.1.final (OpenJDK 64-Bit Server VM, Java 1.7.0-internal).
Type in expressions to have them evaluated.
Type :help for more information.

scala> java.util.Objects.equals(null, null)
res0: Boolean = true

Simply setting javaHome := Some(file("/Library/Java/JavaVirtualMachines/openjdk-1.7-x86_64/Contents/Home")) changes the Java version used to compile and fork processes, but does not change the version of the Java standard library on the classpath, nor the version used to run tests, which are always run the the same JVM as SBT.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...