Install Mysql JDBC Driver on WildFly

First of, I found an article which explains how to install a jdbc driver on WildFly in a fancy way. However, I’m going to introduce an easy way to do it at the end. So let’s start with the one I found.

You may want to Initialize MySQL to begin with.

Configure JDBC Driver on WildFly 8

Used technologies in the tutorial:

  • Wild Fly 8.2.0.Final (Tested on WildFly 10 and it worked)
  • Mysql Connector 5.1.33 (Tested with MySQL Connector 5.1.39 and it worked)

1. Create the jboss module

Enter in the file path ${EAP_HOME}/modules/system/layers/base and create the directories com/mysql/driver/main.

Into the folder main copy the driver library jar, and create a file module.xml as showed in the sample below

<module xmlns="urn:jboss:module:1.3" name="com.mysql.driver">
        <resource-root path="mysql-connector-java-5.1.33.jar" />
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>

For an explanation about the meaning of the fields take a look at Jboss Module Documentation.

2. Register the module as driver with CLI.
Start the server from the directory ${EAP_HOME}/bin and excute ./ --server-config=${server-profile}
Start the management CLI by executing ./ (if you’re using windows, you should do it in cmd. Go to ${EAP_HOME}/bin, and execute jboss-cli)
Run the the command: /subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql.driver,driver-class-name=com.mysql.jdbc.Driver)”
If the operation is successful then the message below will be shown
{"outcome" => "success"}
In addition, the code below should be added to standalone.xml

<driver name="mysql" module="com.mysql.driver">

The easy way

Login to WildFly web console, go to Deployments -> add a managed deployment. Then you can choose any divers you would like to deploy.

How about GlassFish?

For glassfish, these is no need to “install” the driver. before starting the server up, place the driver in the directory of %{your domain folder}\lib\ext. Then you will be good to go. You can then add pool and datasource under Resources -> JDBC within web console (add pool first, then ds). There are bugs with this module in GlassFish4. You may want to do it in GlassFish3 or Payara.
P.S. It seems if you reopen IDE, and do a clean startup of the server, then it will be ok.