Remote Debug : Java Application using JDWP

Debugging application is always a common topic for all developers and it may cover more than 60%+ of total development time if using traditional way like using debugging message.

After the release of Sun Java Development Kit 1.4.2, you can be benefited by the magic tool called JDWP (Java Debugging Wire Protocol), It provides sophisticated implementation for debugging your JAVA application in a modern way, especially when you want to debug server java application like Tomcat, JBoss, etc..

Okay, you may say you are happy using debug message for debugging remote application and thus let me list the summary of how JDWP can aid the development.

  1. Thread stepping execution: Suspend/Resume particular thread
  2. Breakpoints management: Insert/Remove breakpoint for investigate failure point
  3. Hotswap Bug Fixing: Recompile the classes on-the-fly for bug fixing without redeployment

I thought you may be interested with the features 3, which greatly reduces the re-deployment time for debugging an application.

This articles will focus how the setup for debugging remote java application. Tomcat5.5 and Eclipse Europa will be used for an example.

1. High Level View

Basically it is divided into two entities: Debuggee and Debugger. The Debuggee is the application that you want to debug and for our example it is Tomcat. The Debugger is the vendor of JDI (Java Debugging Interface) : Eclipse.

jpda

 

2. Enable JDWP in the Debuggee (Tomcat)

JDWP can be enabled out of the box by setting the appropriate system properties :

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

This enables JVM with JDWP at port 9002 using server mode with any suspension.

Server
(“n” or “y”) If “y,” listen for a debugger application to attach; otherwise, attach to the debugger application at the specified address.
Address
transport address for the connection. If server=n, attempt to attach to a debugger application at this address. If server=y, listen for a connection at this address.
Timeout
If server=y, this specifies the timeout, in milliseconds, to wait for the debugger to attach. If server=n, this specifies the timeout, in milliseconds, to use when attaching to the debugger.
Suspend
If “y,” JVM suspends the execution until a debugger connects to the debuggee JVM. Preferably set this option to “n” else the application will not start unless the debugger attaches the port on which debugee  application is lessoning.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s