DEBUG tomcat with eclipse
by krishna
Whichever platform you are using (Tomcat or JBoss) you need to start them with the JPDA debugging enabled. For Tomcat this is very easy. In the $CATALINA_HOME/bin directory there is a script catalina.sh. If you provide the arguments ‘jpda start‘ tomcat will startup and listen on port 8000 for a debugger connection.
The value of JAVA_OPTS needs have -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=6666,suspend=n specified.
So this is what is going on with this argument list
Xdebug start the jvm and listen for debugging connections
Xrunjdwp the info on how to connect to do remote debugging
server=y start in server mode (i.e. wait for connections, don’t go out looking to connect
transport=dt_socked use sockets, this works (I think) only on unix, on Windows you have to use shared memory via the transport=dt_shmem argument instead. I’m fairly sure this works but its been a while since I tried it on Windows.
address=6666 the port to connect to or the shared mem address to use
suspend=n don’t wait for a debugger to tell you what to do, go ahead and launch
Once you have JBoss or Tomcat running and listening for debugging connections you are good to go for connecting with Eclipse
1. The first thing you need to do is create a ‘debug launch configuration’ by bringing up the launch configuration editor.
2. When the launch config editor appears select ‘Remote Java Application’ from the ‘Configurations:’ selection list on the left hand side then click the ‘New’ button
3. Since it defaults to the Tomcat port leave the port number set to 8000, if yours is different then change it to 8000. Notice also that you can specify the host to connect to. If you have access to the port and the process is running on another machine then you can debug the process remotely. This works out really well for those situations where it works fine in your local environment but not in the test environment. I usually rename the configuration (it defaults to the name of the project for me) to ‘Debug Tomcat’ or something like that.
4. The other options (Source & Common) can be ignored for now. If you have not already launched tomcat in debug mode do so now on the command line with $CATALINA_HOME/bin/catalina.sh jpda start. When its launched go back to the Eclipse launch configuration editor and hit the ‘Debug’ button. If you are not auto switched to the ‘Debug’ perspective go there now.
5. Your code should be directly below the Debug View if you have the default layout still in place. If so go there and set a break point in one of your servlets’ service methods (or any other code that is being executed in Tomcat, like a struts action or whatever) and then go to the Web browser and tickle the code that you have a break point set in. Notice that Eclipse suspends Tomcat at the breakpoint, comes to the front and lets you debug your program. Everything works just as if you were debugging locally.
6. Everything works the same within JBoss once you get it started with the debugging turned on. Keep in mind that you must set the port to match (in the above discussion of JAVA_OPTS it is set to 6666). So you need to create a new Debug launch configuration and specify 6666 as the port. Then you can debug your EJBs.
Whichever platform you are using (Tomcat or JBoss) you need to start them with the JPDA debugging enabled. For Tomcat this is very easy. In the $CATALINA_HOME/bin directory there is a script catalina.sh. If you provide the arguments ‘jpda start‘ tomcat will startup and listen on port 8000 for a debugger connection. The value of…
Recent Comments
Archives
- August 2025
- July 2025
- June 2025
- May 2025
- April 2025
- March 2025
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- January 2024
- December 2023
- November 2023
- February 2012
- January 2012
- December 2011
- October 2011
- August 2011
- July 2011
- May 2011
- January 2011
- November 2010
- October 2010
- September 2010
- July 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- August 2008
- July 2008
- June 2008
- December 2007
- April 2007
- January 2007