简体   繁体   English

Tomcat 不识别 Java 升级

[英]Tomcat doesn't recognise Java Upgrade

I recently upgraded the Java Version from 11 to 17. But whenever I run the.war file I get the following error:我最近将 Java 版本从 11 升级到 17。但是每当我运行 .war 文件时,我都会收到以下错误:

java.lang.UnsupportedClassVersionError: somePackage/SomeClass 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 (unable to load class [somePackage.SomeClass]) java.lang.UnsupportedClassVersionError: somePackage/SomeClass 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 [31995pack18 无法加载18.0]某类])

To verify if the Tomcat is using the right version, I did this:为了验证 Tomcat 是否使用了正确的版本,我这样做了:

[root@ip-172-31-21-71 apache-tomcat-9.0.58]# java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo
Server version: Apache Tomcat/9.0.58
Server built:   Jan 15 2022 14:37:38 UTC
Server number:  9.0.58.0
OS Name:        Linux
OS Version:     4.14.214-160.339.amzn2.x86_64
Architecture:   amd64
JVM Version:    17.0.5+8-LTS
JVM Vendor:     Amazon.com Inc.
[root@ip-172-31-21-71 apache-tomcat-9.0.58]# ps -ef | grep tomcat
root     12088 11400  0 08:49 pts/0    00:00:00 grep --color=auto tomcat
root     15642     1  1 Nov16 ?        00:12:09 /opt/jdk-17.0.5/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat-9.0.58/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dfile.encoding=UTF-8 -Xms128m -Xmx700m -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /opt/apache-tomcat-9.0.58/bin/bootstrap.jar:/opt/apache-tomcat-9.0.58/bin/tomcat-juli.jar -Dcatalina.base=/opt/apache-tomcat-9.0.58 -Dcatalina.home=/opt/apache-tomcat-9.0.58 -Djava.io.tmpdir=/opt/apache-tomcat-9.0.58/temp org.apache.catalina.startup.Bootstrap start
[root@ip-172-31-21-71 apache-tomcat-9.0.58]# /opt/jdk-17.0.5/bin/java --version
java 17.0.5 2022-10-18 LTS
Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.5+9-LTS-191, mixed mode, sharing)

Even ${JAVA_HOME} points to the right directory.甚至${JAVA_HOME}也指向正确的目录。 Everything works well locally.一切都在当地运作良好。 I don't know what I'm missing.我不知道我错过了什么。 Any suggestions would be appreciated.任何建议,将不胜感激。 Thanks in advance.提前致谢。

Well... since you are running startup.sh by hand...好吧...因为您正在手动运行startup.sh ...

The startup.sh calls catalina.sh start . startup.sh调用catalina.sh start And the catalina.sh script uses the JRE_HOME or JAVA_HOME environment variables. catalina.sh脚本使用JRE_HOMEJAVA_HOME环境变量。 But it loads them by sourcing the setenv.sh script if it can find them.但是如果可以找到它们,它会通过获取setenv.sh脚本来加载它们。

So my bet is that your setenv.sh is where the salient JRE_HOME or JAVA_HOME settings are.所以我敢打赌,您的setenv.sh是显着JRE_HOMEJAVA_HOME设置所在的位置。

But the good news is that all of these files are just shell scripts, so you can read them to figure out what it going on.但好消息是,所有这些文件都只是 shell 个脚本,因此您可以阅读它们以弄清楚发生了什么。 And if you can't read shell scripts, you can add set -x in the respective scripts to watch what they are doing!而如果你看不懂shell脚本,你可以在各自的脚本中加上set -x看看他们在干什么!


By the way:顺便一提:

To verify if the Tomcat is using the right version, I did this: $ java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo为了验证 Tomcat 是否使用了正确的版本,我这样做了: $ java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo

That is not a valid test.那不是一个有效的测试。 You have to figure out how the scripts are choosing the JRE that they are using.您必须弄清楚脚本如何选择它们正在使用的 JRE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM