Wildfly – Install PostgreSQL JDBC Driver as a Module

Instead of deploying a JDBC driver with the wildfly auto-deploy feature, the driver can be alternatively installed as an module. This is also necessary to be used with XA-Datasources. So it is a recommended way to install the driver as a module. The following section shows how to a jdbc driver module is created.

Creating a Module

To create a module:

  1. Go to WILDFLY_HOME/modules/system/layers/base/ and create the folder org/postgresql/main;
  2. copy the file postgresql jdbc driver jar file  to the new folderWILDFLY_HOME/modules/system/layers/base/org/postgresql/main
  3. create the file module.xml in the same folder with the following content:
        <?xml version="1.0" encoding="UTF-8"?>
        <module xmlns="urn:jboss:module:1.1" name="org.postgresql">
                <resource-root path="postgresql-9.4.1211.jar"/>
                <module name="javax.api"/>
                <module name="javax.transaction.api"/>

The name of the driver file may vary, so make sure you declare exactly the same name in the resource-root tag. At this point, the module is not available yet. Youneed to reference the module as a driver in WildFly configuration with the following jboss-cli command:

[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=postgresql:add(

The command returns {“outcome” => “success”} in case of success. This command resulted in the following part in the configuration file:

            <driver name="postgresql" module="org.postgresql">

It makes the JDBC driver module available for the datasource creation. So a datasource definition can now be defined to use the postgresql driver in the following way:

 <datasource ....>


Create a Module with CLI

You can create a module also with the wildfly CLI:

module add –name=org.postgres \
      –resources=postgres/postgresql-9.3-1100.jdbc4.jar \

The –resources value refers to the jdbc jar file (relative from bin folder of application server or absolute path).

7 Replies to “Wildfly – Install PostgreSQL JDBC Driver as a Module”

  1. I suspect you have two typos in the jboss_cli command: the “mysql” should be “postgresql”?

  2. Btw. you can create a module also with CLI:
    module add –name=org.postgres –resources=postgres/postgresql-9.3-1100.jdbc4.jar –dependencies=javax.api,javax.transaction.api
    The –resources value reffers to the jdbc jar file (relative from bin folder of application server or absolute path).

  3. I tried to enable jta in admin console after I added postgresql datasource but turned out error message. Do you have any idea why?

  4. Did you try first a simple database connection pool? Did this work?. Maybe you can you post the error message?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.