BackPrevious Page Next PageNext

Configuring the datasource.xml File

Contents of datasource.xml

Reloading connection information from datasource.xml

Integrating JReport Server with your Java application server

Example 1: Using JNDI data source connections of WebLogic Server

Example 2: Using JNDI data source connections of JBoss server

In order to enable you to conveniently set different connections in JReport Server, a configuration file, datasource.xml, is provided with which you can change to another runtime JDBC or JNDI data source to run reports by setting up connection mapping information such as the JDBC driver, URL, or JNDI data source name, user and password, depending on the data source your application uses. This allows you to control the catalog data source connections in JReport Server to connect dynamically to your production data sources.

The datasource.xml file is located in the <install_root>\bin directory. Change this file according to the data source you want to use. Two types of connections are supported by JReport Server. They are JNDI data source connection and JDBC connection.

Contents of datasource.xml

There can be multiple <datasource></datasource> tags in datasource.xml. Each pair will map one of the connections in your catalog. You can define mapping connections for multiple connections for more than one catalog. The catalog connection name should be unique in the datasource.xml file, otherwise the latter <datasource> information will overwrite the previous ones.

The contents of the datasource.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<datasource-mapping>
    <datasource>
        <catalog-connection-name>Connection1</catalog-connection-name>
        <connection-type>JNDI</connection-type>
        <jndi-datasource>Sample</jndi-datasource>
    </datasource>
    <datasource>
        <catalog-connection-name>Connection2</catalog-connection-name>
        <connection-type>JDBC</connection-type>
        <driver>sun.jdbc.odbc.JdbcOdbcDriver</driver>
        <url>jdbc:odbc:jinfonet</url>
        <user>Username</user>
        <password>Password</password>
    </datasource>
</datasource-mapping>

Element descriptions

Reloading connection information from datasource.xml

After you have made changes to the datasource.xml file, you need to reload it in JReport Server. This file can be reloaded using either of the following ways:

Then restart JReport Server.

Integrating JReport Server with your Java application server

After updating the datasource.xml file, you can integrate JReport Server with your application server.

If you are using a WAR file, make sure that the datasource.xml file is included in the WAR file. Before making the JReport Server WAR file, in makewar.xml in the <install_root>\bin directory, add <include name="datasource.xml" /> into the <zipfileset dir="${installroot}/bin" prefix="workspace/bin"> section. Before you deploy the WAR file to a web server, make sure that the datasource.xml file is included in the jreport.war/WEB-INF/lib/jrenv.jar/workspace/bin directory.

If you are integrating JReport Server to an application using a non-JReport WAR file, usually you need to specify the -Dreporthome parameter in the application server so that the application server can locate and load the resources it needs. Since the datasource.xml already exists in the bin directory, you do not need to do anything special for this file.

Example 1: Using JNDI data source connections of WebLogic Server

Using WebLogic as an example, take the following steps:

  1. Start WebLogic server, navigate to <YourProjectName> > Services > JDBC > Connection Pools. In the Configuration tab, make sure that the connection you are going to use is there and correctly set up.
  2. Browse to  <YourProjectName> > Services > JDBC > Data Sources. In the Configuration tab, create a data source using the JNDI name MyJNDISample. Select the correct connection from the Pool Name drop-down list.
  3. Open datasource.xml in the <install_root>\bin directory and add:
    <datasource-mapping>
        <datasource>
            <catalog-connection-name>ConnectionName</catalog-connection-name>
            <connection-type>JNDI</connection-type>
            <jndi-datasource>MyJNDISample</jndi-datasource>
            <user>youruserid</user>
            <password>yourpassword</password>
        </datasource>
    </datasource-mapping>
  4. Build the JReport Server WAR file using the makewar utility in the <install_root>\bin directory.
  5. Deploy JReport Server to WebLogic.
  6. Run the report that uses this connection.

Example 2: Using JNDI data source connections of JBoss server

Using JBoss as an example, in this Example, DB2 is used, and JBoss is installed to D:\jboss-4.0.1, take the following steps:

  1. Copy the DB2 driver to D:\jboss-4.0.1\server\default\lib.
  2. Create a db2-ds.xml file in D:\jboss-4.0.1\server\default\deploy, and add the following content:
    <?xml version="1.0" encoding="UTF-8"?>
    <datasources>
        <local-tx-datasource>
            <jndi-name>DB2DataSource</jndi-name>
            <connection-url>jdbc:db2://dbs-b/sample</connection-url>
            <driver-class>com.ibm.db2.jdbc.net.DB2Driver</driver-class>
            <user-name>db2admin</user-name>
            <password>db2admin</password>
            <min-pool-size>0</min-pool-size>
            <metadata>
                <type-mapping>DB2</type-mapping>
            </metadata>
        </local-tx-datasource>
    </datasources>
  3. Modify datasource.xml in <install_root>\bin. Make sure that the following are included:
    <datasource-mapping>
        <datasource>
            <catalog-connection-name>ConnectionName</catalog-connection-name>
            <connection-type>JNDI</connection-type>
            <jndi-datasource>java:/DB2DataSource</jndi-datasource>
        </datasource>
    </datasource-mapping>
  4. Build the JReport Server WAR file using the makewar.bat utility in the <install_root>\bin directory.
  5. Deploy JReport Server to JBoss.
  6. Run the report that uses this connection.

BackPrevious Page Next PageNext