Hi,

Jay SenSharma

Jay SenSharma

There are many forums and web Links which describes an Issue while creating the DataSource using Ant Script using the “weblogic.ant.taskdefs.management.WLConfig” ant task. Here we are going to create a DataSource for WLS Version 9.x onwards. It means this script is suitable for Any WebLogic Version which is higher than WLS9.
.


People face the Problem because the concept of Connection Pool and dataSource is changed a bit after WLS8.1 version. Earlier we used to separately create Connection Pool and then We used to assign the Connection pool to DataSource. But from WLS9.x onwards we ned to just create the DataSource which internally have all the configuration of Connection Pool.

NOTE: Please read the bottom of this Page  ( Instruction-3) to know a related BUG. (Tested on WebLogic10.3.0)

Step1). Start Pointbase Server (U can use any DataBase Server..just for testing we are using Pointbase).
C:bea103wlserver_10.3commonevalpointbasetoolsstartPointBase.cmd

Step2). Create a Folder somewhere inside your file system “C:ANT_DataSource” and then write a “build.xml” file inside this directory as following:

<?xml version="1.0" ?>
<project name="deploy" default="makeDataSource" basedir=".">
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.url" value="t3://localhost:7001" />
<property name="wls.targetServer" value="AdminServer" />
<property name="wls.domainName" value="base_domain" />
<property name="database.url" value="jdbc:pointbase:server://localhost:9092/demo" />
<property name="database.driver" value="com.pointbase.jdbc.jdbcUniversalDriver" />
<property name="database.user" value="PBPUBLIC" />
<property name="database.password" value="PBPUBLIC" />

<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<taskdef name="wlconfig" classname="weblogic.ant.taskdefs.management.WLConfig"/>

<target name="makeDataSource">
         <wlconfig username="${wls.username}" password="${wls.password}" url="${wls.url}">
               <query domain="${wls.domainName}" type="Server" name="${wls.targetServer}" property="x" />
               <create type="JDBCConnectionPool" name="TestDS">
                           <set attribute="CapacityIncrement" value="1"/>
                           <set attribute="DriverName" value="${database.driver}"/>
                           <set attribute="InitialCapacity" value="1"/>
                           <set attribute="MaxCapacity" value="10"/>
                           <set attribute="Password" value="${database.password}"/>
                           <set attribute="Properties" value="user=${database.user}"/>
                           <set attribute="RefreshMinutes" value="0"/>
                           <set attribute="ShrinkPeriodMinutes" value="15"/>
                           <set attribute="ShrinkingEnabled" value="true"/>
                           <set attribute="TestConnectionsOnRelease" value="false"/>
                           <set attribute="TestConnectionsOnReserve" value="true"/>
                           <set attribute="TestTableName" value="SYSTABLES"/>
                           <set attribute="URL" value="${database.url}"/>
                           <set attribute="Targets" value="${x}" />
                    </create>

                    <create type="JDBCDataSource" name="TestDS" >
                          <set attribute="JNDIName" value="jdbc/TestDS"/>
                          <set attribute="PoolName" value="TestDS"/>
                          <set attribute="Targets" value="${x}" />
                     </create>
          </wlconfig>
</target>
</project>

Step3). Run the “setWLSEnv.cmd” in a new fresh command prompt to set the enironment.
NOTE: If you are using Unix based Operating System then please read the below instructions carefully while running the setWLSEnv.sh script…

. ./setWLSEnv.sh
Note: the first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.
Now Verify that the Classpath is Set properly or not:
echo $CLASSPATH

Step4). Now start WebLogic server then run the above ant script like following:

Ant task DataSource Creation

Ant task DataSource Creation

Step5). Now Login to AdminConsole and verify the DataSource Test is Successful or not.

Verifying Ant Created DataSource is OK?

Verifying Ant Created DataSource is OK?

Testing dataSource Created by Ant task

Testing dataSource Created by Ant task

————————–

INSTRUCTIONS-1:

Remember to set the Domain Name and the target Server name very carefully in the above ANT Script using:
<query domain=”base_domain” type=”Server” name=”AdminServer” property=”x”/>

Otherwise you will get the following Error:

C:ANT_DataSourcebuild.xml:8: Error invoking MBean command: java.lang.IllegalArgumentException: Property Name and value not valid for the MBean. Value AdminServer for parameter[Targets].java.lang.IllegalArgumentException: Unable to convert the argument valueAdminServer to class javax.management.ObjectName.java.lang.reflect.InvocationTargetException

INSTRUCTIONS-2:

As the Configuration Steps of DataSource and Connection pool creation is little change from WLS9.x onwards …so Always make sure that you set the ConnectionPool Name as the DataSource Name…because now we need to create only DataSource ..which internally holds the configuration of ConnectionPool…please relook on the following lines in the above Ant Script.

<create type=”JDBCConnectionPool” name=”TestDS” >
<create type=”JDBCDataSource” name=”TestDS”>

INSTRUCTIONS-3: (Looks Like a BUG)

Even you set the JNDI name for your DataSource using the following Tag …It’s not going to change the Actual JNDI name as “jdbc/TestDS” rather the PoolName/DataSource Name will be treated as a JNDI name. Which looks like a WebLogic BUG.

<set attribute=”JNDIName” value=”jdbc/TestDS”/>

Try setting a Different JNDI name…u will find that the JNDI name is not taking effect. Even in the JNDI tree of the Server u will not be able to see any JNDI entry for our DataSource after creating the dataSource through the Above ANT Script. But the testing of the DataSource Succeeds.

.
.
Thanks
Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.