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:
- Go to WILDFLY_HOME/modules/system/layers/base/ and create the folder org/postgresql/main;
- copy the file postgresql jdbc driver jar file to the new folderWILDFLY_HOME/modules/system/layers/base/org/postgresql/main
- 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"> <resources> <resource-root path="postgresql-9.4.1211.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module>
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( driver-name=postgresql, driver-module-name=org.postgresql, driver-class-name=org.postgresql.Driver )
The command returns {“outcome” => “success”} in case of success. This command resulted in the following part in the configuration file:
<datasources> {...} <drivers> {...} <driver name="postgresql" module="org.postgresql"> <driver-class>org.postgresql.Driver</driver-class> </driver> </drivers> </datasources>
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 ....> <connection-url>jdbc:postgresql://localhost/....</connection-url> <driver>postgresql</driver> ...
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 \ –dependencies=javax.api,javax.transaction.api
The –resources value refers to the jdbc jar file (relative from bin folder of application server or absolute path).
I suspect you have two typos in the jboss_cli command: the “mysql” should be “postgresql”?
yes you are right, fixed – thanks!
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).
Thanks a lot for your feedback, I will add it into the post.
I tried to enable jta in admin console after I added postgresql datasource but turned out error message. Do you have any idea why?
Did you try first a simple database connection pool? Did this work?. Maybe you can you post the error message?
Yes, thank you for the suggestion. It’s working now
How can I add parameter, like “autosave”?