Tomcat remote debugging

Sometimes your web applications behave different when deployed to the application server although everything worked fine when running inside Eclipse on your workstation.

In this case it is helpful to remote debug the application. In case of using Tomcat as application server just add the following VM parameters to JAVA_OPTS:

-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

I do this inside the file setenv.sh in the bin directory by adding a line JAVA_OPTS="…options…"

The paramete -Xdebug tells the VM to start in debug mode. -Xrunjdwp selects the protocol. Change the port 8000 to an appropriate value for your server (one that is not used by another process and is reachable). By setting the value `suspend=n``` the VM does not wait until a remote debugging session connects until starting.

Now all you have to to is start the server and run a remote debug session in Eclipse. You do this by selecting “Run -> Debug…” from the menu. Then the following dialog appears:

Select the project that contains the application running on the server, enter the hostname of the server and the port you configured in the VM options and click Debug. Now set your breakpoints and debug your application.