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>
				
时间: 2024-10-29 14:51:24

Jboss wildfly add JDBC driver的相关文章

Add Microsoft SQL JDBC driver to Maven(转)

from:http://claude.betancourt.us/add-microsoft-sql-jdbc-driver-to-maven/ Add Microsoft SQL JDBC driver to Maven March 13, 2012 Framework / How-To / Tutorials Maven does not directly support some libraries, like Microsoft's SQL Server JDBC. This tutor

Java系列:Add Microsoft SQL JDBC driver to Maven

Maven does not directly support some libraries, like Microsoft's SQL Server JDBC. This tutorial will show you how to add an external dependency to your local Maven repository. It assumes you have already installed Maven. Download the JDBC driver for

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver解决方案

昨天整理桌面的时候将桌面的一堆文件移动到F盘去了,结果导致原来建的一些项目名称全部出现红色感叹号,打开一看,原来是因为我把hibernate的那些jar包移走了,导致user library里那些jar在原来的路径里找不到了,所以出现红色感叹号,在写新的项目的时候就不能把原来写的羡慕copy过来改了,只好重新新建了个java project,然后重新导包,编好代码运行一下,报了如下错误:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

java eclipse com.mysql.jdbc.Driver

错误: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse 解决: Right Click the project -- > build path -- > configure build path In the libraries tab press Add External Jar and select your jar. ps:感觉自己的知识特别零散,真正有效的学习还是要去系统地学,去啃大部头.

MySQL Connector/J is the official JDBC driver for MySQL

mysql-connector-java-5.0.8.zip          mysql的jdbc驱动(MySQL Connector/J is the official JDBC driver for MySQL.)     http://dev.mysql.com/downloads/file.php?id=13598 zip压缩文件放在百度云:http://pan.baidu.com/disk/home#from=share_pan_logo 解压后得到mysql-connector-j

IntelliJ IDEA 上的web项目进行数据库连接时出现java.lang.ClassNotFoundException: com.mysql.jdbc.Driver错误解决办法

首先看报错信息: 意思是找不到类:  com.mysql.jdbc.Driver.也就是说tomcat找不到MySQL数据库连接要用的jar包! 出现这种错误的原因是: 项目中没有导入这个jar包, 或者导入路径错误. 经过检查发现我的出错原因是: 直接在web目录下新建目录lib, 然后把mysql连接jar包拷贝到lib里面, 再右击选择Add as Library. 最后运行直接报错了. 对比之前在eclipse上写的项目, 这个lib目录是在 WebContent\WEB-INF 下的,

tomcat启动过程报the JDBC Driver has been forcibly unregistered问题的修复过程

最近两天在整理关于flume的总结文档,没有启动过tomcat.昨天晚上部署启动,发现报了如题的错误,全文如下: 严重: The web application [/oa-deploy] registered the JBDC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a mem

WEB中的java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

必须把mysql-connector-java-5.1.7-bin.jar导入到tomcat的lib目录下面! 在java项目中,只需要引入mysql-connector-java-5.1.7-bin.jar就可以运行java项目. 在web项目中,当Class.forName("com.mysql.jdbc.Driver");时eclipse是不会去查找字符串,不会去查找驱动的.所以只需要把mysql-connector-java-5.1.7-bin.jar拷贝到tomcat下lib

错误:“Cannot load JDBC driver class &#39;com.mysql.jdbc.Driver”的解决方法

"Cannot load JDBC driver class 'com.mysql.jdbc.Driver " 表示没有JDBC连接MySql的驱动包,因此需要手动添加驱动包到WEB-INF目录下的lib目录中. 解决方法: 从网上下载mysql-connector-java.jar,将其放到"D:\workspace\my-web\src\main\webapp\WEB-INF\lib"目录下,即可解决上述问题. 错误:"Cannot load JDBC