Enable tomcat debugging

Shutdown tomcat and make sure that it has properly shut down by monitoring the tomcat process.

Once it has completely shutdown, export the following environment variables:

Here, we’re setting the jpda address to port 8000. Note this down as you will need this port number in order to connect via your IDE or whatever debugging tool you’re using.

Options above will run tomcat as usual so if you want to debug something that happens early on in the lifecycle, you either need to be really quick about attaching your debugger or add the following JPDA option:

This will suspend the tomcat startup until you attach your debugger.

Next, start tomcat jpda using catalina script:

At this stage, you can monitor the log in catalina.out file to make sure everything goes smoothly.

Now setup your IDE to connect to tomcat at port 8000. If you are using vagrant as your VM, make sure you are port forwarding 8000 in your network settings. If not, you can always tunnel in:

Or if its a remote server, you can just use the normal ssh command:

Hope this helps!


  • Conor Restall: For suggesting JPDA_SUSPEND option.

Waiting for tomcat to start up in a script

So here’s something that I have found that waits for tomcat to come up but rather than polling or a static time based wait, it uses FIFO pipeline to wait.

Drop this into a tomcat-util.sh file, make it executable and then source the file:

You’ll now have isTomcatUp available as a bash command.


Unix/Linux command to check if Apache Tomcat is running

So I’ve come across this problem quite a few times. Normal way to do this is:

ps -ef | grep tomcat

This works most of the times. If tomcat is running, it gives between 1 and 2 lines back but if not, it gives anywhere between 0 and 1 lines back. A much cleaner use of the above command would be with wc -l:

ps -ef | grep tomcat | wc -l

However, this doesn’t solve the actual problem as along with the tomcat process, it also gives you the process of command "grep tomcat".
Continue reading