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

2023-05-04 20:14:42 浏览数 (1)

java项目构建从高版本JDK改为低版本JDK报错。这是再次编译时使用的JDK版本比你原来编译的版本低所导致的。 maven项目在服务器上构建时报错(Unsupported major.minor version 52.0 ):

代码语言:javascript复制
 java.lang.UnsupportedClassVersionError: com/byron4j/listener/InitListener : Unsupported major.minor version 52.0 (unable to load class com.byron4j.listener.InitListener) 
 at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2961) 
 at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210) 
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690) 
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) 
 at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:506) 
 at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:488) 
 at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:115) 
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4932) 
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528) 
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) 
 at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095) 
 at org.apache.catalina.startup.HostConfig
DeployWar.run(HostConfig.java:1930)    at java.util.concurrent.Executors
RunnableAdapter.call(Executors.java:471) 
 at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
 at java.lang.Thread.run(Thread.java:745)

原来本地项目指定的JDK版本是1.8的:

代码语言:javascript复制
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
</plugin>

部署到linux服务器上之后,启动项目时报Unsupported major.minor version 52.0 错误,检查发现是linux服务器上JDK版本过低导致的,然后将项目指定JDK版本为1.7,再发布启动OK了。

代码语言:javascript复制
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
</plugin>

JDK版本在官方对应的版本号列表如下:

代码语言:javascript复制
JDK 8.0 = 52,
JDK 7.0 = 51,
JDK 6.0 = 50,
JDK 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

正是指定的JDK版本为52,但是由于服务器是JDK 7导致引发Unsupported major.minor version 52.0

0 人点赞