Java remote debugging is luckily a sufficiently mature protocol that almost all the benefits that the Tomcat plugin gives can be achieved without it, in addition to being able to test in a more "realistic" deployment environment with tomcat invoked using the normal scripts. Here are the steps necessary to set this up in an Eclipse environment:
- Set up a new Tomcat invocation under the "External Tools" menu in Eclipse. This menu button has a picture of a green "Play" button with a small red suitcase in front of it. Create a new entry under "Program" and set "Location" to be the catalina startup script (on my machine E:\jakarta-tomcat-5.0.25\bin\catalina.bat), and make sure to set the working directory to be the directory containing it, otherwise you will need to set CATALINA_HOME. Set "Arguments" to jpda start. Go to the "Environment tab" and make the following two settings: JPDA_ADDRESS to 8000, and JPDA_TRANSPORT to dt_socket. For convenience, in the "Common" tab tick "Display in favorites menu" and "Launch in background".
- Set up the remote debugging task under the "Debug" menu, which looks like a squashed cyan bug. Create a new entry under "Remote Java Application" and add all the projects containing code you wish to debug to the "Source Menu". Tick "Allow termination of remote JVM" (important).
- On Windows, it is helpful to edit the "catalina.bat" file to prevent it trying to start a separate process for Tomcat. If you remove the text that says "start" and "start Tomcat" at the following section:
:doStart shift if not "%OS%" == "Windows_NT" goto noTitle set _EXECJAVA= %_RUNJAVA% goto gotTitle :noTitle set _EXECJAVA= %_RUNJAVA%then the console output from Tomcat will be directed into the Eclipse console, with various benefits such as being able to click on exception traces. A similar alteration would probably help on UNIX as well.
Now, to invoke Tomcat you may click on the "suitcase" icon, and press the "cyan bug" icon at any subsequent time to attach the debugger to it. On Windows it's worth noting that killing the Tomcat process from the "External Tool" view will in general not kill the underlying java.exe process which you will then need to find manually. However, if you have enabled "Allow JVM termination" on the debug entry, killing the process through that interface will work correctly.