Let’s assume you’ve got an executable JAR file which launches a server listening on port 4444.

tonkatsu:~ mchung$ java -jar server.jar

or

tonkatsu:~ 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:

tonkatsu:~ 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:

  1. When compiling the JAR file, include the source code as well.

  2. If that’s not possible, create a second JAR containing only source code.

  3. Debuggers will let you configure a classpath which is used to map bytecode back to the source.