Saturday, September 28, 2013

Remote debugging Java applications using Eclipse IDE

Java applications can be debugged by attaching its source to a remotely IDE following a client-server approach. The running Java application is considered as server and the IDE with source attached is considered as client.

Server (Java application)
The application to be debugged should be started with the following JVM argument for Java 5.0 and beyond.
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n

The debugger listens to the port 8000.

Executing java -agentlib:jdwp=help on the command prompt shows the help and list of options.

For pre Java 5.0, the server should be started with
-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000, suspend=n

Client (Eclipse IDE)
  1. Click the Debug Configurations in the Debug button menu.
  2. In Debug Configurations window, right click Remote Java Application and click New.
  3. Give an appropriate name for the remote debug configuration.
  4. The Connection Type should be Standard (Socket Attach)
  5. Enter the Host on which the Java application is running.
  6. Enter the Port which was used as addresss= while starting the Java application.
  7. In the Source tab select a project or source jar.
  8. Click Apply to save the settings.
  9. Set appropriate break points in the source and start debugging by clicking on Debug in the Debug Configurations window.

No comments:

Post a Comment