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 :

  1. Debian 7.5
  2. Tomcat 7, installed via apt-get
  3. JDK 6 and JDK 7
Note
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.

tomcat-manager

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

/etc/init.d/tomcat7

#...
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”.

/etc/init.d/tomcat7

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.

About the Author

author image
mkyong
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

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Sujeet SinghHow to change Tomcat to use JDK 7 Recent comment authors
newest oldest most voted
trackback
How to change Tomcat to use JDK 7

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

Sujeet Singh
Guest
Sujeet Singh

One can use jps or VisualVM to know the Tomcat JVM without touching tomcat configuration.