Maven在OSX上忽略了JAVA_HOME?

时间:2014-11-19 20:16:35

标签: java macos maven

由于某些原因,Maven忽略了OSX上的JAVA_HOME。

我最近从java 8 build 11升级到java 8 build 25并因为25中的错误修复而删除了11。

我已更新JAVA_HOME

:~ > echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

javajavac都报告了正确的版本:

:~ > java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

:~ > javac -version
javac 1.8.0_25

libexec是正确的:

:~ > /usr/libexec/java_home 
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

CurrentJDK符号链接是正确的:

:~ > ls -la /System/Library/Frameworks/JavaVM.framework/Versions/
total 64
drwxr-xr-x  11 root  wheel   374B Nov 19 14:35 ./
drwxr-xr-x  12 root  wheel   408B Sep 23 14:29 ../
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.4@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.4.2@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.5@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.5.0@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.6@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.6.0@ -> CurrentJDK
drwxr-xr-x   8 root  wheel   272B Jul 29 18:41 A/
lrwxr-xr-x   1 root  wheel     1B Jul 28 14:50 Current@ -> A
lrwxr-xr-x   1 root  wheel    58B Nov 19 14:35 CurrentJDK@ -> /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents

但Maven仍然试图达到1.8.0_11:

:~ > mvn -version
Error: JAVA_HOME is not defined correctly.
  We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/bin/java

运行OSX Mavericks。

知道为什么Maven忽略了JAVA_HOME

2 个答案:

答案 0 :(得分:22)

一位同事告诉我问题是什么。他不想要回复点,所以我只是通过谷歌发现这个问题的答案。

解决方案是

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

in

~/.mavenrc

显然无论出于何种原因,maven都会获得自己的个人资料文件。使用上述值创建上述文件会立即修复问题:

:~ > mvn -version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T16:58:10-04:00)
Maven home: /usr/local/Cellar/maven/3.2.3/libexec
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"

答案 1 :(得分:2)

我通过添加

解决了这个问题

export JAVA_HOME="$(/usr/libexec/java_home)"

~/.mavenrc

Apple建议使用/usr/libexec/java_home而不是使用Java的整个路径