Database module in wildfly

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

Hello all, we are going to learn how to create a database module in wildfly so that it is available for applications to be used a datasource. We will take mysql as an example database module in wildfly.

Creating module:

  • Go to WildFly installation on your disk. In my case the installation is at  C:\wildfly-8.2.0.Final .
  • Under the installation you can see modules directory. Open the directory and navigate to base for modules i.e.  C:\wildfly-8.2.0.Final\modules\system\layers\base
  • Here you can see com directory. Create a directory mysql under com.
  • Create a directory main under mysql.
  • Under main create a file named module.xml.
  • Now you should be having mysql-connector.jar file for database connectivity. Copy it under main directory.

The directory structure should look like this.

module directory structure

 

and under main directory, module.xml and mysql connector jar are placed as follows.

 

under main directory

 

 

 

 

Now, open module.xml and we need to add some code to it such that it is recognized as a module in WildFly.

Add following code to it

  •   name = "com.mysql"  is the identifier which will be used to identify this module in standalone.xml
  • path="mysql-connector-java-5.1.21-bin.jar" is the location of mysql connector jar file relative to the main directory.

Till now we have created database module in wildfly.

Configure module in wildfly as datasource:

Open standalone.xml file located at  <wildfly_home>/standalone/configuration and edit it. Find the drivers element and add a new driver using following code

This creates the driver with name mysqlDriver for module com.mysql

Now, create a datasource using database module in wildfly.

Yes, we are done. You can use this datasource in applications using the jndi-name java:/mysql

 

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

4 thoughts on “Database module in wildfly

Leave a Reply

Your email address will not be published. Required fields are marked *