Java/JBoss EAP 6.1+ – Power to the Properties

Posted: October 28th, 2013 | Author: | Filed under: Technology | Tags: , | 1 Comment »

Resources within a Core Module

Class loading in EAP6 is considerably different than previous versions of JBoss as it utilizes a modular class loader based on the JBoss Modules project instead of a hierarchical class loading structure. One can hook into this modular architecture to add external resources, such as properties files, to the classpath of an application by creating a core module. User defined core modules are a common practice and are typically used to add third party database driver support to EAP. Fellow Red Hat consultant Joey Yore has compiled a detailed article on how to create a core module and the methods of adding the dependency to a project.

An example core module has been provided in the support folder of the sample application at <APP_ROOT>/support/modules. To add the module to JBoss, copy the contents to the <JBOSS_HOME>/modules folder.

After the module has been installed within JBoss, it is eligible to be utilized by deployed applications. One of the methods to add a module to an application as described in Joey Yore’s article is to add it as a dependency within the jboss-deployment-structure.xml file. A sample file can be found at <APP_ROOT>/support/build/jboss-deployment-structure.xml and contains the following:

<?xml version="1.0" encoding="UTF-8"?>
            <module name="com.andyserver.jboss"/>

To build the project with the user defined core module included as a dependency, run the following command:

mvn clean install –P jboss-module

This Maven profile will package the jboss-deployment-structure.xml file from the support folder into the WEB-INF folder of the application. After the application is deployed, the values from the <JBOSS_HOME>/modules/com/andyserver/jboss/main/ should be displayed within the application.

Alternatively, instead of defining a module as a dependency within an application, a core module can be defined as a global module within the JBoss server itself. This will cause the module to be included as a dependency by all applications. Global modules can be added via the CLI or the Management Web Console. Since we discussed CLI usage earlier, let’s demonstrate how to add the global module using the Management Console. The Management Console can be accessed at http://localhost:9990. Global modules are defined on the profile page by expanding Container and selecting EE on the left hand navigation. Clicking the Add button will present a dialog for defining the properties of the global module. Enter com.andyserver.jboss in the name field and specify alt instead of the main in the slot field. The slot parameter allows for multiple release versions of a module to be included in JBoss. Our module includes two versions (the default [main] which was utilized in the jboss-deployment-structure.xml file earlier and alt which is being utilized now as a global module). After redeploying the application, the values from the alt version of the module should be visible in the application.

Note: Even though we just finished covering the process of utilizing resources in a global module, using resources within global modules is not a recommended approach. It may cause unexpected and unforeseen issues to other applications deployed on the server. It was covered purely for demonstration purposes.

So far, we have covered four methods for loading resources onto the classpath. As you have seen, each implementation supersedes the values previously configured. The following is the order of precedence these resources are found by the classloader:

  1. Core module configured as a global module
  2. Core Module included as a dependency in an application
  3. Deployment overlay
  4. Resource packaged within an application

One Comment on “Java/JBoss EAP 6.1+ – Power to the Properties”

  1. 1 christophe said at 10:15 am on November 3rd, 2014:

    Thanks for that nice article.
    I tried your example with AS7.1, but did not work. It seems that deployment overlay works as from AS7.2(EAP6.1)

Leave a Reply