7

I wanted to make my Tomcat JVM version be 7. So I followed in the instruction here: How to change Java version used by TOMCAT? and changed my JAVA_HOME to 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 verify, and ran the command I got from here: https://stackoverflow.com/a/10822328/998318

$ /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 indeed I see that 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 going on? and indeed I started this whole process because my war isn't getting deployed because of a 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 output 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)
Community
  • 1
  • 1
Moshe Shaham
  • 15,448
  • 22
  • 74
  • 114

2 Answers2

5

On *nix, create the setenv.sh file with the following content:

JRE_HOME=/usr/java/jdk1.7.0_03/jre
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
SaviNuclear
  • 886
  • 1
  • 7
  • 19
  • this worked, kind of. I used `export JRE_HOME="/usr/lib/jvm/java-7-openjdk-amd64"` without the second line and it was all fixed! – Moshe Shaham Sep 02 '15 at 11:50
3

According this article there are 4 different ways:

1. Changing JRE by updating JAVA_HOME or JRE_HOME

This way is very simple to implement but it works only for Tomcat installed from a zip distribution (in contrast to 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 JRE for Tomcat by updating this variable.

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

JRE_HOME=C:\Program Files\Java\jre7

2. Changing JRE by using “setenv” script

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

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

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

3. Changing JRE in Tomcat service manager

For a Tomcat installation which is installed as a service (on Windows), we can change the version of JRE that runs Tomcat by configuring the Java Virtual Machine setting in the Tomcat service manager program (e.g. Tomcat7w.exe), as shown in the following screenshot:

enter image description here

4. Changing JRE in Eclipse IDE

To change JRE version for a Tomcat runtime in Eclipse, go to the menu Window > Preferences. In the Preferences dialog, open the Server > Runtime Environments node, select a Tomcat version in the list, and then click the Edit button

Check further info in linked article

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109