Skip to content

Instantly share code, notes, and snippets.

@mchung
Created June 24, 2013 01:36
Show Gist options
  • Save mchung/5847244 to your computer and use it in GitHub Desktop.
Save mchung/5847244 to your computer and use it in GitHub Desktop.
remote debugging java processes
Let’s assume you’ve got an executable JAR file which launches a server listening on port 4444.
server:~ mchung$ java -jar server.jar
or
server:~ mchung$ java -classpath server.jar com.mchung.Server
Launching a Java process with debugging activated is easy when you pass in the correct arguments:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
For example:
server:~ mchung$ java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -jar server.jar
Once it starts, you can configure Eclipse, IntelliJ, NetBeans, JSwat, or any other JPDA-based debugger to connect remotely to your process at localhost:8000
Most of the challenges when integrating with a remote debugger, is configuring the correct CLASSPATH.
To make matters easier:
When compiling the JAR file, include the source code as well.
If that’s not possible, create a second JAR containing only source code.
Debuggers will let you configure a classpath which is used to map bytecode back to the source.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment