Wildfly mysql dependencies not available

1.1k Views Asked by At

I'm using wildfly and maven and I'm trying to deploy a java ee application to wildfly as well as add a mysql database as a datasource.

I've added the mysql-connector-java-5.1.6.jar driver in the \.wildfly\modules\system\layers\base\com\mysql\main folder aswell as a module.xml file:

<?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.6.jar"/>             
  </resources>
  <dependencies>
     <module name="javax.api"/>
     <module name="javax.transaction.api"/>
  </dependencies>
</module>

I've also edited the \.wildfly\standalone\configuration\module.standalone.xml file and added the datasource:

<datasource jndi-name="java:/mySQLDS" pool-name="quizzer" enabled="true" use-ccm="true">
    <connection-url>jdbc:mysql://localhost:3306/quizzer</connection-url>
    <driver>mysqlDriver</driver>
    <security>
        <user-name>****</user-name>
        <password>****</password>
    </security>
    <validation>
        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
        <background-validation>true</background-validation>
        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
    </validation>
</datasource>

As well as the driver:

<driver name="mysqlDriver" module="com.mysql">
    <datasource-class>com.mysql.Driver</datasource-class>
</driver>

I'm using jboss forge and maven to build the project. When I try to deploy the application the generated warfile from the project I get the following error:

Cannot upload deployment: {"WFLYCTL0288: One or more services were unable to start due to one or more indirect dependencies not being available." => {"Services that were unable to start:" => ["jboss.deployment.unit.\"quickdemo.war\".POST_MODULE","jboss.persistenceunit.\"quickdemo.war#mySQLPersistence\".__FIRST_PHASE__"],"Services that may be the cause:" => ["jboss.jdbc-driver.mysqlDriver"]}}

Finally, this is my pom.xml file and this is the full stack from .forge\log\forge.log.

One more strange thing: The wildfly welcome screen on localhost:8080/ says WildFly 9 is running however console at localhost:9990/console/App.html#standalone-deployments (which is where one of the welcome screen links points to) says 10.0.0.Final and that makes more sense because it's the one I downloaded and installed. I think the other version may be due to the Wildfly As plugin I installed on forge or perhaps they simply forgot to update the welcome screen.

2

There are 2 best solutions below

6
Shettyh On

I think the problem with the driver class.

Use <driver-class>com.mysql.jdbc.Driver</driver-class> instead <datasource-class>com.mysql.Driver</datasource-class>

And its always recommended to have custom modules outside system directory

Exact stack trace will be more helpful if you can provide,

0
JAGJ jdfoxito On

WILDFLY 10 using mysql 5.7

follow this steps: comment or delete exampleds in standalone.xml

into jboss-cli.bat --connect after execute command [standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)

should be ok

this modified standalone.xml, then add

url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
    <user-name>sa</user-name>
    <password>sa</password>
</security>
</datasource> -->
<datasource jndi-name="java:/mysql" pool-name="mysqlDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/wildfly</connection-url>
<driver>mysql</driver>
<security>
    <user-name>root</user-name>
    <password>jdfoxito10</password>
</security>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>

should look like!

and module.xml put in

\java\server\wildfly-10.1.0.Final\modules\system\layers\base\com\mysql\main

mysql-connector-java-5.1.40-bin.jar (come installer mysql-installer-community-5.7.15.0.msi) module.xml

and content from module.xml like:

<?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.40-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>

and ready, JAVA_HOME should be ok