如何使用SBT编译Java 8源 [英] How do I compile Java 8 sources with SBT
问题描述
我正在尝试使用SBT 0.13.7使用lambda编译包含一些Java 8源文件的项目. 现在,我设置
I am trying to compile a project containing some Java 8 source files using lambdas using SBT 0.13.7. Now, I set
-java-home /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Home
在
/usr/local/etc/sbtopts
显然SBT确实考虑了这一点,因为如果我提供了错误的路径,它会抱怨不存在Java.
And apparently SBT does take this into consideration, because if I supply the wrong path it complains about no java being present.
但是,当我尝试编译时,会得到以下内容
However, when I try compiling, I get the following
[error] /Users/edafinov/GitRepos/Java8SBTTest/src/main/java/Main.java:10: error: illegal start of expression
[error] new ArrayList<Integer>().stream().filter(i -> i%2 ==0).count();
[error] ^
[error] 1 error
[error] (compile:compile) javac returned nonzero exit code
[error] Total time: 1 s, completed Dec 26, 2014 12:28:55 PM
这似乎表明SBT不使用javac 1.8,而是使用1.7(这是我的系统的默认值).
This seems to indicate that SBT does not use javac 1.8, but rather the 1.7 one which is the default one for my system.
我在做什么错了?
提前谢谢
推荐答案
显然,如果路径中包含JDK,即使您已显式设置-java-home选项,SBT也会尝试使用该JDK.我通过从$ PATH中删除默认的JDK解决了我的问题
Apparently if you have a JDK in the path, SBT would try to use that one, even when you have explicitly set the -java-home option. I solved my problem by removing the default JDK from $PATH
这篇关于如何使用SBT编译Java 8源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!