Java 6 不支持的major.minor 版本 51.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31394456/
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
Java 6 Unsupported major.minor version 51.0
提问by Hassan Syyid
I recently uninstalled Java 8, to use Java 6 as I want my code/creations to be usable by more people than just those on Java 8. When I do mvn - version
it returns:
我最近卸载了 Java 8,以使用 Java 6,因为我希望我的代码/创作能够被更多人使用,而不仅仅是 Java 8 上的人。当我这样做时,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:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.accessjava version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
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)
When I do java -version
:
当我这样做时java -version
:
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /opt/dev/jdk1.7.0_45/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-36-generic", arch: "amd64", family: "unix"
Everything seems fine with Java, but this also happens when I try to run executable JARs. I got around it by manually doing java -jar (jar name)
Java 看起来一切正常,但是当我尝试运行可执行 JAR 时也会发生这种情况。我通过手动执行 java -jar (jar name) 来解决它
采纳答案by John Ament
According to maven website, the last version to support Java 6 is 3.2.5, and 3.3 and up use Java 7. My hunch is that you're using Maven 3.3 or higher, and should either upgrade to Java 7 (and set proper source/target attributes in your pom) or downgrade maven.
根据Maven 网站,支持 Java 6 的最新版本是 3.2.5,3.3 及更高版本使用 Java 7。我的预感是您使用的是 Maven 3.3 或更高版本,应该升级到 Java 7(并设置适当的源/target 属性在你的 pom 中)或降级 maven。
回答by Andy Turner
That version number (51.0) indicates that you are trying to run classes compiled for Java 7. You will need to recompile them for Java 6.
该版本号 (51.0) 表明您正在尝试运行为 Java 7 编译的类。您需要为 Java 6 重新编译它们。
Note, however, that some features may no longer be compatible with Java 6, which is very old, and no longer (publicly) supported by Oracle.
但是请注意,某些功能可能不再与 Java 6 兼容,Java 6 非常旧,并且不再(公开)受 Oracle 支持。
回答by Rajesh Kumar Yadav
i also faced similar issue. I could able to solve this by setting JAVA_HOME in Environment variable in windows. Setting JAVA_HOME in batch file is not working in this case.
我也遇到了类似的问题。我可以通过在 windows 的 Environment 变量中设置 JAVA_HOME 来解决这个问题。在这种情况下,在批处理文件中设置 JAVA_HOME 不起作用。
回答by pintu
I face the same problem and solved by adding the JAVA_HOME variable with updated version of java in my Ubuntu Machine(16.04). if you are using "Apache Maven 3.3.9" You need to upgrade your JAVA_HOME with java7 or more
我遇到了同样的问题,并通过在我的 Ubuntu 机器(16.04)中添加具有更新版本的 java 的 JAVA_HOME 变量来解决。如果您使用的是“Apache Maven 3.3.9”,您需要使用 java7 或更高版本升级您的 JAVA_HOME
Step to Do this
执行此操作的步骤
1-sudo vim /etc/environment
1-sudo vim /etc/environment
2-JAVA_HOME=JAVA Installation Directory (MyCase-/opt/dev/jdk1.7.0_45/)
2-JAVA_HOME=JAVA安装目录(MyCase-/opt/dev/jdk1.7.0_45/)
3-Run echo $JAVA_HOME will give the JAVA_HOME set value
3-运行 echo $JAVA_HOME 将给出 JAVA_HOME 设置值
4-Now mvn -version will give the desired output
4-现在 mvn -version 将提供所需的输出
##代码##回答by Mohammad Zebardast
The problem is because you haven't set JDK version properly.You should use jdk 7 for major number 51. Like this:
问题是因为你没有正确设置JDK版本。你应该使用jdk 7作为主编号51。像这样:
JAVA_HOME=/usr/java/jdk1.7.0_79
JAVA_HOME=/usr/java/jdk1.7.0_79
回答by Dakshin Rajavel
I ran into the same problem. I use jdk 1.8 and maven 3.3.9 Once I export JAVA_HOME, I did not see this error. export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/
我遇到了同样的问题。我使用 jdk 1.8 和 maven 3.3.9 导出 JAVA_HOME 后,我没有看到此错误。导出 JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/
回答by harun ugur
add jdk8 or higher version at JAVA_HOME and path.
在 JAVA_HOME 和路径添加 jdk8 或更高版本。
add JAVA_HOME add C:\ProgramFiles\Java\jdk1.8.0_201
添加 JAVA_HOME 添加 C:\ProgramFiles\Java\jdk1.8.0_201
For Path =>
对于路径 =>
add %MAVEN_HOME%\bin
添加 %MAVEN_HOME%\bin
and finally restart your pc.
最后重启你的电脑。