JBoss migration – the data source

I have spent a lot of time lately trying to create a migration plan for an application currently running on JBoss 4.2.2. Since this application development started a few migration attempts to newer versions of JBoss have been done (see for 5.1) but as it seems each version has different style configuration files and this application is expected to have a long lifetime the work seems a bit futile so in parallel of
migrating to JBoss-7.1.1 I’ve tried to migrate to Tomcat since our use of EJB’s is limited and other MBeans can be refactored in simpler ways. Unlike JBoss, Tomcat configuration seems to be eternal and by all means simpler.

1. The data source

The purpose of the following configurations is to define an JNDI DataSource which can be then used in the application allowing DB configuration to be separated from the application itself.

1.1 JBoss 4.2.2

In JBoss 4.2.2 the datasource was defined in a ${name}-ds.xml in the following format:

<?xml version="1.0" encoding="UTF-8"?>
        <!-- ... -->

The JNDI name will be: java:/XOracleDS.

1.2 JBoss 7.1.1

In JBoss 7.1.1 first a module has to be defined as jboss-7/modules/com/oracle/ojdbc4/main containg the ojdbc14.jar and a module.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.oracle.ojdbc4">
        <resource-root path="ojdbc14.jar"/>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>

Then the file jboss-7/standalone/configuration/standalone.xml has to be modified. The datasources part should be changed to:

<datasource jndi-name="java:/XOracleDS" pool-name="XOracle" enabled="true" use-java-context="true">
    <driver name="oracle" module="com.oracle.ojdbc4">

Note that this method deploys the JDBC driver as a core module. There is an alternative to install as a deployment which can be found here. This link is one of the basis, even if not always complete for migration information.
The JNDI name will be: java:/XOracleDS.

1.3 Tomcat

In Tomcat the definition of the datasource is (can be) done in a context.xml file located in $CATALINA_HOME/conf/context.xml

<Resource name="jdbc/XOracleDS"

One thing to note is that the Tomcat JNDI name will be: java:/comp/env/jdbc/XOracleDS since the prefix is mandatory.


Leave a Reply