Servlet Debugging

The Basics

The most important aspect in debugging Java servlets using JSwat is how you start the application server. The application server must be started with the debugging flags passed to the server JVM. An example is shown below:

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

Now you can use the remote attach functionality in JSwat to connect to the running application server. Note that many application servers have startup scripts that must be run to properly bootstrap the system. You may want to read these scripts to better understand how to enable remote debugging. Below are instructions for some specific application servers.

Apache Tomcat

Debugging web applications running in Tomcat is quite simple. To start Tomcat with debugging support enabled, you must invoke the catalina.sh or catalina.bat with the arguments "jpda start".

If your Tomcat installation does not have a catalina script, then add the debugging flags shown above to the Java Options section in the Java Tab of the Tomcat Properties window.

By default the catalina.sh Unix shell script will run the socket transport on port 8000. The catalina.bat Windows batch file will use the shared memory transport with the name "jdbconn". Both of these addresses can be changed by setting the JPDA_ADDRESS environment variable before starting Tomcat. Additionally, you can set the desired transport by setting the JPDA_TRANSPORT environment variable.

Once Tomcat has been started with debugging enabled, simply connect to the socket or shared memory address using the remote attach functionality in JSwat. From there you can set breakpoints and debug as usual.

Macromedia JRun

Debugging web applications running under Macromedia JRun is possible with a little editing of the configuration files.

Version 3.x

Edit the file jrun_home/servers/default/local.properties and set the java.args.debug parameter like so:

java.args.debug = -Xdebug -Djava.complier=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5000

In a command shell, start JRun with the following options: jrun -start default -debug

Now start JSwat and use the remote attach functionality to connect to JRun on port 5000. At this point you can set breakpoints and debug in the usual manner.

Version 4.0+

The file to edit is called SERVER-INF/jvm.config and the property is named java.args. You need to add the debug flags to this property, just as would be done for version 3.x.