Java Maven 安装 OSX 错误不受支持的major.minor 版本 51.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29255495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 07:39:52  来源:igfitidea点击:

Maven Installation OSX Error Unsupported major.minor version 51.0

javamacosmaveninstallunsupported-class-version

提问by Steven

I installed maven by following this steps:(a tutorial)

我按照以下步骤安装了 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

then I wrote the echo in the .bash_profile sth like this:

然后我在 .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…

and also I wrote this in the .bashrc

我也在 .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: I think there are some versions wrong, but I don't know.

现在,当我想检查版本 ( mvn -v) 时,出现以下异常:我认为有些版本是错误的,但我不知道。

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
java -version
0(URLClassLoader.java:58) at java.net.URLClassLoader.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)

Additional information:

附加信息:

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)
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
javac 1.8.0_40
$JAVA_HOME/bin/java -version

采纳答案by GerSua

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:

问题是你没有在 Mac 中正确设置 JAVA_HOME。为了做到这一点,你应该像这样设置它:

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

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

In my case my JDK installation is jdk1.8.0_40, make sure you type yours.

就我而言,我的 JDK 安装是 jdk1.8.0_40,请确保键入您的。

Then you can use maven commands.

然后你可以使用maven命令。

Regards!

问候!

回答by René

Please rather try:

请尝试:

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

Maven uses $JAVA_HOMEfor classpath resolution of JRE libs. To be sure to use a certain JDK, set it explicitly before compiling, for example:

Maven$JAVA_HOME用于 JRE 库的类路径解析。要确保使用某个JDK,请在编译前显式设置它,例如:

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

Isn't there a version < 1.7 and you're using Maven 3.3.1? In this case the reason is a new prerequisite: https://issues.apache.org/jira/browse/MNG-5780

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

回答by evandrix

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

一个动态的$HOME/.zshrc解决方案,如果你像我一样,即。Linux@工作;MBP/A @ 家

brew uninstall maven
brew tap homebrew/versions 
brew install maven2

回答by javaboygo

I solved it putting a old version of maven (2.x), using brew:

我使用 brew 解决了它放置旧版本的 maven (2.x):

##代码##

回答by Noumenon

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.

在 Eclipse 中,您不需要更改 JAVA_HOME,您只需要将 Maven 的运行配置更改为 1.6 以上的内容(即使您的项目在 Java 6 上,Maven 也不应该如此)。右键单击项目,选择 Maven Build 或 Run As > Run Configurations 并设置正确的 JDK 版本。

回答by Pradeep

Do this in your .profile -

在您的 .profile 中执行此操作 -

export JAVA_HOME=`/usr/libexec/java_home`

导出 JAVA_HOME=`/usr/libexec/java_home`

(backticks make sure to execute the command and place its value in JAVA_HOME)

(反引号确保执行命令并将其值放在 JAVA_HOME 中)