Module Creation

Class loading in JBoss Application Server - WildFly version is different than the previous versions of the JBoss Application Server.

The following are the major features of class loading in JBoss Application Server - WildFly version:

  • based on the modules and need to define explicit dependencies on other modules.
  • deployments in the modules do not have access to classes that are defined in JARs, unless an explicit dependency on those classes is defined.
  • the deployers within the server implicitly add some commonly used module dependencies to the deployment, such as, the javax.api and sun.jdk. In this way, the classes become visible to the deployment at runtime.
  • for some classes, the modules must be specified explicitly in the MANIFEST.MF file as dependencies or Class-Path entries. Otherwise, you may see ClassNotFoundExceptions, NoClassDefFoundErrors, or ClassCastExceptions.

After creating the hierarchal folders as mentioned in the Creating Subdirectory Structure, create the module.xml file for each database. Define the actual JAR file inside it, which contain the database driver. For example, if you have installed Oracle database, create a module.xml file in the $JBOSS_HOME\modules\system\layers\base\com\oracle\ojdbc6\main folder. For creating a module.xml file for each database, refer to the following samples:

For Oracle database

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.oracle.ojdbc6">
    <resources>
        <resource-root path="ojdbc6.jar"/>
        <!-- Insert resources here -->
    </resources>
    <dependencies>
		        <module name="javax.api"/>
		        <module name="javax.transaction.api"/>
    </dependencies>
</module>

For SQL Server database

<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.3" name="com.microsoft.sqlserver">
    <resources>
        <resource-root path="sqljdbc4.jar"/> 
    </resources> 
    <dependencies> 
        <module name="javax.api"/> 
        <module name="javax.transaction.api"/> 
    </dependencies> 
</module> 

For PostgreSQL database

<?xml version="1.0" encoding="UTF-8"?>
  <module xmlns="urn:jboss:module:1.3" name="org.postgresql">
       <resources>
           <resource-root path="postgresql-9.1-901.jdbc4.jar"/>
       </resources>
       <dependencies>
               <module name="javax.api"/>
               <module name="javax.transaction.api"/>
           </dependencies>
   </module>

The following tables describes the elements that are used in the module.xml file.

Elements and Description of Module.xml File

Element Name Description
Module Name It must match with the directory structure that you have created for each database. For example, the directory structure for Oracle database is $JBOSS_HOME\modules\system\layers\base\com\oracle\ojdbc6. Therefore, the module name is com.oracle.ojdbc6.
resource-root path Specify the driver JAR file name based on the database that you have installed. The path is relative and default to the main directory. For example, if you have installed the PostgreSQL database, specify <resource-root path="postgresql-9.1-901.jdbc4.jar"/>.
Dependencies Define any dependency. For example, all JDBC data sources are dependent on the Java JDBC API's. They are defined in the javax.api module, which is located at modules/system/layers/base/javax/api/main folder.