mvn不会识别正确的java

时间:2015-09-22 03:05:21

标签: java macos maven unsupported-class-version

所以我和这个家伙有完全相同的问题:

Maven Installation OSX Error Unsupported major.minor version 51.0

那里没有任何东西对我有用....我认为问题出在我的符号链接中。我在.bash_profile中定义了$ JAVA_HOME,并且java -version正确地报告了该版本。但是,出于某种原因,mvn正在尝试使用旧版本的java。

这是我机器上所有内容的列表:

/usr/libexec/java_home -verbose
Matching Java Virtual Machines (5):
    1.8.0_40, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
    1.7.0_79, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
    1.7.0_75, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
    1.6.0_65-b14-466.1, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-466.1, i386:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

我想使用1.8。并且mvn认识它。

如果我这样做:

ls -l `which java`
lrwxr-xr-x  1 root  wheel  74 May 24 22:46 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

然后如果我跑:

/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

我注意到这个符号链接乱序:

cd /System/Library/Frameworks/JavaVM.framework/Versions
ls -l
total 64
lrwxr-xr-x  1 root  wheel   10 May 24 22:46 1.4 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 May 24 22:46 1.4.2 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 May 24 22:46 1.5 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 May 24 22:46 1.5.0 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 May 24 22:46 1.6 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 May 24 22:46 1.6.0 -> CurrentJDK
drwxr-xr-x  7 root  wheel  238 May 24 22:46 A
lrwxr-xr-x  1 root  wheel    1 May 24 22:46 Current -> A
lrwxr-xr-x  1 root  wheel   59 May 24 22:46 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

是" CurrentJDK"实际上用在哪里?我该如何更新链接?

我无法理解发生了什么......一切似乎都指向了新的Java,mvn在哪里以及如何阅读Java 6(不支持的major.minor版本51.0)?

1 个答案:

答案 0 :(得分:0)

/System/Library/Frameworks/JavaVM.framework/Versions中的符号链接指向旧的JDK。

运行这些命令修复它:

cd /System/Library/Frameworks/JavaVM.framework/Versions 
sudo rm CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/ CurrentJDK