Monday, June 22, 2015

Configuring Oracle Driver on Jboss Wildfly 8.0

If looking for configuring oracle jdbc driver as an module for supporting XML data types, continue to read.

My initial setup was simple, an web application which uses oracle as backend with spring jdbc. I just deployed the oracle driver jar (ojdbc-6.jar) an a deployment using the jboss management console and used it to configure the datasource in standalone.xml. Everything was working fine till i used the XML datatypes as part of our design.

Immediately the fun started. Got the error NoClassDefFoundError: oracle/xdb/XMLType. After some research found that we need to include xdb-6.jar which can be found in the oracle client/server installations.
Added that the restarted the application, half expecting success!. Surprise!, got another error, related to xml parser exception. Turned out that i need to include another jar xmlparserv2.jar from oracle. This continued this for a while and found that creating the oracle driver as an module in wildfly or jboss as is the way to go.

Step 1: 

Create a folder as below under /modules/system/layers/base/com/oracle/main

Step 2:

Create the module configuration xml "module.xml" with below content<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.oracle">
    <resources>
        <resource-root path="ojdbc-6.jar"/>
        <resource-root path="xdb-6.jar"/>
        <resource-root path="xmlparserv2.jar" />
        <resource-root path="orai18n.jar" />
        <resource-root path="orai18n-collation.jar" />
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

Step 3:

Find and copy all the jars from your target oracle servers installation

ojdbc-6.jar
xdb-6.jar
orai18n.jar
orai18n-collation.jar
xmlparserv2.jar

Step 4:

Configuring the standalone.xml to load the driver module
Add the below snippet in section of your standalone.xml
        
</drivers>
....
        <driver name="oracle" module="com.oracle">
                <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> 
        </driver>
</drivers>

Step 5:

Referring the newly added driver in the datasource. You just need to refer the configured driver by name. Sample snippet below.


<datasource jta="true" jndi-name="java:/jdbc/MetricsDS" pool-name="MetricsDS" enabled="true" use-ccm="true">
            <connection-url>jdbc:oracle:thin:@10.158.20.50:1521:DEVDB1</connection-url>
            <driver>oracle</driver>
            <pool>
        ....
<datasource>

Step 6:

Remember to remove all existing ojdbc jars in your applications. This might cause inconvenience when you want to run your application in another container like tomcat due to the missing jar. But that's manageable by dropping the jar into the servers common lib folders.

Now start the wildfly/jboss server, and everything works just fine!