Tomcat JVM version is different from JAVA_HOME

I wanted to make the Tomcat JVM version equal to 7. So, I read the instructions here How to change the Java version used by TOMCAT? , and changed my JAVA_HOME be my jdk7 directory.

To make sure, here is the command:

 $ echo $JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64 

I restarted Tomcat. I wanted to check and executed the command that I got from here: https://stackoverflow.com/a/464829/

 $ /usr/share/tomcat7/bin/catalina.sh version /usr/share/tomcat7/bin/catalina.sh: 1: /usr/share/tomcat7/bin/setenv.sh: -Dcom.sun.management.jmxremote: not found /usr/share/tomcat7/bin/catalina.sh: 2: /usr/share/tomcat7/bin/setenv.sh: -Dcom.sun.management.jmxremote.port=1099: not found /usr/share/tomcat7/bin/catalina.sh: 3: /usr/share/tomcat7/bin/setenv.sh: -Dcom.sun.management.jmxremote.authenticate=false: not found /usr/share/tomcat7/bin/catalina.sh: 4: /usr/share/tomcat7/bin/setenv.sh: -Dcom.sun.management.jmxremote.ssl=false: not found Using CATALINA_BASE: /usr/share/tomcat7 Using CATALINA_HOME: /usr/share/tomcat7 Using CATALINA_TMPDIR: /usr/share/tomcat7/temp Using JRE_HOME: /usr/lib/jvm/java-7-openjdk-amd64 Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar Server version: Apache Tomcat/7.0.28 Server built: Apr 8 2014 08:47:08 Server number: 7.0.28.0 OS Name: Linux OS Version: 3.16.0-0.bpo.4-amd64 Architecture: amd64 JVM Version: 1.7.0_79-b14 JVM Vendor: Oracle Corporation 

and I really see that the JVM version is 1.7.0_79-b14

BUT , when I go to the online manager, I see this: enter image description here

what's happening? and indeed, I started this whole process because my war is not unfolding due to version mismatch:

 Caused by: java.lang.UnsupportedClassVersionError: org/glassfish/jersey/servlet/init/JerseyServletContainerInitializer : Unsupported major.minor version 51.0 (unable to load class org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer) 

Update as requested, here is the result for running java -version:

 $ java -version java version "1.7.0_79" OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-1~deb7u1) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode) 
+5
source share
2 answers

In *nix create the setenv.sh file with the following contents:

 JRE_HOME=/usr/java/jdk1.7.0_03/jre CATALINA_PID="$CATALINA_BASE/tomcat.pid" 
+4
source

According to this article, there are 4 different ways:

1. Change JRE by updating JAVA_HOME or JRE_HOME

This method is very simple to implement , but it only works for Tomcat installed from the zip distribution (unlike Tomcat installed as a service).

  • if only the JAVA_HOME environment variable is set, Tomcat will run under the JRE as part of the JDK specified by the JAVA_HOME variable. Therefore, we change the JRE for Tomcat by updating this variable.

  • If the environment variables JAVA_HOME and JRE_HOME , JRE_HOME is preferred. Here is an example of a valid value for the variable JRE_HOME (path on Windows):

 JRE_HOME=C:\Program Files\Java\jre7 

2. Changing the JRE with the "setenv" script

We can change the JRE for Tomcat by setting the JRE_HOME variable to a script file called setenv.bat (on Windows) or setenv.sh (on *nix ). This file does not exist by default, so create such a file and place it in the CATALINA_BASE\bin ( CATALINA_BASE is the Tomcat installation directory).

On Windows, create the setenv.bat file with the following contents:

 set "JRE_HOME=C:\Program Files\Java\jdk1.7.0_03\jre" exit /b 0 

3. Changing the JRE in the Tomcat service manager

To install Tomcat, which is installed as a service (on Windows), we can change the version of the JRE that launches Tomcat by setting the Java virtual machine setting in the Tomcat service manager program (for example, Tomcat7w.exe ), as shown in the following screenshot:

enter image description here

4. Change JRE in Eclipse IDE

To change the JRE version for the Tomcat runtime in Eclipse, go to Window> Preferences. In the Settings dialog box, open Server> Runtime Environments node, select the version of Tomcat in the list, and click the Change button

Check additional information in the related article.

+3
source

All Articles