【已解决】Tomcat 运行报错: XXX has been compiled by a more recent version of the Java Runtime

问题:

jakarta.servlet.ServletException: java.lang.UnsupportedClassVersionError: com/companyabc/xxw/demo/SimpleBean has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (无法载入的类 [com.companyabc.xxw.demo.SimpleBean])
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:667)
	org.apache.jsp.jsp.Test_005fJavaBean.use_005fjavabean_005fdemo_005f01_jsp._jspService(use_005fjavabean_005fdemo_005f01_jsp.java:149)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)

原因:Tomcat 运行所依赖的jre环境版本(与Tomcat本身的版本没关系),与编译出来的 .class(JavaBean)文件版本不一致(本人在 Ubuntu 上用 javac 命令编译出 .class文件,在 windows 的 Tomcat 上运行)而导致。

解决步骤:

1.JDK version和class file version(Class编译版本号)对应关系

JDK 17 = 61,
JDK 16 = 60,
JDK 15 = 59,
JDK 14 = 58,
JDK 13 = 57,
JDK 12 = 56,
JDK 11 = 55,
JDK 10 = 54,
JDK 9 = 53,
JDK 8 = 52,
JDK 7 = 51,
JDK 6.0 = 50,
JDK 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
————————————————
版权声明:本文为CSDN博主「lzhfdxhxm」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lzhfdxhxm/article/details/117018384

2.下载安装 JDK17;

3.安装另一个 Tomcat 实例

关键步骤:

【已解决】Tomcat 运行报错: XXX has been compiled by a more recent version of the Java Runtime_第1张图片

 【已解决】Tomcat 运行报错: XXX has been compiled by a more recent version of the Java Runtime_第2张图片

3. 安装 Tomcat 过程中,注意更改端口号,不能和现有 Tomcat 网站使用重复端口,之后重新配置 service.xml里的网站目录即可。

参考(侵删):

http://t.csdn.cn/lVXEW

http://t.csdn.cn/i7Z5H 

你可能感兴趣的:(java,tomcat)