Maven InstallationOSX 错误不支持 Major. small 版本51.0

我通过以下步骤安装了 maven: (一个教程)

JAVA_HOME=/Library/Java/Home
export M2_HOME=/Users/steven/zimmermann/maven
export M2=$M2_HOME/bin
export PATH=$M2:$PATH


echo $JAVA_HOME
echo $M2_HOME
echo $M2
echo $PATH


nano .bash_profile

然后我在.bash _ profile 中写了回声,如下所示:

JAVA_HOME=/usr/libexec/java_home
M2_HOME=/path/to/your/apache-maven-3.x.x
M2=/path/to/your/apache-maven-3.x.x/bin
PATH=/path/to/maven/bin:/$….bla-bla-bla…

我还在.bashrc 中写了这个

export M2_HOME=/Users/steven/zimmermann/maven
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

now when I want to check the version (mvn -v) I get the following exception: 我觉得有些版本是错的,但我不知道。

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)

附加信息:

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)
javac -version
javac 1.8.0_40
101100 次浏览

请尝试一下:

$JAVA_HOME/bin/java -version

Maven 使用 $JAVA_HOME解析 JRE 库的类路径。 为了确保使用某个 JDK,可以在编译之前显式地设置它,例如:

export JAVA_HOME=/usr/java/jdk1.7.0_51

是不是有一个版本 < 1.7并且您正在使用 Maven3.3.1?在这种情况下,原因是一个新的先决条件: https://issues.apache.org/jira/browse/MNG-5780

The problem is because you haven't set JAVA_HOME in Mac properly. In order to do that, you should do set it like this:

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

在我的情况下,我的 JDK 安装是 jdk1.8.0 _ 40,请确保键入您的 JDK。

Then you can use maven commands.

问候!

A dynamic $HOME/.zshrc solution, if you're like me ie. Linux @ work; MBP/A @ home

if [[ $(uname) == "Darwin" ]]; then export OSX=1; fi
if [[ $(uname) ==  "Linux" ]]; then export LINUX=1; fi


if [[ -n $OSX ]]; then
export JAVA_HOME=$(/usr/libexec/java_home)
else
export JAVA_HOME=/usr/lib/jvm/default-java
fi

我用一个旧版本的 maven (2.x)解决了这个问题,用的是 brew:

brew uninstall maven
brew tap homebrew/versions
brew install maven2

In Eclipse, you don't need to change JAVA_HOME, you just need to change the run configuration for Maven to something above 1.6 (even if your project is on Java 6, Maven shouldn't be). Right-click the project, choose Maven Build or Run As > Run Configurations and set the correct JDK version.

这样做在您的。配置文件-

Export JAVA _ HOME = ‘/usr/libexec/JAVA _ home’

(反勾确保执行命令并将其值放在 JAVA _ HOME 中)