如何使用 SBT 编译 Java 8 源代码 [英] How do I compile Java 8 sources with SBT

查看:37
本文介绍了如何使用 SBT 编译 Java 8 源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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,SBT 会尝试使用那个,即使您已经明确设置了 -java-home 选项.我通过从 $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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆