Search code examples
jdbcjbosswildflykeycloak

Whats the correct way to allow different jdbc drivers for deployed applications on JBoss / Wildfly?


My setting is the following:

  • I got an application, which I deploy in /standalone/deployments
  • The jboss-deployment-structure.xml of my deployment in /standalone/deployments looks the following:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            [...]
            <module name="org.postgresql"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>
<?xml version="1.0" encoding="UTF-8"?>
<module name="org.postgresql" xmlns="urn:jboss:module:1.5">
    <resources>
        <resource-root path="postgresql-42.2.5.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>
  • My requirement is, to allow different types of jdbc-drivers, e.g. postgres, oracle, mssql.

First option:

I can change my jboss-deployment-structure.xml to

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            [...]
            <module name="org.postgresql" optional="TRUE"/>
            <module name="com.oracle.ojdbc6" optional="TRUE"/>
            [...]
        </dependencies>
    </deployment>
</jboss-deployment-structure>

(added the optional-parameter)

Then I have to allow all drivers explicitly. Seems to be not the best way.

The idea comes from the standard documentation.


Second option:

I change my module-path to driver/jdbc/main (instead of org/postgres/main) and the module.xml to

<module name="driver.jdbc" xmlns="urn:jboss:module:1.5">
[...]
</module>

(changed name of module)

and go with the module-reference in my jboss-deployment-structure.xml like

<jboss-deployment-structure>
    [...]
    <module name="driver.jdbc"/>
    [...]
</jboss-deployment-structure>

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.

The idea comes from this question.


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 jboss-deployment-structure.xml is no option as mentioned above.

Whats the correct way to achieve my goal of being flexible with the jdbc-driver?


EDIT: mentioned, dropping jboss-deployment-structure.xml is not working.


Solution

  • At least I went with a hybrid solution of my two above mentioned approaches for the jboss-deployment-structure.xml like as follows

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
        <deployment>
            <dependencies>
                <module name="org.postgresql" optional="TRUE"/>
                <module name="com.oracle.ojdbc6" optional="TRUE"/>
                [...]
                <module name="driver.jdbc" optional="TRUE"/>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>
    

    I listed all the relevant database divers as optional modules and listed another one with flexible naming if a driver is desired, which is not mentioned in the list above.