Adding a Module to JBoss EAP

15 minutes
  • 4 Learning Objectives

About this Hands-on Lab

The JBoss Enterprise Application Platform provides extensive support for deploying and managing Java-based applications. Part of this support includes the ability to add and create modules, which in turn opens up additional functionality for your application — such as allowing the option to connect to a MySQL database, as in this lab.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Download Module Drivers
  1. Download the MySQL JDBC connector:

    wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.18.tar.gz
  1. Extract the contents:

    tar xf mysql-connector-java-8.0.18.tar.gz
Create Module
  1. Move into the modules directory:

    cd /opt/jboss-eap/modules
  1. Create com directory to store local, non-system modules:

    sudo mkdir com
  2. We can now create the mysql module directory underneath this; each module stores all required configurations and JAR files in a required main directory, so create this, too:

    sudo mkdir -p com/mysql/main
  3. Move the downloaded .jar file into this new directory:

    sudo mv ~/mysql-connector-java-8.0.18/mysql-connector-java-8.0.18.jar com/mysql/main/
Create .xml File

Within the main directory for the mysql module, create a module.xml file to configure the MySQL JDBC diver. Note that the name of the module must mimic the directory structure — in this case, it should be com.mysql:

sudo vim com/mysql/main/module.xml

<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
  <resources>
    <resource-root path="mysql-connector-java-8.0.18.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

Note that the dependencies provided are system modules, found in /opt/jboss-eap/modules/system/layers/base/javax/.

Add as a Global Module
  1. Open the management CLI:

    cd ..
    sudo ./bin/jboss-cli.sh
  1. Connect:

    connect
  2. Add the module to global modules, under the EE subsystem:

    /subsystem=ee:list-add(name=global-modules,value={name=com.mysql})
  3. We can check that the module has been added by logging in to the Management Console at PUBLICIP:9990 using the username admin and the password pinehead. Select Start, under Configuration, then select Subsystems from the menu. View the EE subsystem. Select Global Modules — the com.mysql module should be listed.

Additional Resources

You are setting up a new JBoss EAP standalone configuration to support a fledgling project for your team. The standalone server will support a number of small applications, each needing the ability to connect to an existing MySQL database. Because of this, the MySQL JDBC driver needs to be added as a module to the standalone server setup. Since all applications need access to this module, it should be enabled as a global module.

The JBoss EAP home directory can be found at /opt/jboss-eap. To log in to the Management Console, use PUBLICIP:9990 with the username admin and the password pinehead.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?