Skip to end of metadata
Go to start of metadata

Datasources are configured through the datasource subsystem. Declaring a new datasource consists of two separate steps: You would need to provide a JDBC driver and define a datasource that references the driver you installed. 

JDBC Driver Installation

The recommended way to install a JDBC driver into WildFly 8 is to deploy it as a regular JAR deployment.  The reason for this is that when you run WildFly 8 in domain mode, deployments are automatically propagated to all servers to which the deployment applies; thus distribution of the driver JAR is one less thing for you to worry about!

Any JDBC 4-compliant driver will automatically be recognized and installed into the system by name and version. A JDBC JAR is identified using the Java service provider mechanism. Such JARs will contain a text a file named META-INF/services/java.sql.Driver, which contains the name of the class(es) of the Drivers which exist in that JAR. If your JDBC driver JAR is not JDBC 4-compliant, it can be made deployable in one of a few ways.

Modify the JAR

The most straightforward solution is to simply modify the JAR and add the missing file. You can do this from your command shell by:

  1. Change to, or create, an empty temporary directory.
  2. Create a META-INF subdirectory.
  3. Create a META-INF/services subdirectory.
  4. Create a META-INF/services/java.sql.Driver file which contains one line - the fully-qualified class name of the JDBC driver.
  5. Use the jar command-line tool to update the JAR like this:

For a detailed explanation how to deploy JDBC 4 compliant driver jar, please refer to the chapter "Application Deployment".

Datasource Definitions

The datasource itself is defined within the subsystem datasources:

(See standalone/configuration/standalone.xml)

As you can see the datasource references a driver by it's logical name.

You can easily query the same information through the CLI:

Using the web console or the CLI greatly simplifies the deployment of JDBC drivers and the creation of datasources.

The CLI offers a set of commands to create and modify datasources:

Using security domains

Information can be found at https://community.jboss.org/wiki/JBossAS7SecurityDomainModel

Deployment of -ds.xml files

Starting with WildFly 8, you have the ability to deploy a -ds.xml file following the schema:

http://www.ironjacamar.org/doc/schema/datasources_1_1.xsd

It is mandatory to use a reference to an already deployed / defined <driver> entry.

This feature is primarily intended for development, and thus has a few limitations to be aware of. It can not be altered in any of the management interfaces (consle, CLI, etc). Only limited runtime information is available. Also, password vaults and security domains are not deployable, so these can not be bundled with a datasource deployment.

Component Reference

The datasource subsystem is provided by the IronJacamar project. For a detailed description of the available configuration properties, please consult the project documentation.

Labels:
s s Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. May 09, 2014

    In the example, the h2 driver is used, and the driver-name=h2 so its easy to define a datasource. 

    I found no way to set the driver-name on deploy of a jdbc driver other than editing the standalone.xml file. I understood this is not the way to go and it is recommended to use the web console or the cli to manipulate the standalone.xml.

    I'm using the cli comman 'deploy <file> --name <driver-name>' .

    In jboss 7.x, this would set the driver-name correctly, in wildfly 8.x it does not. In wildfly, it sets the runtime-name, but this is not used when defining a datasource. A datasource needs a correctly set driver-name.

    I tested this on 8.0.0Final and 8.1.0CR1.

    Is this a bug or am I doing something wrong ?

    1. May 09, 2014

      Please file jira bug report and we can go on from there.

  2. Jan 07, 2015

    Please provide HowTo install driver as a module as an alternative. I found that driver deployed as a JAR is undeployed on failed web app startup. It is not a rare case when web app throws exception and does not start while development. I observed in Eclipse Kepler + JBoss Tools that failed web app start undeploys Oracle driver. 

      1. Jan 08, 2015

        Thanks for pointing in the right direction. The link you provided is for JBoss-6. The actual steps required to install Oracle driver ojdbc6 on WildFly-8 are slightly different. The example below is for standalone server:

        1. Create directory [WH-HOME]\modules\system\layers\base\com\oracle\ojdbc6\main
        2. Copy ojdbc6.jar to this directory
        3. Create module.xml file in this directory

        <?xml version="1.0" encoding="UTF-8"?>
        <module xmlns="urn:jboss:module:1.3" name="com.oracle.ojdbc6">
          <resources>
            <resource-root path="ojdbc6.jar"/>
          </resources>
          <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
          </dependencies>
        </module>

        4. Start WildFly-8: [WF-HOME]\bin\standalone.bat
        5. Start Management CLI: [WF-HOME]\bin\jboss-cli.bat
        6. The Management CLI session will be the following (red is your input)

        C:\Servers\wildfly-8.2.0.Final\bin>jboss-cli.bat
        You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
        [disconnected /] connect
        [standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=ojdbc6:add(driver-name=ojdbc6,driver-module-name=com.oracle.ojdbc6)
        ["outcome" => "success"]
        [standalone@localhost:9990 /] quit
        Press any key to continue . . .

        7. The result is the added line in [WH-HOME]\standalone\configuration\standalone.xml file:

        <profile>
          . . .
          <subsystem xmlns="urn:jboss:domain:datasources:2.0">
            <datasources>
              <drivers>
                 . . .
                 <driver name="ojdbc6" module="com.oracle.ojdbc6"/>
              </drivers>
            </datasources>
          </subsystem>
        </profile>
  3. Mar 29, 2015

    Due to this not working in 8.2.0 Final for domain deployment (as already logged by others) the workaround I found was a slightly more involved.

    On all hosts in the domain, make the directory and copy the jar file and the above .xml file in there (I'm on Linux though)

    mkdir -p {wildfly home}/modules/system/layers/base/com/oracle/ojdbc6/main
    cp ojdbc6.jar {wildfly home}/modules/system/layers/base/com/oracle/ojdbc6/main
    cp module.xml {wildfly home}/modules/system/layers/base/com/oracle/ojdbc6/main
    

    Use the CLI to register the driver.

    [disconnected /] connect server-01.example.com
    [domain@server-01.example.com:9990 /] /profile=full-ha/subsystem=datasources/jdbc-driver=ojdbc6:add(driver-name=ojdbc6,driver-module-name=com.oracle.ojdbc6
    {
        "outcome" => "success",
        "result" => undefined,
        "server-groups" => {"app-server-group" => {"host" => {
            "server-02.example.com" => {"app-server-2" => {"response" => {
                "outcome" => "success",
                "result" => undefined
            }}},
            "master" => {"app-server-1" => {"response" => {"outcome" => "success"}}}
        }}}
    }
    exit
    

    Now when I create a datasource the driver appears, and it passes a connection test but won't enable. Seems I need to edit the domain.xml manually for that.

  4. Jul 06, 2015

    how i set datasource isolation levels??