Remote Debugging JVM Applications |Remote Debugging Tomcat & JBoss Apps with Eclipse

The JVM provides a useful feature called the Java Platform Debugger, or JPDA. When enabled via startup options, it provides a port through which debuggers (e.g. Eclipse) are able to connect and do their thing. This allows you to debug practically any application, such as Tomcat, or in my case, WebTest (running inside of an Ant process).

There are a bunch of available options for JPDA, but here is the basic incantation:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8008
  • jdwp: Java Debug Wire Protocol
  • transport: indicates that debuggers should attach using sockets, as opposed to the other option, which is shared memory (dt_shmem)
  • server: when 'y', listens for a debugger application to attach (otherwise, attempt to connect to the specified debugging instance)
  • suspend: the JVM should wait for a debugger application to attach before starting up
  • address: the port to expose for debugger applications (or address to connect to in order to debug)

*Note: you may have seen a different set of arguments for starting a JVM in debug mode:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8008
This is required for Java versions < 5.

You can find a full list of options here.

Now that you have your application faithfully waiting for you to debug it ('Listening for transport dt_socket at address: 8008'), you just have to set up a remote debug configuration in Eclipse and run it:
  1. Run > Debug Configurations... > new Remote Java Application
  2. Connection Type: Standard (Socket Attach)
  3. Connection Properties: host and port of JDWP application
  4. Allow termination of remote VM: if selected, when you are finished with the debugger and click the terminate button in Eclipse, the remote application will exit also

No comments:

Post a Comment

Please Provide your feedback here