Blog
Posts tagged with "tomcat".
Remote debugging Tomcat6 using Eclipse
Sid
17 Aug 2010 14:56
This (unimaginatively titled) post explains how to set up remote debugging for Tomcat6 running as a Windows service using Eclipse and first, why you might want to.
Why remote debug?
Once an application grows over a certain size it becomes more difficult to work out what’s going on from watching its behaviour – e.g. error messages and stack traces. This is equally true for small but layered or componentised applications (and doubly true for large layered and componentised applications!).
One approach is to add log statements outputting debug information like variable names, loop counter statuses, null checks, but this quickly become more time-consuming than it’s worth, and being able to debug in the IDE gives you more control and ultimately saves a lot of time.
You might not believe me, but try a few rounds of entering log statements and restarting and then we’ll talk. If you’re not even doing that and entering System.out.println then shame on you!
How to set it up for Tomcat6/Eclipse
This article covers setting it up for Tomcat6 only because it’s slightly different. There are undoubtedly resources out there for your favourite web server / IDE combination so take a look.
In order to remotely debug the IDE needs to connect to another port where your app server is running (another meaning one than the port on which it accepts HTTP connections).
There are two parts to making this happen:
- Telling the JVM on the web server which port to use for remote debugging
- Telling your IDE which host and port to listen to
Tomcat6 is usually set up as a service on Windows and that makes setting the JVM arguments a little more complicated.
- Open a command prompt in your
/bin folder, e.g. “C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin” - Use the tomcat6.exe utility to update the existing Tomcat6 service to add the JVM arguments. The arguments begin with -X and are separated by semi-colons.
tomcat6 //US// —JvmOptions -Xdebug; -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
The first argument tells the JVM to remotely debug and the second to accept a socket connection on port 8000. You don’t have to choose this port, any sensible free port will do.
That’s the web server set up. Now you need to set up Eclipse.
- Go to Run>Debug Configurations and click the icon at the top of that screen to create a new one
- Enter the host (in the picture I’m running my server locally hence localhost) and the port that you configured it on.
That’s all the set up. Now you just need to start the web server, set a breakpoint (e.g. in your login.jsp) and navigate to the login page on your development server. You should see your breakpoint hit.
Good luck!

