Setting up data source for JBoss

Setting up data source for JBoss 7

Data source configuration in JBoss AS 7 is different from that in the older versions. Please follow instructions below to create the data source in JBoss AS 7 (or refer to the Web site http://community.jboss.org/wiki/DataSourceConfigurationInAS7).

The following section will take one database type (ASA/SQL Anywhere database with Sybase jConnect JDBC driver) as an example to show you how to create a data source for JBoss AS 7, you can later create data sources for other database types by taking the same steps below but specifying different parameters according to Data source parameters.

You need to perform two main tasks to define a data source in JBoss AS 7. First, you must make the JDBC driver available to the application server; then you need to configure the data source that references the driver you installed.

Method 1
Installing a JDBC driver via the configuration file

Step 1: Go to the "modules\com" directory under the root directory of the JBoss application server (e.g. jboss-as-7.1.1.Final\modules\com), create a "asa" subdirectory and a "asa\main" subdirectory, so the directory looks like the following: jboss-as-7.1.1.Final\modules\com\asa\main.

Step 2: Go to the "main" directory, paste the driver JAR file there, in this example, the jconn3.jar file.

Step 3: Go to the "main" directory, create a module.xml file, and define the file as follows.

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.asa">
  <resources>
    <resource-root path="jconn3.jar"/>
        <!-- Insert resources here -->
  </resources>
  <dependencies>
    <module name="javax.api"/>
  </dependencies>
</module>

As you can see from above, in this example, set the module name to "com.asa", which matches the directory structure you had created under the "modules" directory. Set resource-root path to the JAR file name, the path appears to be relative, and default to the "main" directory under the directory structure you created, which is "com/asa" in this example.

Finally, define any dependencies you might have. In this case, as the case with all JDBC data sources, we would be dependent on the Java JDBC API's, which in this case is defined in another module called javax.api, which you can find under modules/javax/api/main as you would expect.

Different database drivers might require different dependencies. For example, the IBM DB2 database working with the IBM JDBC driver requires the following dependencies:

  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
    <module name="javax.servlet.api" optional="true"/>
  </dependencies>

And the following class name (specified in the standalone.xml file later in the next section):

          <driver name="db2jdbc" module="com.ibm.db2">
                 <driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
                 <xa-datasource-class>com.ibm.db2.jcc.DB2XADataSource</xa-datasource-class>
          </driver>

You can check the documents provided by the corresponding database driver vendor to find out the dependencies and the class name.

Step 4: Modify the JAR file.

  1. Under the same directory as the jconn3.jar file, create a "META-INF" subdirectory and a "META-INF\services" subdirectory.

  2. Under the "META-INF\services" directory, create a java.sql.Driver file which contains one line - the fully-qualified class name of the JDBC driver, in this example, com.sybase.jdbc3.jdbc.SybDriver.

  3. Execute the "jar" command to update the JAR file: "jar -uf jconn3.jar META-INF/services/java.sql.Driver". You can also use WinRAR tool to add the java.sql.Driver file to the "MEAT-INF\services" directory in jconn3.jar, as shown in the following figure.

    Figure 51. Modify the jar file

    Modify the jar file

Configuring the data source for JBoss AS 7 via the configuration file

Step 5: Open the standalone.xml file under the <jboss_installation_root>\standalone\configuration folder, find the related datasource, and then add the prefix "java:/" to the jndi-name value if there is not such prefix in it, as shown in the following sample code.

You will need to check the documents provided by the corresponding database driver vendor to find out the class name.

<datasources>
      <datasource jndi-name="java:/AppeonSample" pool-name="AppeonSample" enabled="true" jta="true" use-java-context="true" use-ccm="true">
          <connection-url>jdbc:sybase:Tds:192.0.3.150:2638/AppeonSample
          </connection-url>
                 <driver>jconnect3</driver>
                 <security>
                      <user-name>dba</user-name>
                      <password>sql</password>
                 </security>
      </datasource>
      <drivers>
          <driver name="jconnect3" module="com.asa">
                 <driver-class>com.sybase.jdbc3.jdbc.SybDriver</driver-class>
          </driver>
          ...
      </drivers>
      ...
</datasources>
Method 2
Installing a JDBC driver via the Web console

Step 1: To directly access the Management Console, point your browser at: http://localhost:8080/ or http://127.0.0.1:8080/. If you want to access the console via LAN or WAN (or call EJB), you will need to modify the standalone.xml to add a new interface. For example:

<interfaces>
        <interface name="management">
            <inet-address value="127.0.0.1"/>
        </interface>
        <interface name="public">
            <inet-address value="127.0.0.1"/>
        </interface>

       <!-- Equivalent of -b 0.0.0.0 -->
        <interface name="any">
            <any-address/>
        </interface>
</interfaces>

And use this new interface in the socket-binding-group:

<!-- Use the "any" interface -->
<socket-binding-group name="standard-sockets" default-interface="any">
        <socket-binding name="http" port="8080"/>
        <socket-binding name="https" port="8443"/>
        <socket-binding name="jmx-connector-registry" port="1090"/>
        <socket-binding name="jmx-connector-server" port="1091"/>
        <socket-binding name="jndi" port="1099"/>
        <socket-binding name="osgi-http" port="8090"/>
        <socket-binding name="remoting" port="4447"/>
        <socket-binding name="txn-recovery-environment" port="4712"/>
        <socket-binding name="txn-status-manager" port="4713"/>
</socket-binding-group>

Step 2: If you have not yet added at least one management user, an error page will be displayed asking you to add a new user. You can run the add-user.bat (add-user.sh for Linux) in the jboss-as-7.1.1.Final\bin folder. For details, please refer to the Managing your JBoss Application Server 7 | Authentication section at https://docs.jboss.org/author/display/AS71/Getting+Started+Guide.

Figure 52. Add a new user

Add a new user


Step 3: Log on to the JBoss AS Administration Console, as shown in figure below.

Figure 53. Datasources Configuration page

Datasources Configuration page

Step 4: Click Deployments > Manage Deployments, as shown in figure below.

Figure 54. Manage Deployments page

Manage Deployments page


Step 5: Modify the JAR file, refer to Step 4 in "Installing a JDBC driver via the configuration file" for details. Click Add Content to deploy this .jar file.

  1. Upload the jconn3.jar, and click Next.

    Figure 55. Upload the jar file

    Upload the jar file


  2. Verify the deployment names and click Save.

    Figure 56. Verify the deployment name

    Verify the deployment name


Step 6: Click Enable to enable the jconn3.jar, as shown in the following figure.

Figure 57. Enable the jar file

Enable the jar file


Configuring the datasource for JBoss AS 7 via the Web console

Step 7: Set up the target database as a service, and start the service SQLAnywhere-appeonsample by inputting the following command lines in the sqlAnywhere.bat:

"C:\Program Files\SQL Anywhere 12\Bin32\dbsrv12.exe" -x tcpip(port=2698) -n duanserv2 "D:\jboss711-hsqldb-2\AppeonSample.db".

Step 8: Switch to the Profile tab, and click Add to create a new datasource, as shown in the following figure.

Figure 58. Add a new datasource

Add a new datasource


  1. Input any text as the data source name and the JNDI name. For example, "java:/appeonsample". Click Next.

    Note: The JNDI name will be used as the data source name in AEM.

    Figure 59. Specify datasource attributes

    Specify datasource attributes

  2. Select the JDBC driver, in this example, jconn3.jar. Click Next.

    Figure 60. Specify JDBC driver

    Specify JDBC driver


  3. Specify the connection information and click Done.

    The following table describes how to specify the connection information for Sybase ASA/SQL Anywhere databases. The values are different according to database types. You can refer to Data source parameters.

    Table 24. Connection properties

    Connection URL

    For example, jdbc:sybase:Tds:192.0.2.204:2698?ServiceName=appeonsample

    Username

    Type the database login username. The username is set on the database server.

    Password

    Type the database login password. The password is set on the database server.


    Figure 61. Specify connection information

    Specify connection information


Step 9: After the data source is created successfully, you will be redirected to the Datasources page and you will be able to see the new data source in the list.

Figure 62. Datasource list

Datasource list

Setting up data source for JBoss 5

The following section will take one database type (Oracle database with Oracle JDBC driver) as an example to show you how to create a data source for JBoss 5, you can later create data sources for other database types by taking the same steps below but specifying different parameters according to Data source parameters.

Detailed steps are as below:

Step 1: Start JBoss AS 5 and log on to the JBoss AS Administration Console.

Step 2: Click Resources > Datasources > Local Tx Datasources, as shown in figure below.

Step 3: Click Add a new resource.

Figure 63. Add a new datasource

Add a new datasource

Step 4: In the Resource Template, select Oracle Local Tx and then click Continue.

If you are using other type of database, please select default.

Figure 64. Select resource template

Select resource template

Step 5: Specify the connection information and click Save.

Figure 65. Specify connection information

Specify connection information

The following table describes how to specify the properties for connection information

Table 25. Datasource properties

JNDI Name

Input any text as the data source name. For example, "oracle_datasource1". This name will be recognized as the data source name in AEM.

Username

Type the database login username. The username is set on the database server.

Password

Type the database login password. The password is set on the database server.

JDBC Driver Class

oracle.jdbc.driver.OracleDriver

Connection URL

jdbc:oracle:thin:@Hostname:Port:DBName

for example, jdbc:oracle:thin:@192.0.0.51:1521:testing


Step 6: In order to test the connection, please log on to Appeon AEM to configure a Transaction Object and then test it.