JBoss AS 7 Debugging With Eclipse
If you have ever wanted to debug application code running on a instance of JBoss then this post is for you. This information is in various places on the Net, but I thought I would pull it together in one spot. That’s how I roll.
First off, I use JBoss EAP 6.1 (AS 7) and Eclipse Juno. These instructions will probably work for you should your versions be different. Just wanted to get that out of the way.
Next, You will need to start JBoss with a few extra options to the JVM. You can set these either in standalone.xml, or via the JAVA_OPTS environment variable. The options look basically the same, but for this post I will use JAVA_OPTS. Read this post from the JBoss Community forum if you want to use standalone.xml to configure the JVM parameters.
Add this line to your existing JAVA_OPTS:
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
The port number (8787) above must match your Eclipse setup (see below).
Finally, you will need to tell Eclipse how to connect to the remote process. In Eclipse, click the Debug button’s drop-down arrow and select “Debug Configurations”.
- In that dialog, navigate to “Remote Java Application” and click the “New” button.
- Under “Project” select the project that contains the code you want to debug.
- Under Connection Type make sure “Standard (Socket Attach)” is selected.
- Under Connection Properties, make sure the host (e.g., localhost) and port (which must match the port spec in the JAVA_OPTS, in this case 8787) are set.
- Click on the “Source” tab and add any projects containing code you want to debug (if there are other projects in your workspace that contain code other than the main project).
- In the Common tab, under “Display in favorites menu” select the Debug icon and a handy dandy icon will appear in your Debug toolbar dropdown (the name will be the same as the Project setting from earlier).
If JBoss is already running (with the options set earlier) click Debug to attach. If not, start JBoss, then click Debug to attach.
Now you can set breakpoints, step through your code, etc.