简体   繁体   English

我需要JRE_HOME吗? Tomcat Java环境版本差异

[英]Do I need JRE_HOME? Tomcat java environment version difference

Recently I had come across an error while running a basic webapp in tomcat. 最近,我在tomcat中运行基本的webapp时遇到错误。 The error was "class has been compiled by a more recent version of the Java Environment". 错误是“类已由Java环境的较新版本编译”。 I am using jdk-11.0.2 and jre1.8.0_201. 我正在使用jdk-11.0.2和jre1.8.0_201。 Then I came across this page about setting tomcat server which says : 然后,我碰到了有关设置tomcat服务器的页面, 页面显示:

If both JRE_HOME and JAVA_HOME are specified, JRE_HOME is used

So I tried deleting the JRE_HOME variable and that solved the error. 因此,我尝试删除JRE_HOME变量,从而解决了该错误。 Is this the right method to solve the issue? 这是解决问题的正确方法吗? Is it possible to make JRE_HOME invisible for tomcat alone? 是否可以使JRE_HOME仅对于tomcat 不可见 Am I going to need JRE_HOME anywhere else? 我在其他任何地方都需要JRE_HOME吗?

So I tried deleting the JRE_HOME variable and that solved the error. 因此,我尝试删除JRE_HOME变量,从而解决了该错误。 Is this the right method to solve the issue? 这是解决问题的正确方法吗?

Yes. 是。 Based on your information , your web app requires Java version >8 to run. 根据您的信息,您的Web应用程序需要运行Java版本> 8。 And what you do here is to ensure that Tomcat is using Java 11 to run which is the right direction to solve the problem. 您在此处所做的就是确保Tomcat使用Java 11来运行,这是解决问题的正确方向。

Also , it is very normal that you only set JAVA_HOME but not set JRE_HOME because behind the scenes if you do not set JRE_HOME , Tomcat startup script ( setclasspath.bat ) will automatically set JRE_HOME for you based on the JAVA_HOME value. 同样,只设置JAVA_HOME而不设置JRE_HOME是非常正常的,因为如果没有设置JRE_HOME ,那么在后台,Tomcat启动脚本( setclasspath.bat )将根据JAVA_HOME值自动为您设置JRE_HOME

You can also customize / override JRE_HOME or JAVA_HOME by creating a setenv.sh inside bin folder. 您还可以通过在bin文件夹中创建setenv.sh来自定义/覆盖JRE_HOMEJAVA_HOME All settings inside setenv.sh is only applied for the Tomcat : setenv.sh内的所有设置仅适用于Tomcat:

export JAVA_HOME=/path/to/jdk-11.0.2

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

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