Running multiple versions of database drivers in JBoss EAP

Solution Verified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7.x

Issue

  • We need to use a specific and older version of the Oracle JDBC driver for compliance with one deployed application but we want to use the current version for all other application
  • I tried to run multiple versions of Oracle JDBC drivers in JBoss EAP 6.4.2 following the tutorial on https://access.redhat.com/solutions/185243. However, the 'slot' is not mentioned in the standalone.xml file when following the above. Could you help me determine the cause of this? In the article you mention there is a problem with this functionality in JBoss prior 6.4.2, but I'm using the latest version
  • How to Configure several oracle drivers in JBoss EAP 6.2?

Resolution

Please make sure the latest patches are applied

Directions after patching

When creating a module for the driver, you can specify a slot for it
The default slot is main

The below uses Oracle for the examples, but the syntax is the same for other databases.
The commands (other then the module command) are for standalone mode. For domain mode, simply prefix them with /profile=yourprofile

Start the CLI, but do not connect. For domain mode this will need to be done on each host controller.

Install the default driver:

module add --name=com.oracle.jdbc --resources=/path/to/ojdbc6_11.2.0.3.jar --dependencies=javax.api,javax.transaction.api

Add a specific version to it's private slot - we're using the slot "appX" to indicate this is used by application X (but the name is free to choose of course)

module add --name=com.oracle.jdbc --resources=/path/to/ojdbc6_11.2.0.2.0.jar --slot=appX --dependencies=javax.api,javax.transaction.api

For reference, this results in the directory structure:

modules/com/oracle/jdbc/
├── main
│   ├── module.xml
│   └── ojdbc6_11.2.0.3.jar
└── appX
    ├── module.xml
    └── ojdbc6_11.2.0.2.0.jar

The module.xml for the "appX" will look like this; note the "slot" attribute:

<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="com.oracle.jdbc" slot="appX">
    <resources>
        <resource-root path="ojdbc6_11.2.0.2.0.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

Next, in the CLI, connect to the standalone instance or to the domain controller.

Register both drivers:

The default one, which will become the "main" slot.

/subsystem=datasources/jdbc-driver=oracle:add(driver-module-name=com.oracle.jdbc,driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource,driver-name=oracle)

and the specific one, in the "appX" slot

/subsystem=datasources/jdbc-driver=appX:add(driver-module-name=com.oracle.jdbc,driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource,driver-name=appX,module-slot=appX)

For reference, this results in the XML snippet; note the ":appX" suffix to the "module" attribute

<subsystem xmlns="urn:jboss:domain:datasources:1.1">
  <datasources>
...
    <drivers>
      <driver name="oracle" module="com.oracle.jdbc">
        <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
      </driver>
      <driver name="appX" module="com.oracle.jdbc:appX">
        <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
      </driver>
    </drivers>
  </datasources>
</subsystem>

When creating datasource, simply specify if you want to use the "oracle" or the "appX" driver.
Details on setting up datasources can be found in How to create a datasource from the JBoss CLI in JBoss EAP 6

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.