我似乎无法让Maven使用Java 1.8。使用1.8作为目标会出现以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
(default-compile) on project csaro: Fatal error compiling: invalid target
release: 1.8 -> [Help 1]
错误的原因很明显:Maven没有使用正确的Java版本:
$ mvn -version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T07:51:42-06:00)
Maven home: /usr/local/Cellar/maven/3.2.2/libexec
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"
但是Java的安装版本应为1.8:
$ java -version
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b22)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b21, mixed mode)
并设置JAVA_HOME:
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
我也在这里尝试了命令(创建mavenrc
)。我尝试过多次重启计算机,并验证了正确设置了env var(在中设置了.bash_profile
)。
Maven与Homebrew一起安装。
Java 1.8在Eclipse(使用m2e)中运行良好。我只是无法让Maven在命令行上工作。