Main Tutorials

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?

Environment

  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

Note
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 
/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.
#JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

#...

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

/etc/default/tomcat7

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

#...Correct
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

References

  1. Java : Unsupported Major.Minor Version 51.0
  2. Find out Tomcat is using which JDK.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Luis Angel Cerritos
9 years ago

That i’snt a bug, JAVA_HOME is a shell var, and the symbol “=” always be used of this way, without extra spaces.

mkyong
9 years ago

Thanks for your feedback ~

Luis Angel Cerritos
9 years ago
Reply to  mkyong

You’re welcome.