How to add PostgreSQL datasource to WildFly 9.0?

czerny picture czerny · Jul 4, 2015 · Viewed 26.7k times · Source

I've tried tutorial at mastertheboss.com:

  1. ./jboss-cli.sh
  2. module add --name=org.postgres --resources=/tmp/postgresql-9.3-1101.jdbc41.jar --dependencies=javax.api,javax.transaction.api
  3. /subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
  4. data-source add --jndi-name=java:/PostGreDS --name=PostgrePool --connection-url=jdbc:postgresql://localhost/postgres --driver-name=postgres --user-name=postgres --password=postgres

This tutorial works with WildFly 8.2, but it doesn't work with WildFly 9.0. 3rd step fails with error message:

{
"outcome" => "failed",
"failure-description" => "WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}

How to add Postgres datasource to WildFly 9.0?

Answer

ragelh picture ragelh · Aug 26, 2015

I've encountered the same error and behavior of WildFly 9. I'm a complete newbie to WF, but after some research I've found that the trouble is in the module naming. If I'm getting it well, the actual package names in the module are used to resolve the path to module.xml.
I've changed the steps to those below and it worked:

module add --name=org.postgresql --slot=main --resources=/usr/local/lib/postgresql-9.4-1201.jdbc4.jar --dependencies=javax.api,javax.transaction.api

/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)