Using eclipse to debug your tomcat web application

Got this question again today. Usually i’d say: use the tomcat plugin, but in this case tomcat 3.2.4 is used, as that’s the tomcat version the web server is still using. The eclipse tomcat plugin only supports tomcat 3.3 and up.

Here’s what you do:

  • Start java with remote debugging enabled. You do this by modifying tomcat.bat (assuming you’re on windows). You have to add some parameters when starting java. If you start tomcat from a cmd box, look for the line “echo Starting Tomcat in new window” in tomcat.bat. Add the following line:

    set JAVA_X_OPTS=-Xdebug -Xnoagent\
       -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5000
    

    And modify the star t java line as follows:

    %_STARTJAVA% %TOMCAT_OPTS% -Dtomcat.home="%TOMCAT_HOME%"\
     org.apache.tomcat.startup.Tomcat %2 %3 %4 %5 %6 %7 %8 %
    

    Now you can start tomcat by typing startup.bat in your cmd box.

  • Click on the debug button in your eclipse toolbar. Select the “Debug…” item. This will open a debug window. Under configurations you’ll find an entry “Remote Java Application”. Select this and then press the new button. Choose a project, leave the connection type to “standard (socket attach)” and for connection properties choose “localhost” and “5000” (change these if you’re using a different port or a different machine to run tomcat). Now press apply and debug.

That’s it. You can now set breakpoints in your code, and inspect what your application is doing.

blog comments powered by Disqus