由较新版本的 Java 运行时(类文件版本 61.0)编译的 Tomcat 11 错误

由较新版本的 Java 运行时(类文件版本 61.0)编译的 Tomcat 11 错误

我已经安装了 Tomcat 11.0.0-M6,每次第一次启动它时都会收到此错误消息:

Error: LinkageError occurred while loading main class org.apache.catalina.startup.Bootstrap java.lang.UnsupportedClassVersionError: org/apache/catalina/startup/Bootstrap 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 55.0

我已经通过执行操作检查了 Java 版本java -version,并且获得了版本 11,对应于 Tomcat 要求的类文件版本 55: java version "11.0.12" 2021-07-20 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.12+8-LTS-237) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.12+8-LTS-237, mixed mode)

然后我这样做了update-alternatives --display java,得到了:

java - manual mode
  link best version is /opt/jdk/jdk-11.0.12/bin/java
  link currently points to /opt/jdk/jdk-11.0.12/bin/java
  link java is /usr/bin/java
/opt/jdk/jdk-11.0.12/bin/java - priority 100
/opt/jdk/jdk-17.0.7/bin/java - priority 100
/opt/jdk/jdk1.8.0_301/bin/java - priority 100

我们可以看到使用的是 Java 11,而不是 Java 17

有 tomcat.service 文件:

[Unit]
Description="Tomcat Service"
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
RestartSec=10
Restart=always


Environment="JAVA_HOME=/opt/jdk/jdk-11.0.12"
Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target
[Service]
Environment="CATALINA_OPTS=-Djava.library.path=/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu:/usr/lib64:/lib64:/lib:/usr/lib"

有人知道是什么导致了这个错误吗?

感谢您的帮助

相关内容