maven在Mac OS X上没有使用Java

时间:2015-06-11 08:25:23

标签: java macos maven

我为Mac OS X下载了最新版本的JDK8,并且还安装了maven。但是,我似乎在Java和maven之间存在不兼容性:

myusername$ mvn -version
    Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:254)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
        at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:144)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:266)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

我正在使用:

myusername$ javac -version
javac 1.8.0_45

如何让Java和maven相互兼容?

尝试了可能重复的问题的说明:Maven Installation OSX Error Unsupported major.minor version 51.0

myusername$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.6.0_65.jdk/Contents/Home
myusername$ mvn -version
Error: JAVA_HOME is not defined correctly.
  We cannot execute /Library/Java/JavaVirtualMachines/jdk1.6.0_65.jdk/Contents/Home/bin/java

2 个答案:

答案 0 :(得分:8)

Mac上{1.6} Java版本的JAVA_HOME /Library/Java/Home只安装了Java 7及更高版本/Library/Java/JavaVirtualMachines

执行/usr/libexec/java_home -version 1.8以获取当前的1.8 Java Home。我使用export JAVA_HOME=$(/usr/libexec/java_home -version 1.8)来设置正确的JAVA_HOME

答案 1 :(得分:1)

无论我选择哪种JVM目标,我都得到了同样的错误。解决方案是downgrade maven

brew uninstall maven
brew tap homebrew/versions
brew install maven30