How to develop a custom module for JBoss EAP 6x / AS 7

Sometimes you want to be able to share a custom JBoss EAP module across a number of different WARs or EARs on your application server. I cam across this recently when a client had a big module that retrieved a lot of data from a legacy system. Since the data set was so big, it didn’t make sense to deploy the library with every application.

There are really just two steps to the process: build the custom module and then wire up your application to use it.

Step one: create a custom JBoss module

Developing the custom module

If you’re using JBoss AS7 or EAP 6x, you’re probably using Maven. So here’s a pretty minimal pom to get you started. The only real dependency you might want to exclude (but do you really?!?) is Google’s Guava.

Now, let’s do the test driven development thing and start with a test class in the src/test/java Maven directory. If you haven’t worked with this approach with Intellij IDEA, you’re missing out. The ergonomics really are nice.

And here’s the actual implementation class:

Now, let’s assemble the module. Remember how I included the Guava package? Well, to make this demo simple, let’s go ahead and rely on the maven-assembly-plugin that we included in the pom above like this.

First, run mvn clean package, and you’ll see two different artifacts created:

two-artifacts

Installing the custom JBoss module

Now let’s get the module installed. First, create a directory named {jboss_home}/modules/com/redhat/demo/main. The “main” is significant because it lets you configure multiple “slots” if you have different versions of the same module installed on the server. Then copy the JAR file with the dependencies over to that main directory.

Next, we’ll create a descriptor in that “main” directory called module.xml. Mine is ultra simple with the following:

Finally, let’s set up the module as a “global” module so it’s easily available to all the application on AS7/EAP 6 by adding the following to standalone.xml (or the equivalent in domain.xml):

Now start your JBoss AS7/EAP instance.

Step two: start using the module

I created a simple “hello, world” type servlet just to demo the module. Here’s the pom:

And here’s the simple servlet:

That’s it, now deploy it on your instance and you should see it running.

3 thoughts on “How to develop a custom module for JBoss EAP 6x / AS 7”

  1. Very useful tutotial. My 2 cents, the JBoss CLI equivalent to add the module as Global module would be:

Leave a Reply

Your email address will not be published. Required fields are marked *