title: How to add PostgreSQL datasource to WildFly Full 9.0.1.Final?
body: <p>I am trying to use postgres in  WildFly Full 9.0.1.Final. Unfortunately, for a task that should be simple, we have had 2 people trying for days to figure out how to make this work.</p>
  
  <p>I should add that I am using Docker, and as I build the docker image I am trying various ways to add postgres support to  WildFly Full 9.0.1.Final.</p>
  
  <p>We have tried the following:</p>
  
  <p><strong>batch file</strong></p>
  
  <pre><code>batch
  connect
  #module add --name=org.postgres --resources=/opt/jboss/wildfly/psql-jdbc.jar --dependencies=javax.api,javax.transaction.api
  
  #module add --name=org.postgres --resources=/opt/jboss/wildfly/postgresql-9.3-1101.jdbc41.jar --dependencies=javax.api,javax.transaction.api    
  module add --name=org.postgresql --slot=main --resources=/opt/jboss/wildfly/postgresql-9.3-1101.jdbc41.jar --dependencies=javax.api,javax.transaction.api
  
  #/subsystem=datasources/jdbc-driver=postgresql:add(driver-name="postgresql",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
  #datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
  /subsystem=datasources/jdbc-driver=postgres:add(driver-name="org.postgresql",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
  
  
  #The batch failed with the following error (you are remaining in the batch editing mode to have a chance to correct the error): {"WFLYCTL0062: Composite operation failed and was rolled back. Steps that #failed:" =&gt; {"Operation step-1" =&gt; "WFLYJCA0041: Failed to load module for driver [org.postgresql]"}}
  
  
  #/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
  
  
  
  
  # Add the datasource
  #data-source add --jndi-name=java:jboss/datasources/ISDS --name=pu-magick --connection-url=jdbc:postgresql://UI_PG_DATABASE:5432/magick --driver-name=postgresql --user-name=magick --password=magick
  run-batch
  </code></pre>
  
  <p><strong>In a Dockerfile</strong></p>
  
  <pre><code>ADD modules /opt/jboss/wildfly/modules/
  </code></pre>
  
  <p>This attempt resulted in:</p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: No layers directory found at /opt/jboss/wildfly/modules/system/layers
      at org.jboss.modules.LayeredModulePathFactory.resolveLayeredModulePath(LayeredModulePathFactory.java:65)
      at org.jboss.modules.LocalModuleFinder.getRepoRoots(LocalModuleFinder.java:111)
      at org.jboss.modules.LocalModuleFinder.&lt;init&gt;(LocalModuleFinder.java:107)
      at org.jboss.modules.LocalModuleFinder.&lt;init&gt;(LocalModuleFinder.java:88)
      at org.jboss.modules.LocalModuleLoader.&lt;init&gt;(LocalModuleLoader.java:57)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at org.jboss.modules.DefaultBootModuleLoaderHolder$1.run(DefaultBootModuleLoaderHolder.java:37)
      at org.jboss.modules.DefaultBootModuleLoaderHolder$1.run(DefaultBootModuleLoaderHolder.java:33)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.jboss.modules.DefaultBootModuleLoaderHolder.&lt;clinit&gt;(DefaultBootModuleLoaderHolder.java:33)
      ... 1 more
  </code></pre>
  
  <p><strong>Adding driver to deployment directory</strong></p>
  
  <p>I have found in the past that a database driver can be added to jboss by adding the jar to the deployment directory. This, in my opinion, is about as complicated as it needs to be.</p>
  
  <p>So, I also tried copying <code>postgresql-9.3-1101.jdbc41.jar</code> to <code>/opt/jboss/wildfly/standalone/deployments/</code></p>
  
  <p><strong>DockerFile</strong></p>
  
  <pre><code>FROM wildflyext/wildfly-camel
  MAINTAINER ah &lt;ah@domain.io&gt;
  
  ENV TMPDIR /tmp/
  ENV WFDIR /opt/jboss/wildfly/
  
  RUN /opt/jboss/wildfly/bin/add-user.sh admin admin --silent
  
  
  
  
  
  
  ## COPY PG MODULE TO SERVER
  #ADD module.xml opt/jboss/wildfly/modules/
  #ADD standalone.xml $WFDIR/standalone/configuration/
  #ADD system /opt/jboss/wildfly/modules/
  
  
  
  ## COPY PG DRIVER TO SERVER
  #ADD postgresql-9.3-1101.jdbc41.jar /opt/jboss/wildfly/standalone/deployments/
  #ADD postgresql-9.3-1101.jdbc41.jar /opt/jboss/wildfly/
  
  #ADD psql-jdbc.jar $WFDIR/standalone/deployments/
  
  
  
  ## COPY STANDALONE TO SERVER
  ADD standalone-camel.xml /opt/jboss/wildfly/standalone/configuration/
  
  
  ADD config.sh $TMPDIR
  ADD batch.cli $TMPDIR
  RUN $TMPDIR/config.sh
  
  
  #CMD ["-c", "standalone-camel.xml"] # loads correct standalone, cannot access mgmt console - connection interupted
  #CMD ["-b", "0.0.0.0", "-c", "standalone-camel.xml"] # does not load correct standalone, cannot access mgmt console - connection interupted
  #CMD ["-c", "standalone-camel.xml"m "-b", "0.0.0.0"] # WFLYSRV0073: Invalid option '/bin/sh'
  #CMD ["-c", "standalone-camel.xml", "-b", "0.0.0.0"] # loads correct standalone, cannot access mgmt console - connection interupted
  
  # attempt with two CMDs = loads incorrect standalone - standalone.xml, not standalone-camel.xml, cannot access mgmt console - connection interupted
  #CMD ["-c", "standalone-camel.xml"]
  #CMD ["-b", "0.0.0.0"]
  
  # attempt with NO CMDs
  </code></pre>