Can't add mysql driver to jboss

2020-06-09 06:46发布

Ok this is driving me crazy. Especially because there are already many similar questions out there. But no answer works for me.

I have jboss 7.1.1 on my windows 7 machine (running it from eclipse normally) and want to use mysql.

I did the following:

1 created directory jboss-as-7.1.1.Final\modules\com\mysql\main

2 Files there: module.xml and mysql-connector-java-5.1.26-bin.jar (downloaded from official mysql site)

3 Content of module.xml:

<?xml version="1.0" encoding="UTF-8"?>
<modulexmlns="urn:jboss:module:1.0" name="com.mysql">
  <resourxces>
     <resource-rootpath="mysql-connector-java-5.1.26-bin.jar"/>              
  </resources>
  <dependencies>
     <modulename="javax.api"/>
  </dependencies>
</module>

4 Relevant parts from jboss-as-7.1.1.Final\standalone\configuration\standalone.xml:

<datasource jndi-name="java:jboss/datasources/mysqlDS" pool-name="mysqlDS" enabled="true" jta="true"  use-ccm="true" use-java-context="true">
    <connection-url>jdbc:mysql://192.168.1.1:3306/eAuftrag</connection-url>
    <driver>com.mysql</driver>
    <security>
        <user-name>root</user-name>
        <password>fffff</password>
    </security>
    <timeout>  
        <idle-timeout-minutes>0</idle-timeout-minutes>  
        <query-timeout>600</query-timeout>  
    </timeout>  
    <statement>  
        <prepared-statement-cache-size>100</prepared-statement-cache-size>  
        <share-prepared-statements>true</share-prepared-statements>  
    </statement>  
</datasource>

and:

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

Everytime I start the jboss server I see this message:

service jboss.jdbc-driver.com_mysql (missing) dependents: [service jboss.data-source.java:jboss/datasources/mysqlDS]

And when I go to the managment-console and look at datasources, the mysqlDS is listed there, but when I click on it I get the error (sorry can't select the text there, so here comes the image):

error from managment console

6条回答
We Are One
2楼-- · 2020-06-09 07:08

You need to give the driver tag a driver class or a data source.

<driver name="com.mysql" module="com.mysql">
    <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
查看更多
啃猪蹄的小仙女
3楼-- · 2020-06-09 07:11

Make sure you do NOT have a space at the beginning of module.xml file or you will get a:

new missing/unsatisfied dependencies

...error for this driver.

查看更多
等我变得足够好
4楼-- · 2020-06-09 07:16

To make the JDBC driver classes available to the JBoss Application Server, copy the archive mysql-mysql-connector-java-5.1.5-bin.jar from the Connector/J distribution to the lib directory in the default server configuration (assuming that is the server configuration you’re running).

Now create a mysql-ds.xml

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
  <jndi-name>DefaultDS</jndi-name>
  <connection-url>jdbc:mysql://localhost:3306/test</connection-url>
  <driver-class>com.mysql.jdbc.Driver</driver-class>
  <user-name>root</user-name>
  <password>jboss</password>
  <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
  <metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

you can also refer this links https://zorq.net/b/2011/07/12/adding-a-mysql-datasource-to-jboss-as-7

http://docs.jboss.org/jbossas/getting_started/v4/html/db.html

查看更多
虎瘦雄心在
5楼-- · 2020-06-09 07:17

WILDFLY 10 using mysql 5.7

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

  1. 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

<datasources>
<!--
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-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

查看更多
Rolldiameter
6楼-- · 2020-06-09 07:18

Here is my sample module.xml

<module xmlns="urn:jboss:module:1.1" name="com.mysql">

<resources>
    <resource-root path="mysql-connector-java-5.1.6.jar"/>
    <!-- Insert resources here -->
</resources>
<dependencies>
          <module name="javax.api"/>
          <module name="javax.transaction.api"/>
</dependencies>

Below is the Data source configuration in standalone.xml

<datasource jta="true" jndi-name="java:jboss/jdbc/MyDS" pool-name="AppzillonDS"         enabled="true" use-java-context="true">
  <connection-url>jdbc:mysql://192.168.1.98:3306/mydb?zeroDateTimeBehavior=convertToNull</connection-url>
  <driver>mysql</driver>
    <security>
       <user-name>user</user-name>
       <password>password</password>
    </security>
</datasource>

Look at the driver tag in above. drive is just mysql and not the com.mysql. Hope this should help you....

查看更多
Emotional °昔
7楼-- · 2020-06-09 07:21

So once more I can pay tribute to my stupidity. I did everything right except I had typos in my module.xml file. Notice that in the code above are no blanks (" ") between some words - somehow they got lost. But what's even worse is that apparantly these module-files are not validated by jboss, that's why I never realized it. Anyway here's the correct config without the typos...

<?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.26-bin.jar"/>              
  </resources>
  <dependencies>
     <module name="javax.api"/>
  </dependencies>
</module>
查看更多
登录 后发表回答