线程“main”中的异常 java.lang.UnsupportedClassVersionError,不支持的major.minor 版本 52.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18161907/
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
Exception in thread "main" java.lang.UnsupportedClassVersionError, Unsupported major.minor version 52.0
提问by georgiana_e
I am trying to run the WordCount example on hadoop - 1.0.4 and I am getting the following error:
我正在尝试在 hadoop - 1.0.4 上运行 WordCount 示例,但出现以下错误:
Exception in thread "main" java.lang.UnsupportedClassVersionError: WordCount :
Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access0(URLClassLoader.java:71)
at java.net.URLClassLoader.run(URLClassLoader.java:361)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.hadoop.util.RunJar.main(RunJar.java:149)
I use the following java version:
我使用以下java版本:
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) Server VM (build 23.6-b04, mixed mode)
Also JAVA_HOME indicates to the java7 installation directory.
JAVA_HOME 也表示到java7 的安装目录。
Thanks for your help.
谢谢你的帮助。
采纳答案by Suresh Atta
Seems like you are using JDK8 for compiling and Lower version on Where you are using it.
似乎您正在使用 JDK8 进行编译,并在使用它的地方使用较低版本。
So
所以
Assuming using eclipse, Window > Preferences > Compiler > compiler level
假设使用eclipse, Window > Preferences > Compiler > compiler level
and then set lower level(< current one ).
然后设置较低的级别(< 当前级别)。
回答by chrylis -cautiouslyoptimistic-
Looks like someone managed to compile a class with a Java 8 compiler. Recompile the offending jar with a compliance level of Java 7 or lower.
看起来有人设法用 Java 8 编译器编译了一个类。使用 Java 7 或更低的合规性级别重新编译有问题的 jar。
回答by saurav
Well obviously that won't work! You are compiling on a newer JDK and deploying on an older JDK / JRE. You need to compile on the older JDK.
那么显然这行不通!您正在较新的 JDK 上编译并在较旧的 JDK/JRE 上部署。您需要在较旧的 JDK 上进行编译。
回答by prash.gaikwad4
The problem is due to .jsp files are getting compiled with higher compiler(8) than expected(7). Change all compilation levels to lower one(i.e. 7) also change the jdk path given in eclipse configuration settings file in the same folder where .exe is located.
问题是由于 .jsp 文件使用比预期 (7) 更高的编译器 (8) 进行编译。将所有编译级别更改为较低级别(即 7),同时更改 .exe 所在文件夹中 eclipse 配置设置文件中给出的 jdk 路径。
回答by ppant
I think you already got your answer ..just to add, in eclipse under project there is a JRE System Library [JavaSE-1.x] folder .. right click on it you will see JRE System Library screen..there you can set the execution environment.
我想你已经得到了答案..只是补充一下,在项目下的 eclipse 中有一个 JRE 系统库 [JavaSE-1.x] 文件夹.. 右键单击它你会看到 JRE 系统库屏幕..你可以在那里设置执行环境。
回答by Albert
I had the same problem which I solved. I found that
the JAVA_HOME
in my hadoop-env.sh
is /usr/lib/jvm/java-6-openjdk
but the JAVA_HOME
in /etc/profile
is /usr/local/java/jdk1.8.0_25
.
我有同样的问题,我解决了。我发现JAVA_HOME
in my hadoop-env.sh
is/usr/lib/jvm/java-6-openjdk
但JAVA_HOME
in /etc/profile
is /usr/local/java/jdk1.8.0_25
。
After I change JAVA_HOME
in /etc/profile
to /usr/lib/jvm/java-6-openjdk
which is the same as hadoop-env.sh
and use
$source /etc/profile # to make /etc/profile effects
在我更改JAVA_HOME
为/etc/profile
与/usr/lib/jvm/java-6-openjdk
哪个相同hadoop-env.sh
并使用之后
$source /etc/profile # to make /etc/profile effects
My problem is solved! I hope this will help you.
我的问题解决了!我希望这能帮到您。
回答by niks
I also encountered the same problem.Should use same JAVA version for compile and same or greater on where you are executing it although vice-versa cause this error. If you checked:
我也遇到了同样的问题。应该使用相同的 JAVA 版本进行编译,并且在执行它的位置相同或更高,反之亦然会导致此错误。如果您检查:
Window > Preferences > Compiler > compiler level
java -version
and both has same version then you are good to go. While creating New Project in Eclipse:File -> New -> Java Project
under JREcheck Use an execution environmentand set to same version which is on your system and system where you need to execute this project.