Tag Archives: Tomcat

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
set JPDA_ADDRESS=5003

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.


Obscure Ant build errors

I’ve been using Eclipse at work now, the first time I’ve done more than toy with it.  Along with Eclipse are the attendant tools – Ant, Maven, TomCat and ClearCase (oh yes, ClearCase).

So, Ant. I came across a situation where the build was failing to deploy the WAR files to TomCat, with the following error:

build.xml:887: java.net.UnknownHostException: C

Not much use there.  As it turns out, the solution was both simple and cripplingly unintuitive: replace “file://” with “file:///”.  The extra slash makes all the difference.

For example:

Replace:

war="file://${dist.dir}/app.war"

With:

war="file:///${dist.dir}/app.war"