Configure postgresql driver as a JBoss EAP 6.x global module

In this example we will configure postgresql driver as a global module to be used by any application deployed to the application server.

  1. Download and install Red Hat JBoss EAP 6.3 GA from JBoss developer portal.
  2. Download postgresql driver according to your database version. We will use 9.2, as it is the one shipped with RHEL 7.x
  3. Create module under EAP_HOME/modules
    1. Create the following path: org/postgresql/main
    2. Copy the driver jar to this folder.
    3. Create a new xml file called module.xml in the same folder with the following content:
      <?xml version="1.0" encoding="UTF-8"?> 
      <module xmlns="urn:jboss:module:1.0" name="org.postgresql"> 
           <resources> 
             <resource-root path="postgresql-xxxxxx.jar"/> 
           </resources> 
           <dependencies> 
             <module name="javax.api"/> 
             <module name="javax.transaction.api"/> 
           </dependencies> 
      </module>
    4. Replace the name of the jar with the correct downloaded version and save.
  4. Edit the standalone.xml located under the EAP_HOME/standalone/configuration folder.
  5. Find the java ee subsystem.
    <subsystem xmlns="urn:jboss:domain:ee:1.2">
         <spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>
         <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
         <annotation-property-replacement>false</annotation-property-replacement>
    </subsystem>
  6. Add the global module entry. 
    <subsystem xmlns="urn:jboss:domain:ee:1.2">
         <global-modules>
           <module name="org.postgresql" slot="main"/>
         </global-modules>
         <spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>
         <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
         <annotation-property-replacement>false</annotation-property-replacement>
    </subsystem>
  7. Save and restart server if already running. Now the module is available for any deployment under the standalone configuration.

As an extra, you can configure the postgresql as a driver available in the JBoss EAP configuration to create datasources from the web console. You only have to run the following script from jboss-cli.

/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql,driver-class-name=org.postgresql.Driver,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)

It will create the required driver entry in the standalone.xml file.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s