Installing MySQL JDBC driver into Wildfly


To install a MySQL JDBC driver into Wildfly


This recipe explains the basic steps one needs to do in order to install MySQL JDBC driver into Wildfly application server and how to make it available for use in a given application.

How to

  1. The first thing we need to do is create the module.xml file for the driver. In order to do so, create the following folders com/mysql/main inside $WILDFLY_HOME/modules/system/layers/base (we will be using Wildfly 10.1 but it is or should be similar to other versions of Wildfly) and add a file named module.xml inside of the main folder with the following content:
    <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.0" name="com.mysql">
        <resource-root path="mysql-connector-java-5.1.21.jar"/>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
  2. Next, copy the corresponding MySQL JDBC driver version into the same main folder, in this case, a file named mysql-connector-java-5.1.21.jar. In this recipe, we will be using version 5.1.21 of the driver but the previous steps are similar in other versions of the driver. Just make sure that the attribute path in the module.xml file matches the name of the file containing the MySQL driver.
  3. Now, edit your standalone.xml file in $WILDFLY_HOME/standalone/configuration to register the previously installed driver:
        <driver name="mysql" module="com.mysql">


Adding the driver to the classpath of Wildfly as a module and registering the driver’s datasource class makes it available to be used at runtime in any application that needs/uses MySQL JDBC driver as its own persistent store. Assuming that we would be using JPA in a project, we could define a dependency on a JTA datasource such as:

<persistence xmlns=""
  <persistence-unit name="pu" transaction-type="JTA">

And all we would need to configure our application in the Wildfly installation would be define the corresponding datasource in the standalone.xml file, such as the following:

    <xa-datasource jndi-name="java:/jdbc/pu" pool-name="pupool" enabled="true" use-java-context="true">
      <xa-datasource-property name="ServerName">localhost</xa-datasource-property>
      <xa-datasource-property name="DatabaseName">mydb</xa-datasource-property>
        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s