How to change Tomcat to use JDK 7

The current environment is using Tomcat 7 + JDK 6. How to configure Tomcat to use JDK 7?


  1. Tomcat 7 (apt-get install)
  2. Debian 7.5
  3. JDK 6 and JDK 7

P.S Tomcat 7 is installed via apt-get

You may interest at this tutorial – Apache Tomcat 8 + JDK 8 on Debian

1. Solution

Update the JAVA_HOME in this file /etc/default/tomcat7

1.1 Edit /etc/default/tomcat7, update JAVA_HOME

$ sudo vim /etc/default/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.


1.2 Restart Tomcat, done.

$ sudo service tomcat7 restart

1.3 Check this article to find out which JDK is used by Tomcat.

No SPACE, What the F!
Make sure there is no extra space between the equal symbol “=”, it will cause “JAVA_HOME no found”, I spent hours fixing this bug!For example

#...Wrong, SPACE
JAVA_HOME = /usr/lib/jvm/java-7-openjdk-amd64