Friday, December 28, 2012

Configure Tomcat for Remote Debug Your Web Application With Eclipse

Debugging is a vital part of developing any software system. Every developer relay on debug to find bugs and solve those quickly.In case of large code base it is too important.

To do remote debugging  with from eclipse we need to follow steps described bellow .

Before remote debug tomcat from eclipse you need to make sure :
  • Make sure that Tomcat is started in remote debugging mode
  • Make sure that you have the sources for the code that you are trying to debug in your IDE. For the libraries and for Tomcat itself you can "attach" the sources to the jar files: open a class file and then click "Attach Source..." button.
  • If you have a servlet or something, set a breakpoint where it is sure to hit on the next request.
  • Go to "Run->Debug Configurations...". Click on "Remote Java Applications", then click "New". Type in the title. Note that port 8000 from the Tomcat instructions. Save and run.
  • Eclipse will connect to the JVM that Tomcat is running under. Wow, that was easy!

Assume you are not starting tomcat from ide rathe using startup.sh/startup.bat file under /tomcat/bin.

Just add two lines in startup.bat at the end of file but before : 
call "%EXECUTABLE%" start %CMD_LINE_ARGS% 

set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
And change :
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
to 
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS% startup.bat
Now save the file as startup_debug.bat You are ready to start your tomcat in debug mode .Start your tomcat with newly saved *.bat file startup_debug.bat. This will run the tomcat in debug mode.

Setup debug configuration in eclipse ide :
Go to debug configuration this will appear like bellow and replace project name with your one.


You are ready to start debugging . Now hit URL in browser set break point and have fun with debugging .














If you are interested about JPDA then take a look : http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/



No comments:

Post a Comment