Find out Tomcat is using which JDK or JAVA_HOME
In this article, we will show you how to find out which JRE / JDK or JAVA_HOME is used by the Tomcat container.
Environment :
- Debian 7.5
- Tomcat 7, installed via apt-get
- JDK 6 and JDK 7
To understand how Tomcat pick up which JDK to run, refer to the Tomcat startup script – /etc/init.d/tomcat7. Normally, Tomcat will use the JDK which configured in the JAVA_HOME environment, if JAVA_HOME is not set, Tomcat will find a random JDK from a pre-defined location.
1. Tomcat Manager
If the Tomcat manager is installed, you are lucky, no action is needed, just refer to the manager page, the current running JVM will be displayed on the bottom.
Figure : Tomcat manager page
2. Tomcat Startup Scripts
Find Tomcat startup script, edit it to print out the JAVA_HOME value. For Tomcat that installed by apt-get, the startup script is located in /etc/init.d/tomcat7.
2.1 Edit sudo vim /etc/init.d/tomcat7, scroll down to the near bottom, find following patterns
#... status) set +e start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ --user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null 2>&1 if [ "$?" = "0" ]; then if [ -f "$CATALINA_PID" ]; then log_success_msg "$DESC is not running, but pid file exists." exit 1 else log_success_msg "$DESC is not running." exit 3 fi else log_success_msg "$DESC is running with pid `cat $CATALINA_PID`" fi set -e ;;
2.2 Append a simple text “using java – $JAVA_HOME”.
status) set +e start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ --user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null 2>&1 if [ "$?" = "0" ]; then if [ -f "$CATALINA_PID" ]; then log_success_msg "$DESC is not running, but pid file exists." exit 1 else log_success_msg "$DESC is not running." exit 3 fi else # START - UPDATE HERE!!!!!!!!!!!!!! log_success_msg "$DESC is running with pid `cat $CATALINA_PID`, using java - $JAVA_HOME" # END - UPDATE HERE!!!!!!!!!!!!!! fi set -e ;;
2.3 Save and exit. Try tomcat7 status :
$ sudo /etc/init.d/tomcat7 status [ ok ] Tomcat servlet engine is running with pid 10809, using java - /usr/lib/jvm/java-7-openjdk-amd64.
$ sudo service tomcat7 status [ ok ] Tomcat servlet engine is running with pid 10809, using java - /usr/lib/jvm/java-7-openjdk-amd64.
Now, the status option will print out which JDK is used by the Tomcat.
From:一号门
Previous:How to change Tomcat to use JDK 7
COMMENTS