How to do java remote debugging

How to do java remote debugging?

Prerequisite: Application has to be running  in sever and same code you should have in your eclipse.

Step 1:
  • -Xdebug is used  to debug remote JVM.
  • To debug remote application we have to start application in debug mode.
  • We can start application in debug mode by adding below -Xdebug options in JAVA_OPTS of server start-up file(i.e catalina.bat or may be catalina.sh as per your server start-up file)
         -Xdebug -agentlib:jdwp=transport=dt_socket,address=1311,server=y,suspend=n

Example:

JAVA_OPTS="-Xms2048m -Xmx2048m  -XX:MaxPermSize=256m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1310 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=<IP-ADDRESS> -Xdebug -agentlib:jdwp=transport=dt_socket,address=1311,server=y,suspend=n";
export JAVA_OPTS;

Step 2 :
  • Add break points in java file which you want to debug and right click on project, go to debug as -->debug configurations  and double click on 'Remote Java Application'.
  • Now you will get to see host and port(1311 as per above example) fill those fields and click on debug.
Step 3:
  • Now send one request to your server after sending your eclipse will get control.
  • Now use f5,f6,f8 to monitor code flow and variables values.

How to Monitor server JVM Heap?

Note: 
  • In above Example few JMX(Java Management Extension) option, these options are using to monitor server JVM Heap.
  • If you want to monitor server JVM Heap, we have to add above example options.


No comments:

Post a Comment