Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildfly 9 failing to load MySQL driver on startup

I am creating a web application for WildFly, which will connect to a MySQL database through JPA (Hibernate). For now, I am just trying to get WildFly to start up and load the MySQL driver in standalone mode. I am using this page as a guide: http://wildfly.org/news/2014/02/06/GlassFish-to-WildFly-migration/

I am running WildFly and MySQL locally on a Windows system:

  • Windows 7 Enterprise SP1
  • Oracle Java SE 1.8.0_45
  • WildFly 9.0.0.Final
  • MySQL Server 5.6

Attempts to use the recommended console commands did not succeed, so I have manually edited to WildFly configuration files to look like those in the examples on the page linked above. First, I created the module directory and placed in it the MySQL connector JAR and module.xml file:

    Directory of C:\wildfly-9.0.0.Final\modules\system\layers\base\com\mysql\main

07/06/2015  09:54 AM    <DIR>          .
07/06/2015  09:54 AM    <DIR>          ..
07/06/2015  10:12 AM               334 module.xml
07/01/2015  02:38 PM           968,668 mysql-connector-java-5.1.35.jar

The above connector jar was copied from my local Maven repository, which Maven obtained through the following dependency:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.35</version>
</dependency>

The module.xml file was manually edited as follows, to resemble the example I found on wildfly.org:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
    <resources>
        <resource-root path="mysql-connector-java-5.1.35-bin.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

Finally, I added the driver and datasource to the datasources section of standalone.xml:

        <datasource jndi-name="java:/MySQLDS" pool-name="MyDS" enabled="true" use-java-context="true">
            <connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
            <driver>mysql</driver>
            <security>
                <user-name>root</user-name>
                <password>secret</password>
            </security>
        </datasource>
        <drivers>
            <driver name="h2" module="com.h2database.h2">
                <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
            </driver>
            <driver name="mysql" module="com.mysql">
                <driver-class>com.mysql.jdbc.Driver</driver-class>
            </driver>
        </drivers>

Upon starting WildFly in standalone mode, by running %WILDFLY_HOME%\bin\standalone.bat, the following is the first error listed in %WILDFLY_HOME%\standalone\logs\server.log:

2015-07-06 10:25:47,321 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.mysql]"

Similar issues that I have seen posted on Stack Overflow and other question/answer sites usually point to an oversight such as a typo in config files or a misnamed file. However, I've been over this over and over and cannot see any such mistake, and the same error has occurred even after upgrading from Java SE 7 and WildFly 8.2 and re-creating the configuration files from scratch. Any assistance would be greatly appreciated.

like image 735
MTaylorEx Avatar asked Mar 15 '23 12:03

MTaylorEx


2 Answers

In my case it was a matter of having the wrong user:group for the directories and files under ../com/mysql/main

I changed it to wildlfy and everything worked as expected.

like image 117
Gianluca Elmo Avatar answered Mar 18 '23 11:03

Gianluca Elmo


There was a typo in module.xml. The name of the connector JAR listed in module.xml did not match the actual JAR file in modules\system\layers\base\com\mysql\main.

like image 39
MTaylorEx Avatar answered Mar 18 '23 09:03

MTaylorEx