首页 > 代码库 > Jboss wildfly add JDBC driver

Jboss wildfly add JDBC driver

Jboss wildfly  添加 JDBC driver

我这里使用的是 wildfly-8.0.0.Final 

第一步:

首先在modules里面添加mysql的驱动包

例如:modules\system\layers\base\com  在这下面新建 mysql文件夹,然后在mysql下面建子文件夹 main,这个main名字不能随便修改,这是规则。

整体路劲如下:

modules\system\layers\base\com\mysql\main

 

然后在main下面新建一个module.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?><!--  ~ JBoss, Home of Professional Open Source.  ~ Copyright 2011, Red Hat, Inc., and individual contributors  ~ as indicated by the @author tags. See the copyright.txt file in the  ~ distribution for a full listing of individual contributors.  ~  ~ This is free software; you can redistribute it and/or modify it  ~ under the terms of the GNU Lesser General Public License as  ~ published by the Free Software Foundation; either version 2.1 of  ~ the License, or (at your option) any later version.  ~  ~ This software is distributed in the hope that it will be useful,  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ~ Lesser General Public License for more details.  ~  ~ You should have received a copy of the GNU Lesser General Public  ~ License along with this software; if not, write to the Free  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.  --><!-- Represents the Hibernate 4.1.x (works with Hibernate 4.2.x jars also) module  --><module xmlns="urn:jboss:module:1.1" name="com.mysql">    <resources>        <resource-root path="mysql-connector-java-5.1.7-bin.jar"/>        <!-- Insert resources here -->    </resources>    <dependencies>        <module name="javax.api"/>        <module name="javax.transaction.api"/>    </dependencies></module>

name="com.mysql" 这个后面会用到,名字随便起,后面用的时候对应这个名字就行了

path="mysql-connector-java-5.1.7-bin.jar" 是mysql的驱动包
把mysql的驱动包拷到当前main目录下,注意path的名字要一样

第二步:
添加JNDI
我这里启动的是 standalone
打开standalone\configuration\standalone.xml 找到 drivers 节点 在里面添加一个driver 节点
如下:
<driver name="MySQLDSDriver" module="com.mysql">                        <driver-class>com.mysql.jdbc.Driver</driver-class>                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>                    </driver>

这里的module 就是第一步建的module.xml里面的name 

然后找到datasources节点,在里面添加一个datasource 如下:

<datasource jndi-name="java:/MySQLDS" pool-name="MySQLDS" >                    <connection-url>jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8</connection-url>                    <driver>MySQLDSDriver</driver><!--对应上面的device name -->                    <security>                        <user-name>username</user-name>                        <password>password</password>                    </security>                    <pool>                        <min-pool-size>30</min-pool-size>                        <max-pool-size>100</max-pool-size>                        <prefill>true</prefill>                    </pool>                    <!--                    <validation>                        <validate-on-match>false</validate-on-match>                        <background-validation>false</background-validation>                    </validation>                    <statement>                        <share-prepared-statements>false</share-prepared-statements>                    </statement>                    -->                </datasource>

 




Jboss wildfly add JDBC driver