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.

Have fun!

–jsp

Advertisement

JBoss Logging Got Ya Down?

Okay, I admit it, I like JBoss. Well, once I finally got the hang of it, that is. But logging was always something that drove me crazy. On my current project, my client is using Liferay portal and JBoss together, and let’s just say there was some friction. I used to get log messages that looked like this:

10:14:10,134 INFO  [stdout] (JMS Session Delivery Thread - DeidentifiedThreadId) INFO  - ==> Got message:

Notice the [stdout] next to the log message. Because of this, JBoss does not know how to control the logger. Many posts I read recommended putting org.apache.log4j as an exclusion in jboss-deployment-structure.xml. I did this and it did not work. If you are using JBoss EAP 6.x DO NOT DO THIS! READ ON!

First of all, I could never reliably get my log messages to show up (using log4j). Sometimes they would come out, sometimes they wouldn’t. It drove me nuts! We started using JBoss EAP 5 and have now upgraded to 6.1. There has been some pain.

First, we were using a jboss-deployment-structure.xml file to control dependencies (and exclusions). Until today, I had org.apache.log4j under <exclusions>. No more! My jboss-deployment-structure.xml went from this:

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <deployment>
    <exclusions>
      <module name="org.apache.log4j" /> 
      <module name="org.hibernate" />
    </exclusions>
    <dependencies>
      <module name="org.apache.log4j" />
      <module name="com.liferay.portal" />
      <module name="javax.mail.api" />
      <module name="org.apache.xerces" />
      <module name="org.jboss.modules" />
      <module name="org.apache.cxf" />
    </dependencies>
  </deployment>
</jboss-deployment-structure>

To this:

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <deployment>
    <exclusions>
    </exclusions>
    <dependencies>
      <module name="org.apache.log4j" /> 
      <module name="org.hibernate" />
      <module name="org.apache.log4j" />
      <module name="com.liferay.portal" />
      <module name="javax.mail.api" />
      <module name="org.apache.xerces" />
      <module name="org.jboss.modules" />
      <module name="org.apache.cxf" />
    </dependencies>
  </deployment>
</jboss-deployment-structure>

Now I can control log output through the JBoss console (or by changing standalone.xml directly). My log messages come out with the correct logger name and everything works.

Just thought I’d pass that along!

–jsp