JBoss AS7 Module Introduction

AS7's class loading is based on JBoss Modules. To understand JBoss's class loading mechanism, you first need to understand how JBoss modules work.

  • Ryan
  • 2 min read
/images/posts/jboss-module-system.png

Compared to earlier JBoss versions, AS7’s class loading mechanism is entirely different. AS7’s class loading is designed around JBoss modules.

What is a module

A module is a collection of classes and resources, and each module corresponds to a class loader. Modules can have dependencies on one another: if a JAR in one module needs to use classes from a JAR in another module, the dependency must be declared explicitly; otherwise the modules are invisible to each other. Likewise, if you deploy an application to a JBoss AS7 container and the application depends on modules, those dependencies must also be declared explicitly.

If you want to understand the JBoss AS7 module loading mechanism in depth, see: JBoss Module Analysis

Benefits of modules

  1. JARs of the same version are not loaded repeatedly.
  2. Avoids JAR version conflicts.
  3. Provides a more efficient class loading mechanism.

JBoss AS7’s modules

Under the JBoss AS7 installation directory there is a folder called modules that contains a substantial number of built-in modules.

Taking the module org.apache.commons.beanutils as an example, enter the folder <JBoss installation directory>/modules/org/apache/commons/beanutils/main/ and you will see the following files:

total 232
-rw-r--r--. 1 root root 232019 Jan  2  2013 commons-beanutils-1.8.3.jar
-rw-r--r--. 1 root root   1540 Jan  2  2013 module.xml

Among them, module.xml is the module descriptor file, with the following contents:

<module xmlns="urn:jboss:module:1.1" name="org.apache.commons.beanutils">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>

    <resources>
        <resource-root path="commons-beanutils-1.8.3.jar"/>
        <!-- Insert resources here -->
    </resources>

    <dependencies>
        <module name="org.apache.commons.logging"/>
        <module name="org.apache.commons.collections"/>
    </dependencies>
</module>

name=“org.apache.commons.beanutils” is the module’s name and its unique identifier; modules reference each other by specifying this name when declaring dependencies.

resources describes which JAR files the module contains.

dependencies defines the modules this module depends on.

How to configure a JAR as a JBoss module

Configuring a third-party JAR as a JBoss module is also simple: first define the module.xml file, then create the corresponding directory structure under JBoss’s modules directory based on the name, and finally place module.xml and the JAR into the created main directory — the JAR then becomes a JBoss module. There are many detailed steps online, so I won’t repeat them here.

Written by : Ryan

Writing about distributed systems, AI engineering, and production internals.

Recommended for You

JBoss AS7 Class Loading Mechanism

JBoss AS7 Class Loading Mechanism

An introduction to the JBoss AS7 class loading mechanism, covering implicit module dependencies and deployment processors.

The Implementation Details of hashCode()

The Implementation Details of hashCode()

A deep dive into the implementation of Java's hashCode() method, from class loading to hash collision handling.