In this article we’ll create a MySQL module. This can be useful, because a MySQL driver(module) is not part of the core JBoss modules.
First, we have to download JBoss Application Server 7.1.1. If you don’t have an instance, you can download it from here:
First, we have to download JBoss Application Server 7.1.1. If you don’t have an instance, you can download it from here:
After download, unzip to a new directory, wherever you want.
Next step is to get the MySQL connector JAR file. For this article, I use the v5.1.21., so I recommend to download this version.
http://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.21 (Download as JAR)
So, we have a JBoss, and the MySQL driver JAR. Open the ${JBOSS_DIR}/modules/ directory, and create a “com/mysql/main” directory structure.
- First, copy the downloaded JAR file into the main folder, then
- create a “module.xml” file. Copy the following content into this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.21.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
And we’re done!
Use module as a JDBC driver
If you want to use the module as a jdbc driver, open the JBoss standalone.xml, and add the following lines under
"<subsystem xmlns="urn:jboss:domain:datasources:1.0">" -> datasources -> drivers tag:
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
Your standalone.xml will look like this: