Remote Debug JBoss or Tomcat from Eclipse
How To Remote Debug JBoss from Eclipse
These instructions describe how to remote debug a JBoss application server from within the Eclipse Development Environment.
Prerequisites
- JBoss
- Eclipse
- You must have the source of the code you wish to debug imported into Eclipse. (Ensure that the version of the source code is the same as the version of the runtime code)
- The code being debugged must have been compiled with line numbers and debug symbols enabled
- If you are debugging a remote server accessed via ssh, you need to create a tunnel on the port you have chosen (e.g. 8787).
On the JBoss side of things
You must enable Java JDWP debugging in JBoss. JDWP is enabled in any Java VM by adding a specific runtime option (-Xrunjdwp). This runtime option includes the transport to use and the details of that transport.
In your JBoss installation, open up the run script (e.g. run.bat on Windows) and find and uncomment the following line:
rem set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%
Once that line is uncommented, the next time JBoss is started it will be listening for remote debuggers on port 8787. Feel free to change the port to whatever you want. Also note the "suspend=y" flag. That flag controls whether the application will wait for a debugger connection before actually starting up. If that flag is set to "y" then JBoss will not start until you connect your debugger. This is useful, for example, when debugging bootstrap code. In most cases, setting it to "n" when debugging JBoss is desirable.
Go ahead and start JBoss now. Depending on the state of the "suspend" option, JBoss will either start up normally or it will appear to be frozen (but actually waiting for your debugger to connect).
On the Eclipse side of things
- Create a new Debug Configuration of type Remote Java Application
- Go to Run->Debug Configurations
- Right-click on Remote Java Application in the left panel
- Click New
- Fill out the info - give the configuration a name, select the Eclipse project that contains the source code you are debugging, set your connection properties (these should correspond to the settings in your JBoss run.bat)
- Click Apply - do not click Close (keep the Debug Configurations dialog open)
- Make sure your new Debug Configuration is selected, then click the Debug button
- Eclipse will attach to JBoss
- If you set the "suspend" option to "y" then JBoss will now start up
- Set breakpoints, point your browser at your web app, step through your code
For remote debugging Tomcat
The catalina script (sh or bat) supports JPDA natively. See nice instructions in Sakai wiki for how to set up. The eclipse side is the same.