Issue
Recently I had come across an error while running a basic webapp in tomcat. The error was "class has been compiled by a more recent version of the Java Environment". I am using jdk-11.0.2 and jre1.8.0_201. Then I came across this page about setting tomcat server which says :
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. Is this the right method to solve the issue? Is it possible to make JRE_HOME invisible for tomcat alone? Am I going to need JRE_HOME anywhere else?
Solution
So I tried deleting the JRE_HOME variable and that solved the error. Is this the right method to solve the issue?
Yes. Based on your information , your web app requires Java version >8 to run. 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.
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.
You can also customize / override JRE_HOME
or JAVA_HOME
by creating a setenv.sh
inside bin
folder. All settings inside setenv.sh
is only applied for the Tomcat :
export JAVA_HOME=/path/to/jdk-11.0.2
Answered By - Ken Chan