Java 不支持的major.minor 版本52.0(无法加载类)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42820521/
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-12 00:26:04  来源:igfitidea点击:

Unsupported major.minor version 52.0 (unable to load class)

java

提问by user7637864

When i run my project i am getting the following exception:

当我运行我的项目时,我收到以下异常:

javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: apache/commons/codec/UtilityUtil : Unsupported major.minor version 52.0 (unable to load class apache.commons.codec.UtilityUtil)

I have researched and found out that it happens if the version of java is different from runtime and compilation time.

我研究并发现如果java的版本与运行时和编译时间不同,就会发生这种情况。

I have followed these two posts and tried to figure out that i am using java 8 and runtime has 1.7.: Unsupported major.minor version 52.0 captive portalHow to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

我已经关注了这两篇文章,并试图弄清楚我使用的是 java 8 并且运行时有 1.7。: 不支持的major.minor 版本 52.0 强制门户如何修复 java.lang.UnsupportedClassVersionError:不支持的major.minor 版本

I have changed the compilation version to 1.7. But still the same problem exists. I dont know why.

我已将编译版本更改为 1.7。但仍然存在同样的问题。我不知道为什么。

Runtime version: 1.7.0_45 Compilation Version: 1.7.0_80.

运行时版本:1.7.0_45 编译版本:1.7.0_80。

采纳答案by efekctive

This is a duplicate. The classes you are using are probably compiled with Java 1.8 and your jvm is 1.7. That also includes 3rd party jars

这是一个重复。您使用的类可能是用 Java 1.8 编译的,而您的 jvm 是 1.7。这也包括第 3 方罐子

回答by Luca D'Amico

52 = J2SE 8. You are still compiling with Java 1.8 (or some libs you are using are compiled with 1.8 as pointed out by @efekctive).

52 = J2SE 8. 您仍在使用 Java 1.8 进行编译(或者如@efekctive 所指出的那样,您正在使用的某些库是使用 1.8 编译的)。

Please post what command are you using to build.

请发布您使用什么命令来构建。

回答by user7637864

As @efekctive stated my build is using java 8 for building the class. Changed the version back to 7 and worked as expected. Thanks everyone.

正如@efekctive 所说,我的构建使用 java 8 来构建类。将版本改回 7 并按预期工作。谢谢大家。

回答by RKA

Please do the following steps to find out yourJRE version and JDK version.

请按照以下步骤找出您的 JRE 版本和 JDK 版本。

JRE check

JRE检查

java -version

版本

java version "1.7.0_111" OpenJDK Runtime Environment (IcedTea 2.6.7) (7u111-2.6.7-2~deb7u1) OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode)

java version "1.7.0_111" OpenJDK Runtime Environment (IcedTea 2.6.7) (7u111-2.6.7-2~deb7u1) OpenJDK 64-Bit Server VM (build 24.111-b01,混合模式)

JDK check

JDK检查

javac -version

javac -version

javac 1.6.0_38

javac 1.6.0_38

And you can find that both the versions are different. So, make them into common version. That will solve your issue.

你会发现这两个版本是不同的。所以,把它们做成通用版本。那将解决您的问题。