17.03.2013
JBoss DataSource for Apache Derby
This short article describes how configure a DataSource for Apache Derby 10.9 in JBoss AS 7.1.1. Generally there are two ways to create a DataSource in JBoss:
- Copy the JDBC driver into the
deploymentsdirectory - Create a module with the JDBC driver
Also it is necessary to create a DataSource definition in the file standalone.xml. It is recommended to deploy the driver as module.
Direct Deployment
The first solution is a very easy way to deploy the Derby driver in the application server. If you quickly want to test something it is sufficient. But in a productive environment it is better to create a module definition in the JBoss. (see next section)
To deploy the Derby driver directly you simply copy the driver derbyclient.jar into the directory [JBOSS]/standalone/deployments. If the server is running the new file is recognized by JBoss and automatically deployed.
Then you have to adapt the file [JBOSS]/standalone/configuration/standalone.xml. Add the following section into the file:
<datasources>
...
<datasource jndi-name="java:/DerbyDS" pool-name="DerbyDS" enabled="true" use-ccm="false">
<connection-url>jdbc:derby://localhost:1527/jhDB;create=true</connection-url>
<driver-class>org.apache.derby.jdbc.ClientDriver</driver-class>
<driver>derbyclient.jar</driver>
<security>
<user-name>demo</user-name>
<password>demo</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
...
</datasources>
Please note: JBoss 7.1.1 has a bug (AS7-4222). When deploying a JDBC driver direct in the deployments directory an error occurs in the logfile or console:
14:58:20,140 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.derbyclient_jar (missing) dependents: [service jboss.data-source.java:/DerbyDS]
...
14:58:20,337 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "derbyclient.jar"
14:58:20,338 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014776: Newly corrected services:
service jboss.jdbc-driver.derbyclient_jar (no longer required)
Deployment as module
To deploy the driver as a module you have to create the following directory [JBOSS]/modules/org/apache/derby/main ([JBOSS]/modules/org/apache should already exist.). In this directory create a file module.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.apache.derby">
<resources>
<resource-root path="derbyclient.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
Copy the Derby JDBC driver derbyclient.jar into the directory [JBOSS]/modules/org/apache/derby/main, too.
Now you have to adapt the file standalone.xml in the directory [JBOSS]/standalone/configuration. Add the following datasource definition in the section datasources.
<datasources>
...
<datasource jndi-name="java:/DerbyDS" pool-name="DerbyDS" enabled="true" use-ccm="false">
<connection-url>jdbc:derby://localhost:1527/jhDB;create=true</connection-url>
<driver>org.apache.derby</driver>
<security>
<user-name>demo</user-name>
<password>demo</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="org.apache.derby" module="org.apache.derby">
<xa-datasource-class>org.apache.derby.jdbc.ClientXADataSource</xa-datasource-class>
</driver>
</drivers>
...
</datasources>
When you restart JBoss the datasource is available. You can verify this by opening the JBoss Admin Console:
