title: Whats the correct way to allow different jdbc drivers for deployed applications on JBoss / Wildfly?
body: <p>My setting is the following:</p>
  
  <ul>
  <li>I got an application, which I deploy in <code>/standalone/deployments</code></li>
  <li>The <code>jboss-deployment-structure.xml</code> of my deployment in <code>/standalone/deployments</code> looks the following:</li>
  </ul>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jboss-deployment-structure&gt;
      &lt;deployment&gt;
          &lt;dependencies&gt;
              [...]
              &lt;module name="org.postgresql"/&gt;
          &lt;/dependencies&gt;
      &lt;/deployment&gt;
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <ul>
  <li><p>To drop the <code>jboss-deployment-structure.xml</code> completely (because it must not be used if there are no classloading issues), doesn't work. I use more dependencies (keycloak) beside the driver, which can't be found then.</p></li>
  <li><p>My <code>module.xml</code> in my module <code>org/postgresql/main</code> looks like this (like described in <a href="https://www.keycloak.org/docs/4.8/server_installation/index.html#package-the-jdbc-driver" rel="nofollow noreferrer">https://www.keycloak.org/docs/4.8/server_installation/index.html#package-the-jdbc-driver</a>)</p></li>
  </ul>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;module name="org.postgresql" xmlns="urn:jboss:module:1.5"&gt;
      &lt;resources&gt;
          &lt;resource-root path="postgresql-42.2.5.jar"/&gt;
      &lt;/resources&gt;
      &lt;dependencies&gt;
          &lt;module name="javax.api"/&gt;
          &lt;module name="javax.transaction.api"/&gt;
      &lt;/dependencies&gt;
  &lt;/module&gt;
  </code></pre>
  
  <ul>
  <li>My requirement is, to allow different types of jdbc-drivers, e.g. postgres, oracle, mssql.</li>
  </ul>
  
  <hr>
  
  <p><strong>First option:</strong></p>
  
  <p>I can change my <code>jboss-deployment-structure.xml</code> to</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jboss-deployment-structure&gt;
      &lt;deployment&gt;
          &lt;dependencies&gt;
              [...]
              &lt;module name="org.postgresql" optional="TRUE"/&gt;
              &lt;module name="com.oracle.ojdbc6" optional="TRUE"/&gt;
              [...]
          &lt;/dependencies&gt;
      &lt;/deployment&gt;
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <p>(added the optional-parameter)</p>
  
  <p>Then I have to allow all drivers explicitly. Seems to be not the best way.</p>
  
  <p>The idea comes from the standard <a href="https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html/development_guide/class_loading_and_modules" rel="nofollow noreferrer">documentation</a>.</p>
  
  <hr>
  
  <p><strong>Second option:</strong></p>
  
  <p>I change my module-path to <code>driver/jdbc/main</code> (instead of <code>org/postgres/main</code>)  and the <code>module.xml</code> to</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;module name="driver.jdbc" xmlns="urn:jboss:module:1.5"&gt;
  [...]
  &lt;/module&gt;
  </code></pre>
  
  <p>(changed name of module)</p>
  
  <p>and go with the module-reference in my <code>jboss-deployment-structure.xml</code> like </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;jboss-deployment-structure&gt;
      [...]
      &lt;module name="driver.jdbc"/&gt;
      [...]
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <p>Now I force my customers to name the driver-module like I proposed. They can't name the module like mentioned in every standard-documentation.</p>
  
  <p>The idea comes from this <a href="https://stackoverflow.com/questions/18478811/whats-the-module-name-if-deploy-jdbc-in-jboss-as-7-as-web-application">question</a>.</p>
  
  <hr>
  
  <p>I am doing this in context of a keycloak installation with a self-implemented User-federation to access a separate (legacy) user-database. Therefore dropping the <code>jboss-deployment-structure.xml</code> is no option as mentioned above.</p>
  
  <p><strong>Whats the correct way to achieve my goal of being flexible with the jdbc-driver?</strong></p>
  
  <hr>
  
  <p><strong>EDIT:</strong> mentioned, dropping <code>jboss-deployment-structure.xml</code> is not working.</p>