无法让Maven识别Java 1.8 [英] Can't get Maven to recognize Java 1.8

查看:147
本文介绍了无法让Maven识别Java 1.8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让Maven使用Java 1.8。使用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]

错误的原因很明显:Maven没有使用正确的版本of Java:

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"

但已安装的版本Java应该是1.8:

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)

设置JAVA_HOME:

And JAVA_HOME is set:

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home

我也试过命令在这里(创建 mavenrc )。我已尝试多次重启计算机,并已验证env var已正确设置(在 .bash_profile 中设置)。

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与Homebrew一起安装。

Maven was installed with Homebrew.

Java 1.8在Eclipse中工作正常(使用m2e)。我只是不能让Maven在命令行上工作。

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

推荐答案

事实证明我忘记了〜/ .mavenrc 设置了 JAVA_HOME 的值的文件。

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

对于未来的读者,请检查以下位置以查找可能覆盖 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

  • ~/.bash_profile
  • ~/.bash_login
  • ~/.bashrc
  • ~/.profile
  • /etc/mavenrc
  • ~/.mavenrc

这篇关于无法让Maven识别Java 1.8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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