Advertise with us

Our eBooks

How to install a module on WildFly / JBoss EAP

Installing a module on WildFly / JBoss EAP requires creating a path under the JBOSS_HOME/modules folder. Under this path, you will install the JAR libraries which are part of the module and a module.xml file which describes the module itself and dependencies with other module.

Example1: Manually creating the module for Quartz library:

Create the following path under the JBOSS_HOME:

$ mkdir -p $JBOSS_HOME/modules/org/quartz/main

 Now include in the main folder the XML descriptor of the module (module.xml) and the JAR files. Here's a view of your modules structure:

+---org
      +----quartz
                +-----main
                        module.xml
                        quartz-all-2.0.2.jar
This is a sample module.xml configuration for your module:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.quartz">
   <resources>
      <resource-root path="quartz-all-2.0.2.jar" />
   </resources>
   <dependencies>
      <module name="org.slf4j" />
      <module name="javax.api" />
   </dependencies>
</module>

This basically says that the module has a dependency on the other modules: org.slf4j (logging framework) and javax.api module.

Example2: Using the CLI to create the "org.postgres" module:

$ module add --name=org.postgres --resources=postgresql-42.2.5.jar --dependencies=javax.api,javax.transaction.api

That will result in the following structure created under your modules folder:

/home/jboss/wildfly-16.0.0.Final/modules
└───org
    └───postgres
        └───main
		module.xml
		postgresql-42.2.5.jar

The module.xml file is already configured with the required dependencies in place:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.postgres">
  <resources>
    <resource-root path="postgresql-42.2.5.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

Using properties in your module

Besides declaring dependencies, you can also specify some System Properties, so that they are loaded up when the module is available. Here's an example:

<module xmlns="urn:jboss:module:1.1" name="com.mymodule" >

    <properties>
        <property name="property.name" value="property.value"/>
    </properties>

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

</module>

How to use a Module in your application

In order to use this module in your applications you have to trigger a dependency on the module. This can be done by adding into the META-INF/MANIFEST.MF file a Dependency [modulename]

Example:

Dependency: org.quartz						

How to define a global module

It is also possible to set up global modules, that are accessible to all deployments. This is done by modifying the configuration file (standalone/domain.xml).
For example, to add javassist to all deployments you can use the following XML in your standalone.xml/domain.xml

<subsystem xmlns="urn:jboss:domain:ee:1.0" >            
  <global-modules>
    <module name="org.javassist" slot="main" />            
  </global-modules> 
</subsystem>

Note that the slot field is optional and defaults to main.

If you want to learn more about modules installation, check out the next tutorial which shows how to install different releases of a module using module slots.

Please notice that, since WildFly 19, you can also use global directories in your configuration: Configuring global modules and directories in WildFly

© 2021 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.