我似乎无法让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
文件)。我试过几次重新启动电脑,并确认环境变量已正确设置(在.bash_profile
中设置)。
Maven是使用Homebrew安装的。
Java 1.8在Eclipse中工作正常(使用m2e)。我只是无法让Maven在命令行中工作。
https://www.quora.com/How-do-I-turn-off-the-rootless-in-OS-X-El-Capitan-10-11
- raoulsson