maven java 不识别,无法让Maven识别Java 1.8

I can't seem to be able to get Maven to use Java 1.8. Using 1.8 as the target turns up the following error:

[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]

The cause of the error is obvious enough: Maven isn't using the right version of 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"

But the installed version of Java should be 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)

And JAVA_HOME is set:

$ echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home

I also tried the command here (which creates mavenrc). I've tried restarting the computer several times, and have verified that the env var is correctly set (it's set in .bash_profile).

Maven was installed with Homebrew.

Java 1.8 is working fine in Eclipse (which is using m2e). I just can't get Maven to work on the command line.

解决方案

It turns out that I had a forgotten ~/.mavenrc file that had set the value of JAVA_HOME.

For future readers, check the following locations for places that may override JAVA_HOME (in ascending order of precedence):

~/.bash_profile

~/.bash_login

~/.bashrc

~/.profile

/etc/mavenrc

~/.mavenrc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值