Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Setting Oracle Datasource in JBoss AS 7



Here are step by step directions on how to configure JBoss AS 7 to communicate with Oracle XE.

1. Create directory for the oracle driver deployment

$ cd $JBOSS_HOME/modules
$ mkdir -p com/oracle/ojdbc6/main
$ vi module.xml

Add the following snippet to the newly created module.xml file
<module xmlns="urn:jboss:module:1.0" name="com.oracle.ojdbc6">
  <resources>
    <resource-root path="ojdbc6.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
  </dependencies>
</module>

Copy the ojdbc6.jar to $JBOSS_HOME/modules/com/oracle/ojdbc6/main [make sure your jar META-INF folder is having a Services dir with a file called java.sql.Driver]

Next, create the driver definition in the standalone configuration file

$ vi $JBOSS_HOME/standalone/configuration/standalone.xml

Look for
<subsystem xmlns="urn:jboss:domain:datasources:1.0"> 

this is where the datasource and driver configuration will go. Within this subsystem, look for the section and add the following:
<driver name="oracle" module="com.oracle.ojdbc6">
  <xa-datasource-class>
    oracle.jdbc.OracleDriver
  </xa-datasource-class>
</driver>

Then create the datasource configuration, also in the standalone configuration file. The following block will go just below the <datasources> element.
<datasource jndi-name="WorkCenterDS" pool-name="OracleDS" enabled="true" jta="true" use-java-context="true" use-ccm="true">
  <connection-url>jdbc:oracle:thin:@localhost:1521:oradb1</connection-url>
  <driver>oracle</driver>
  <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
  <pool>
    <prefill>true</prefill>
    <use-strict-min>false</use-strict-min>
    <flush-strategy>FailingConnectionOnly</flush-strategy>
  </pool>
  <security>
    <user-name>user1</user-name>
    <password>1234</password>
  </security>
</datasource>

Restart JBoss and look for the following lines in your log file to determine if the deployment succeeded.

Your rating: None Average: 4.1 (18 votes)