9/26/2012

How to Create Global Modules in JBoss AS7

In other Java application servers and previous versions of JBoss AS, there is the concept of common lib, where users can put shared libraries for use by all deployed apps. How to achieve the same effect in AS7 with modules and their dependency? The easiest (not necessarily the best) way is to create a global module for a collection of shared jars.

1, Create a module directory structure: 

mkdir -p $JBOSS_HOME/modules/com/mycompany/myproject/main 

2, Copy common jar files to the above directory: 

cp my-util.jar my-service.jar $JBOSS_HOME/modules/com/mycompany/myproject/main

3, Create a module.xml file in the new module's main directory:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mycompany.myproject">
    <dependencies>
        <module name="javaee.api"/>
    </dependencies>

    <resources>
        <resource-root path="my-util.jar"/>
        <resource-root path="my-services.jar"/>
    </resources>
</module>

4, Declare the module com.mycompany.myproject as a global module, by editing $JBOSS_HOME/standalone/configuration/standalone.xml. Add to the ee subsystem:

<subsystem xmlns="urn:jboss:domain:ee:1.1">
    <global-modules>
        <module name="com.mycompany.myproject" slot="main"/>
    </global-modules>
</subsystem>

Editing server configuration files is not a good idea, but so far this is the only way of adding global modules.