Wednesday, April 25, 2012

How To Debug In Eclipse

1) change the '' file as below which is in 'bin' folder of your tomcat directory.Add below lines.

# Debug settings
export JAVA_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5013 $JAVA_OPTS"

2) Start your tomcat server.You can see now server is listening on port 5013.

3) Open debug perspective in eclipse. It will be shown like below in right side corner of eclipse.

4) In Eclipse Run -> Debug Configurations -> Remote Java Application (double click on this option to get below window) and you will get below window.Specify a name & debug port you have set in tomcat.(In above image you can see, it is set to 5013).The debug profile will be added under remote java application.

Click 'Apply' & click 'Debug'.

5) Once you click 'debug', in above window, it will open the debug perspective.You can see how we have kept a break point in one method.After creating the break point, log in to app and execute search or whatever the operation.But as we have the break point, operation will stop in the immediate previous line without executing line with break point.But in variables window, we can see all variable values of that line with break point as shown below.

6) following shortcut keys can be used as well.

F5 - step into (inspect within method)
F6 - step over (go to next line)