8f-xga
Last Updated: November 21, 2017
·
6.932K
· davewatts
Thir

Remote Debugging a Java Application

Add the following to the java command line, after the 'java' but before app-specific args

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

If you run your app as follows:

java -jar app.jar

It would become

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar app.jar

Explaination of parameters (from http://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionX.html)

-Xdebug enables debugging capabilities in the JVM

-Xrunjdwp loads the JPDA reference implementation of JDWP

  • server=y means listen for a debugger application to attach
  • transport-dt_socket is the name of the transport to use in connecting to debugger
  • address=8000 means listen for a connection at this address (no host = this port on add interfaces)
  • suspend=n means do not wait for a debugger to attach

The most relevant options are address, if you need to change the port, and suspend, if you want the java process to wait for you to attach the debugger before execution starts

When debugging a third party tool, the java command line is often in a script. Some of these are described below

Ant

Set the environment variable ANTOPTS to
"-Xdebug -Xrunjdwp:server=y,transport=dt
socket,address=8000,suspend=n"
before running ant.

You can also edit the scripts $ANTHOME/bin/ant or %ANTHOME%\bin\ant.bat. Look for lines referencing JAVACMD for the java command lines used

Tomcat

Edit $CATALINAHOME/bin/startup.sh / $CATALINAHOME\bin\startup.bat

Look for lines referencing EXECUTABLE start, and change them to EXECUTBLE jpda start

The environment variables JPDATRANSPORT, JPDAADDRESS, and JPDASUSPEND can be used for configuration (defaults are dtsocket, 8000, and n respectively). See $CATALINAHOME/bin/catalina.sh / $CATALINAHOME\bin\catalina.bat for more info

More to follow as I need them

Say Thanks
Respond