Remote debugging Tomcat with Eclipse

When you’re running a Tomcat server on your own machine for development purposes, it’s pretty easy to tie it to Eclipse.  When that Tomcat instance (or, in my case, instances) are running as a service, without the benefit of the control panel, it gets a little harder.  Especially if it’s not a traditional web application, but a desktop app with a supporting web back-end.

Here’s how to debug a Tomcat server with Eclipse when it’s running as a service.  This example assumes that the server is at localhost, and that you’ll be debugging on port 5003 (your choice, so long as it’s available – and it can’t be the port that that Tomcat is already on).

Firstly, when you start your Tomcat service you need to pass a few additional options:

set JPDA_TRANSPORT=dt_socket

Next, the line that actually launches the service needs to pass those options in the JvmOptions parameter:

--JvmOptions "-XDebug;-Xrunjdwp:transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=n;-DJAVA_HOME=...

Important: no white-space in there.

Lastly, create the debug configuration in Eclipse:  Run -> Debug Configurations, add a new Remote  Tomcat Application.

  • Connection Type: Standard (Socket Attach)
  • Host: localhost
  • Port: 5003

Et viola, start this debug configuration to attach to the server, then launch your application as normal.

Leave a Reply

Post Navigation