jboss Setting Up MySQL for JBoss AS 7


Example

The following are the steps that you will need to follow to setup mysql datasource in JBoss AS 7.

  1. Download the MySQL jdbc zip file from here:
  2. Create a directory mysql inside /jboss-as-7.1.1.Final/modules/com
  3. Inside that create a directory structure like the following:
/jboss-as-7.1.1.Final/modules/com/mysql/main
  1. Inside the main copy and paste the following jar from the mysql connector that was downloaded in the first step.
mysql-connector-java-5.1.XX-bin.jar
  1. Create a module.xml in the same folder and add the following inside that:
<?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.30-bin.jar"/> 
       <!-- Insert resources here --> 
    </resources> 
    <dependencies> 
       <module name="javax.api"/> 
    </dependencies>
</module>
  1. Inside the standalone.xml in the bin directory add the following:
<driver name="mysql" module="com.mysql">
    <driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>
  1. Now startup your jboss and open the admin console.
  2. Inside the admin console create/add a new datasource and enter the proper details. You can put any name you want. Remember to add the jndi name in the details as:
 java:/mysql
  1. Then enable the connection.
  2. Now you can check for the connection and you should be all set, if you have followed the above steps properly.

You can watch this video, which demonstrates the above steps.