Monday, October 15, 2012

How to Debug In Eclipse

neststat -a |grep http

eg:netstat - nap|grep "127.0.0.1"



Any port which is not used above, can be set at debug port.

In Tomcat -> bin , we have the catalina.sh file. Paste the below lines to that file.Port specified should be the debug port.

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

Then in eclipse, right click on project and then go to Debug As -> Debug Configurations --> Remote Java Application --> (Rightclick on this) --> New and we get the below wizard.


 Port in above window should be the debug port we have mentioned earlier.

We can hav below in build.xml file.This is a task which will help start tomcat in debug mode.

<target name="tomcat-start-debug">
      <echo message="##############################################################" />
      <echo message="#                      Debugging Tomcat                     #" />
      <echo message="##############################################################" />
      <java jar="/home/ishara/Development/Tomcat/apache-tomcat-6.0.35/bin/bootstrap.jar" fork="true">
       <jvmarg value="-Dcatalina.home=/home/ishara/Development/Tomcat/apache-tomcat-6.0.35"/>
       <jvmarg value="-Xdebug"/>
       <jvmarg value="-Xrunjdwp:transport=dt_socket,address=5013,server=y,suspend=n"/>
      </java>
     </target>

run the task as below.

ant tomcat-start-debug

once tomcat is up, go to eclipse and debug --> debug configuration --> select saved remote java application and click on 'Debug' button.

Keep a breakpoint where necessary.

Then start your app, and it will stop at where break point is kept.