Showing posts with label Debug. Show all posts
Showing posts with label Debug. Show all posts

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.

Wednesday, April 25, 2012

How To Debug In Eclipse

1) change the 'catalina.sh' 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)