JBoss AS 7.1.1 has been released and one of its appealing news is the "resurrection" of the earlier -ds.xml datasources which can now be deployed as a standalone resource or even as part of an application.
We have to admit, we were missing it. Although configuring a datasource with AS7 just requires a few minutes work, deployable datasources are a precious quickstart resource (especially for testing purposes).
So how do we get a datasource deployed?
Step 1: At first you need an available driver
The simplest way to provide a driver is copying it into the deployments folder of your application server. Supposing we are going to install a MySQL Driver:
cp mysql-connector-java-5.1.18-bin.jar /usr/jboss-as-7.1.1.Final/standalone/deployments
Now check that the driver has been successfully deployed on the server logs:
09:32:10,400 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559:
Step 2: Deploy the datasource file
Just fill in an xml file which ends (as we used to do) in -ds.xml, for example this is a mysql-ds.xml which is suitable for MySQL database:
JBoss AS should log your successful datasource deployment:
09:37:45,949 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "mysql-ds.xml"
09:37:46,001 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) JBAS010400: Bound data source [jboss/datasources/MySqlDB]
09:37:46,042 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "mysql-ds.xml"
Drawbacks?At this point you might wonder if there is any pitfall when using the older -ds.xml approach ? well actually if you "bypass" the management interface and deploy the datasource in the old way, you will not be able to manage it through the CLI or Web admin interface. As you can see from this snapshot, our datasource is not enlisted through the manageable resources of the Web interface.
Deploying the datasource along with your applicationYou can actually deploy your datasource along with your application, just you used to do in the past.
Here's a sample Web application Structure which ships with a datasource (in the WEB-INF folder). For other a JAR archive you would rather need copying the datasource in the META-INF folder: