Horace
Horace

Reputation: 1208

How to configure Tomcat to use Java 7

I have a web application in java 6 byte code and would like to test it in a Java 7 JVM environmment. For that purpose, I would like to configure Tomcat (for running the web application) to use Java 7. Now my question is how to do this?

Do I just set my JAVA_HOME environment variable to the path where Java 7 is installed, so that tomcat is run in the right JVM (Version 7)? Or is there another way to do this?

Upvotes: 20

Views: 90704

Answers (7)

Just Open the existing tomcat server and open Runtime Environment and check the JDK Version and change it java 7 JDK Config Changes

Upvotes: 0

Aniket Thakur
Aniket Thakur

Reputation: 69025

I had installed it via

sudo apt-get install tomcat7

Setting up JAVA_HOME or PATH did not help me. I had to add entry in file- /etc/default/tomcat7

# Run Tomcat as this user ID. Not setting this or leaving it blank will use the
# default of tomcat7.
TOMCAT7_USER=tomcat7

# Run Tomcat as this group ID. Not setting this or leaving it blank will use
# the default of tomcat7.
TOMCAT7_GROUP=tomcat7

# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for 
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
#JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk
JAVA_HOME=/usr/lib/jvm/java-8-oracle
...

This is Java 8 but you get the point.

Upvotes: 3

Sami Lehtinen
Sami Lehtinen

Reputation: 891

If you're using Windows, this helps. Run Tomcat helper app (tomcatw.exe) and simply configure Java Virtual Machine DLL path under Java tab. Use default must be unchecked.

enter image description here

Upvotes: 28

Jalkin
Jalkin

Reputation: 1132

In Eclipse it is very easy to point Tomcat to a new JVM (in this example JDK7). My problem was I couldn't find where to do it. Here is the trick:

  1. On the ECLIPSE top menu FILE pull down tab, select NEW, -->Other
  2. ...on the New Server: Select A Wizard window, select: Server-> Server... click NEXT
  3. . on the New Server: Define a New Server window, select Apache> Tomcat 7 Server
  4. ..now click the line in blue and underlined entitled: Configure Runtime Environments
  5. on the Server Runtime Environments window,
  6. ..select Apache, expand it(click on the arrow to the left), select TOMCAT v7.0, and click EDIT.
  7. you will see a window called EDIT SERVER RUNTIME ENVIRONMENT: TOMCAT SERVER
  8. On this screen there is a pulldown labeled JREs.
  9. You should find your JRE listed like JDK1.7.0. If not use the Installed JRE button.
  10. Select the desired JRE. Click the FINISH button.
  11. Gracefully exit, in the Server: Server Runtime Environments window, click OK
  12. in the New Server: Define a new Server window, hit NEXT
  13. in the New Server: Add and Remove Window, select apps and install them on the server.
  14. in the New Server: Add and Remove Window, click Finish

Thats all. Interesting, only steps 7-10 seem to matter, and they will change the JRE used on all servers you have previously defined to use TOMCAT v7.0. The rest of the steps are just because I can't find any other way to get to the screen except by defining a new server. Does anyone else know an easier way?

TA, Jalkin

Upvotes: 3

Fritz
Fritz

Reputation: 10055

Tomcat's home page states that

Tomcat requires a JDK (version 1.6 or later) to be installed. The Sun JDK can be downloaded here.

IMPORTANT: Set an environment variable JAVA_HOME to the pathname of the directory into which you installed the JDK release.

So basically you're correct. Still there might be some compatibility issues. I recommend you read this article for a detailed discussion about Tomcat and Java 7.

Upvotes: 0

NimChimpsky
NimChimpsky

Reputation: 47300

Go to tomcat/bin and modify the JAVA_HOME parmater in catalina.sh (for linux/unix) or catalina.bat (for windows). This means that only tomcat jvm will change, not everything else.

Upvotes: 1

Anuj Patel
Anuj Patel

Reputation: 17869

You answered your own question.! :) All You need to do is link java 7 in your JAVA_HOME.!

More Info Here

Edit : (Based on alfabravo's comment :

You can definitely change the pointer to JAVA_HOME in your catalina.bat/sh

Upvotes: 3

Related Questions