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
Download the MySQL JDBC connector:
wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.18.tar.gz
Extract the contents:
tar xf mysql-connector-java-8.0.18.tar.gz
- Create Module
Move into the
modules
directory:cd /opt/jboss-eap/modules
Create
com
directory to store local, non-system modules:sudo mkdir com
We can now create the
mysql
module directory underneath this; each module stores all required configurations andJAR
files in a requiredmain
directory, so create this, too:sudo mkdir -p com/mysql/main
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 themysql
module, create amodule.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 becom.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
Open the management CLI:
cd .. sudo ./bin/jboss-cli.sh
Connect:
connect
Add the module to global modules, under the EE subsystem:
/subsystem=ee:list-add(name=global-modules,value={name=com.mysql})
We can check that the module has been added by logging in to the Management Console at
PUBLICIP:9990
using the usernameadmin
and the passwordpinehead
. Select Start, under Configuration, then select Subsystems from the menu. View the EE subsystem. Select Global Modules — thecom.mysql
module should be listed.