Information Technology, Tips and Tricks

Steps to create MySQL datasource in JBoss 7 (not jdbc 4 compliant driver)

  1. Create the directory structure for the MySQL module.
    Example: how to create a module for MySQL driver:

    cd $JBOSS_HOME
    mkdir modules/com/mysql
    mkdir modules/com/mysql/jdbc
    mkdir modules/com/mysql/jdbc/main

  2. Copy the driver(s) jar into the created directory
  3. Create a module.xml file to define dependencies and resources. For our mysql example it looks like this:
    jboss:module:1.0" name="com.mysql.jdbc"
    

    Note: replace the JAR name accordingly with the version that you have in your local machine

  4. Add driver to the standalone.xml
                    <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.jdbc"> 
    			<driver-class>com.mysql.jdbc.Driver</driver-class>  
    		    </driver>
                    </drivers>
  5. Restart your JBoss
  6. Go to JBoss consoleĀ http://localhost:8080/console, select “Connector –> DataSources” from menu on the left, and then click button “Add” on the top right corner. Afterwards, follow the steps and you will that “mysql” is now available as driver option.