How to Add MySQL JDBC Driver To Wildfly

Wildfly Jboss logo

Wildfly is one of the best application server for Java, it is implementing Java EE, so if you are doing Java EE application development, you can use Wildfly either as your main production server or just for development process. It has a lot of documentation out there, so if you got into trouble, it is not that hard to find the solution.

Here's how to add MySQL JDBC driver to Wildfly, currently i am using Wildfly 12.x, and MySQL connector 8.x.

Using Terminal 

Try creating the Module itself using the   jboss-cli.sh command rather than manually writing the module.xml file. This is because when we use some text editors, they might append some hidden chars to our files. (Specially when we do a copy & paste in such editors)

[standalone@localhost:9990 /]  module add --name=com.mysql.driver  --dependencies=javax.api,javax.transaction.api --resources=/PATH/TO/mysql-connector-java-5.1.35.jar

[standalone@localhost:9990 /] :reload
{
    "outcome" => "success",
    "result" => undefined
}
After running above command you should see the module.xml generated in the following location:  "wildfly-8.2.1.Final/modules/com/mysql/driver/main/module.xml"

Now create DataSource:

[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=mysql/:add(driver-module-name=com.mysql.driver,driver-name=mysql,jdbc-compliant=false,driver-class-name=com.mysql.jdbc.Driver)
{"outcome" => "success"} 

source: https://developer.jboss.org/thread/266472

Manually Creating Data Source


1. Download MySQL connector from Maven central

You can download with this link :

Download : mysql-connector-java-8.0.17.jar

And then put the file under WILDFLY_HOME\modules\system\layers\base\com\mysql\main

2. Create a file "module.xml"

Using any kind of text editor, create file inside your Wildfly path, WILDFLY_HOME\modules\system\layers\base\com\mysql\main, and this is the XML file contents of it:

<module name="com.mysql" xmlns="urn:jboss:module:1.5">
    <resources>
        <resource-root path="mysql-connector-java-8.0.17.jar">
    </resource-root></resources>
    <dependencies>
        <module name="javax.api">
        <module name="javax.transaction.api">
    </module></module></dependencies>
</module>

If the folders didn't exist, create it by yourself.

3. Add MySQL connector to the driver list

Open WILDFLY_HOME\standalone\configuration\standalone.xml, and then find <drivers> tag, inside that tag, put these lines to add MySQL driver:

<driver name="mysql" module="com.mysql">
 <driver-class>com.mysql.cj.jdbc.Driver</driver-class>
 <xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
</driver>

Now you can restart Wildfly and expect that new driver will be inside the available list driver.

Comments

Popular posts from this blog

ERROR 1348 Column Password Is Not Updatable When Updating MySQL Root Password

Spring Kafka - how to use ReplyingKafkaTemplate send and reply synchronously

How To Create Spring Boot Project Using Netbeans

How To Connect SSH Using PEM Certificate On Windows

Step by Step How To Use cURL Library Using C From VS Code Windows