Friday, January 16, 2009

Remote Debugging - Tomcat + Eclipse

I am assuming that you have setup Tomcat by exploding its zip distribution. Windows installer distribution of Tomcat doesn't contain all config and script files including catalina.bat or catalina.sh . I used
- Tomcat 6.0.18
- Eclipse 3.4

- Windows XP


Tomcat Configuration
  1. Go to CATALINA_HOME\bin and edit catalina.bat in any editor, say Notepad++ . Here CATALINA_HOME is your tomcat installation directory. For me it is C:\Tomcat6.0 .
  2. Find JPDA_TRANSPORT and set it as JPDA_TRANSPORT=dt_socket .
  3. Find JPDA_ADDRESS and set it as JPDA_ADDRESS=8000 (you can use any unused port).
  4. Check if port specified is not being already being used; by executing "netstat" at command prompt. Check list of local ports.
  5. Save your changes.
  6. Start your server in debug mode by hitting "catalina jpda start". You may like to add CATALINA_HOME\bin in you PATH environment variable.
Eclipse Configuration
  1. Click on green beetle -> debug configurations...
  2. At Remote Java Application, click new and configure the settings.
  3. Give a name to this debug configuration (homebase-tomcat for me).
  4. Type localhost at Host or any name you have given to you localhost, mapped to 127.0.0.1 in hosts file (localhost.mlbam.com for me).
  5. Type 8000 as the port. Please note that the port must be the same with the JPDA_ADDRESS in catalina.bat file.
  6. Browse the project that you would like to debug.
  7. Click on debug button.

Debugging
  1. Go to your code and put breakpoints by double clicking on the left panel, wherever you want to debug.
  2. Hit your server by opening pages, where you want to debug, in browser.
  3. You will see eclipse switches to debug perspective and debug control flow stops at first breakpoint on the way.
  4. Use following eclipse shortcuts to proceed debugging
  • F5 - Step into (you may like to go inside any method on the way)
  • F6 - Step over (line by line)
  • F7 - Step return (coming out back after going down into a call hierarchy)
  • F8 - Resume debugging (breakpoint to breakpoint)
  1. Use terminate and disconnect buttons to stop debugging
You all set to play with debugging!!

No comments:

Post a Comment