Remote debugging in Eclipse

With Eclipse IDE it is possible to debug Java application which runs on local computer (localhost) or on a remote server.

I created DebuggerTest project for this tutorial, but any other debuggable application can be used. The main method is in si.matjazcerkvenik.debuggertest.DebuggerTest class. The class is built into a jar file and ready to run.

Application run configuration

We need to modify the way JVM is started, by adding additional argument -agentlib to the command line.

> java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 -classpath ./DebuggerTest.jar si.matjazcerkvenik.debuggertest.DebuggerTest

The first argument in command (red) tells JVM to open socket 8000 for incoming debugger sessions. Since I am running jar on the same computer as Eclipse Debugger there is no need to specify hostname (ie. localhost); just set the port to 8000 (default). If jar is run on another computer, set address=hostname:8000. Second argument (blue) will run the main method inside jar.

Execute the command. The java application is now up and running.

Configure Debugger in Eclipse

Right click on the project and select Debug As > Debugger configuration...


Hit enter or click Debug button in Debug Configurations window to start debugging. Make sure that application is running. Debugger should stop at first breakpoint. Proceed in the same way as the application would be running in Eclipse IDE.

To stop debugging, click Disconnect button in Debug Perspective -> Debug window.