Skip to main content

Working with J2C Ant Scripts in Rational Application Developer V7

Tips to customize and run J2C Session Recording Ant script

Ivy Ho (ivyho@ca.ibm.com), Java Connector Tool, Rational, IBM, Software Group
Ivy Ho
Ivy is currently working on the Java Connector Tooling team in the Rational area. She obtained Project Management Professional (PMP) certification in 2005. She received an honors degree in Mathematics (major in Computer Science and minor in Statistics) from the University of Waterloo.
Laszlo Benedek (lbenedek@ca.ibm.com), Application and Integration Middleware Software, WebSphere, IBM Toronto Lab
Laszlo Benedek
Laszlo is currently working on the Adapter Tooling team in the IBM WebSphere area. He has a University and a Master's degree in Computer Science.

Summary:  In IBM® Rational® Application Developer V7.0, one of the most helpful features in the J2EE™ Connector (J2C) Tools is the J2C session recording. When you create beans and data bindings using the J2C wizards, you can now save the settings in an Ant file. You can then invoke the Ant script inside the workbench (or from the command line) to generate J2C Java beans and data bindings.

Date:  05 Dec 2006
Level:  Intermediate
Activity:  1101 views

Introduction

This article demonstrates how to customize the Ant scripts that the Rational Application Developer V7 J2EE Connector (J2C) Tools create.

It provides different Ant script examples, from generating data binding files based on the COBOL source to generating a complete J2C bean accessing a CICS/IMS transaction. It also explains how to run the Ant script from the command line.

Ant is a very powerful development tool for building and automating processes. By using some of the core Ant tasks and some custom J2C Ant tasks in IBM Rational Application Developer V7, you can generate a complete Java™ 2 Platform, Enterprise Edition (J2EE™ platform) Connector architecture bean for CICS/IMS.

The advantages of using Ant to generate the J2C bean and data binding beans include:

  • Flexibility: If the structure of the data is constantly changing on the backend, it becomes tedious and error-prone to recreate the data binding beans for each modification of the native data type. Using the J2C Ant scripts, you can reliably regenerate the data binding beans, knowing that the same options will be applied as were used the first time you stepped through the J2C Wizards.
  • Repeatability: Human mistakes are unavoidable. Selecting one wrong option in the GUI may cause the whole application to fail. In addition, it is not always easy to debug, especially when some of those options are not explicitly shown in the generated artifacts. With the use of Ant script, every option is spelled out explicitly in the file. If you have a large number of similar native structures, you can replicate the code generation to use the exact same options for each structure simply by updating a few fields in the Ant file.
  • Maintainability: It is easier to apply source control to the Ant scripts than to the generated artifacts, or to the documented process to generate the application.

Requirements

This article assumes that you have Rational Application Developer V7.0 with J2EE Connector (J2C) Tools installed. The sample Ant scripts included in this article were created using these J2C Tools.

This article also assumes that you have used the J2C Tools in a previous version of Rational Application Developer (for instance, version 6) to generate the J2C Beans and Data Binding files. The focus of this article is on the Ant features support and will not cover the details usage of the J2EE connector Tools.

Rational Application Developer J2C session recording

In the J2C Tools in Rational Application Developer V7.0, one of the new features is the ability to record a wizard session. It enables you to go through the wizard once and record the user options and data in an Ant script file.

There are two wizards where the Ant script generation is supported.

  • CICS IMS Data Binding wizard: The Ant script will generate one or more data binding files.
  • J2C Java Bean wizard: The Ant script will generate J2C beans, import resource adapters as well as data binding files.

Ant generation in CICS IMS data binding

The CICS IMS Data Binding wizard allows you to generate data binding files based on the cobol, C or PL/1 source. When you go through the wizard, you have to select different options in the wizard before you can generate the data binding files. The Ant script support will save all the settings in the data binding Ant script file.

Figure 1 shows you how to launch the CICS IMS Data Binding wizard.

  1. Select File > New > Other.
  2. Select J2C > CICS IMS data Binding.

Figure 1. CICS IMS Data Binding wizard
choosing the wizard from an explorer view
  1. Click Next in the CICS IMS Data Binding wizard to launch the Data Import page.
  2. Choose COBOL to Java, C to Java or PL1 to Java mapping.
  3. Select the cobol, PL1, or C source file.
  4. Click Next to launch the Importer page.
  5. Select the importer settings and the data structure to be imported.
  6. Click Next to launch the Saving Properties Page shown in Figure 2.

Figure 2. CICS IMS Data Binding Wizard Ant Support
selecting options and saving the session as an Ant script

In the Saving Properties page, specify the name of your data binding file, as well as the project name and package name of where it will be generated. Different generation styles can be selected as well.

You will select the Save session as Ant script checkbox to use the Ant script feature. The default Data Binding Ant Script file name is the name of the Data binding class name. The default location of Ant script will be the current Project where the Data Binding is generated. You can change the name and location for the Ant script generation.

The Save All Settings option is useful if you would like to generate the values for all the settings when you go through the wizard. In this way, it is like you have generated a template for all the properties. If you do not select the Save All Settings option, only the option that you modify or enter when you go through the CICS IMS Data Binding wizard will be generated. For example, the default value for Generation Style is Default. The Generation Style will be generated in the Ant script only if you select another style like Shorten names.

Figure 3 shows the Ant support in the Multiple Possible Output (MPO) case for Saving Properties page of CICS IMS Data Binding wizard.

For the MPO case, the steps to launch the CICS IMS Data Binding wizard and to go to the Saving Properties page are very similar to those above. The only difference is you will choose COBOL MPO to Java , C MPO to Java or PL1 MPO to Java when you're mapping in the Data Import page.

Steps to go to the Saving Properties page for the MPO case.

  1. Click Next in the CICS IMS Data Binding wizard to launch the Data Import page.
  2. Choose COBOL MPO to Java mapping and select the cobol, PL1 or C source file.
  3. Click Next to launch the Importer page.
  4. Select the importer settings and the list of data structures to be imported.
  5. Click Next to launch the Saving Properties Page shown in Figure 3.

Note: The information for Save session as Ant script and Save All Settings are the same as described in the previous non-MPO case.


Figure 3. CICS IMS Data Binding Wizard (MPO Case) Ant support
options and settings for the MPO case

Ant generation in J2C Java Bean wizard

The J2C Java Bean wizard creates a bean that communicates with an Enterprise Information System. Figure 4 shows where the J2C Java Bean wizard is under the J2C folder.

To find the J2C Java Bean wizard shown in Figure 4:

  1. Select File > New > Other.
  2. Select J2C > J2C Java Bean wizard.

Figure 4. J2C Java Bean Wizard
selecting the wizard from an explorer tree

Figure 5 shows the Save session as Ant Script support in the J2C Java Bean Output Properties page. To go to this page:

  1. Select J2C Java Bean wizard and click Next.
  2. In the Resource Adapter Selection page, select the resource adapter and click Next.
  3. The Connection Properties page launches. Enter the connection information and click Next.
  4. You will now go to the J2C Java Bean Output Properties page.

Figure 5. J2C Java Bean Output Properties page
options, including the filename for the Ant script

In the J2C Java Bean Output Properties page, specify the name of your J2C Java Bean Interface and Implementation file, as well as the project name and package name of where they will be generated.

Select the Save session as Ant script checkbox to use the Ant script feature.

The default J2C Java Bean Ant Script file name is the name of the J2C Java Bean interface. The default location of the Ant script will be the current Project where the J2C bean is generated. You can change the name and location for the Ant script generation. The Save All Settings option is useful if you would like to generate the values for all the settings when you go through the wizard. This is a good way to capture for informational purposes all of the values that were used, and it makes it easier for you to change a particular value in the future. If you do not select the Save All Settings option, only the option that you modify or enter when you go through the J2C Java Bean wizard will be generated.

After you select the Save session as Ant script option, click Next to continue to other pages of the wizard to create the rest.


J2C Ant scripts overview

Layout of data binding Ant script

The following describes the Ant file (shown in Listing 1) that is generated as a result of CICS/IMS Data Binding session recording.

The generated data binding script is composed of targets, tasks, types and properties. To find out more about how Ant works, go to http://Ant.apache.org/manual/.

The script has one custom task, discover. The rest of the tags are custom types. Data discovery occurs in two distinct steps, which can be easily identified in the sample script with the performImport and writeToWorkspace complex elements (Ant custom types).

Both custom types contain the necessary data required for language (COBOL, PL1, or C) file import and (data binding bean) artifact generation.

The import and generation is performed internally, using a Discovery Agent and a Workspace Resource Writer respectively. Depending on the imported language and generated artifact type, you can use various implementations. Each implementation is identified by its ID (javax.xml.namespace.QName). COBOL, C, and PL/1 are some examples of files for which an agent implementation exists. In this example, the imported type is COBOL, so the Discovery Agent with the ID of {com/ibm/adapter}CobolDiscoveryAgent is used. The same logic applies for writers as well.

The import and write data is stored using custom property types like propertyElement and propertyGroup. This is the format the agents and writer can handle.

Note that at the end of the script, we have done a refreshLocal and incrementalBuild. This is to allow the Annotation builder to regenerate the code in method body based on all the doclet Tags in the J2C bean and data binding file, and to synchronize the project.


Listing 1. Sample code for a data binding Ant script
 

<project xmlns:adapter="http://com.ibm.adapter" 
default="DataBinding1" name="/myTaderc99/DFHCOMMAREA.xml">
    <property name="debug" value="true"/>
    <property name="project1" value="myTaderc99"/>
    <target name="DataBinding1">
        <adapter:discover>
            <adapter:performImport agent="{com/ibm/adapter}CobolDiscoveryAgent">
                <adapter:importResource>
                    <adapter:propertyGroup name="CobolFileGroup">
                        <adapter:propertyElement name="CobolFile" value="D:\taderc99.cbl"/>
                    </adapter:propertyGroup>
                </adapter:importResource>
                <adapter:queryProperties>
                    <adapter:propertyGroup name="ImportProperties">
                        <adapter:propertyElement name="Platform" value="Win32"/>
                    </adapter:propertyGroup>
                </adapter:queryProperties>
                <adapter:queryResult>
                    <adapter:selectElement name="DFHCOMMAREA"/>
                </adapter:queryResult>
            </adapter:performImport>
            <adapter:writeToWorkspace writer="{com/ibm/adapter/cobol/writer}JAVA_WRITER">
                <adapter:propertyGroup name="COBOLToJavaResourceWriter">
                    <adapter:propertyElement name="GenerationStyle" value="Default"/>
                    <adapter:propertyGroup name="Java Type Name">
                        <adapter:propertyElement name="Project Name" value="${project1}"/>
                        <adapter:propertyElement name="Package Name" value="test.data"/>
                        <adapter:propertyElement name="Class Name" value="DFHCOMMAREA"/>
                    </adapter:propertyGroup>
                </adapter:propertyGroup>
            </adapter:writeToWorkspace>
        </adapter:discover>
       <eclipse.refreshLocal depth="infinite" resource="${project1}"/>
        <eclipse.incrementalBuild project="${project1}"/>
    </target>
   </project>
   

Layout of J2C service Ant script

The following sample (shown in Listing 2) describes the J2C bean generation portion of the Ant file generated as a result of J2C Java Bean session recording.

The script is organized into different targets that depend on each other. The different targets will be executed sequentially according to the dependency.

The script has one task, generateService. The two distinct sections are buildService and writeToWorkspace. The first section is different from the previous example, since the service is being built, not discovered. It assumes that the DFHCOMMAREA.java file exists under the Test2 project and the test.data package.

The second section is identical to the writeToWorkspace from CICS/IMS Data Binding, with the difference in the values being used.

Among the described tasks, the Ant file contains two additional helper tasks. The createProject task, as its name implies, it is used for project creation. The importResourceAdapter task is used for importing resource adapter and creating a connector project cicseci602.


Listing 2. Sample code for J2C Java Bean Ant Script
 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:adapter="http://com.ibm.adapter" xmlns:j2c="http://com.ibm.adapter.j2c" default="J2CBeanGeneration1" name="/Test2/Customer.xml">
    <target name="Init1">
        <property name="debug" value="true"/>
        <property name="project1" value="Test2"/>
        <property name="ra.project" value="cicseci602"/>
        <property name="ra.runtime" value="WebSphere Application Server v6.1"/>
        <property name="ra.file" value="D:\Program Files\IBM\SDP70\ResourceAdapters\cics15\cicseci602.rar"/>
    </target>
    <target depends="Init1" name="DataBinding1">
        <adapter:createProject projectName="${project1}" projectType="Java"/>
        <eclipse.refreshLocal depth="infinite" resource="${project1}"/>
        <eclipse.incrementalBuild project="${project1}"/>
    </target>
    <target depends="DataBinding1" name="importResourceAdapter1">
        <j2c:importResourceAdapter addToEAR="no" connectorFile="${ra.file}" connectorModule="${ra.project}" targetRuntime="${ra.runtime}"/>
    </target>
    <target depends="importResourceAdapter1" name="J2CBeanGeneration1">
        <adapter:createProject projectName="${project1}" projectType="Java"/>
        <j2c:generateService>
            <j2c:buildService class="Customer" package="sample.test">
                <j2c:method>
                    <j2c:methodName value="getCustomerInfo"/>
                    <j2c:methodInput value="/Test2/test/data/DFHCOMMAREA.java"/>
                    <j2c:methodOutput value="/Test2/test/data/DFHCOMMAREA.java"/>
                    <j2c:interactionSpec class="com.ibm.connector2.cics.ECIInteractionSpec">
                        <adapter:propertyGroup name="InteractionSpec property group">
                            <adapter:propertyElement name="functionName" value="taderc99"/>
                            <adapter:propertyElement name="commareaLength" value="-1"/>
                            <adapter:propertyElement name="replyLength" value="-1"/>
                            <adapter:propertyElement name="executeTimeout" value="0"/>
                            <adapter:propertyElement name="interactionVerb" value="1"/>
                        </adapter:propertyGroup>
                    </j2c:interactionSpec>
                </j2c:method>
                <j2c:managedConnectionFactory class="com.ibm.connector2.cics.ECIManagedConnectionFactory" target="MyDefaultJNDIName">
                    <adapter:propertyGroup name="Managed connection property group">
                        <adapter:propertyGroup name="Server">
                            <adapter:propertyElement name="ConnectionURL" value="rubicon"/>
                            <adapter:propertyElement name="ServerName" value="rubicon"/>
                        </adapter:propertyGroup>
                        <adapter:propertyGroup name="UserVerification">
                            <adapter:propertyElement name="UserName" value="sysad"/>
                            <adapter:propertyElement name="Password" value="2006"/>
                        </adapter:propertyGroup>
                        <adapter:propertyGroup name="Security"/>
                    </adapter:propertyGroup>
                </j2c:managedConnectionFactory>
                <j2c:connectionSpec class="com.ibm.connector2.cics.ECIConnectionSpec"/>
                <j2c:resourceAdapter project="${ra.project}"/>
            </j2c:buildService>
            <adapter:writeToWorkspace writer="{com/ibm/adapter/j2c/codegen}J2CAnnotationWriter">
                <adapter:propertyGroup name="J2C Writer Properties">
                    <adapter:propertyElement name="Project" value="${project1}"/>
                    <adapter:propertyElement name="PackageName" value="sample.test"/>
                    <adapter:propertyElement name="InterfaceName" value="Customer"/>
                </adapter:propertyGroup>
            </adapter:writeToWorkspace>
        </j2c:generateService>
        <eclipse.refreshLocal depth="infinite" resource="${project1}"/>
        <eclipse.incrementalBuild project="${project1}"/>
    </target>
</project>

Predefined variables

The generated script also contains predefined Ant properties like debug and project1. These Ant properties can be used as variables within the script. When a value repeats itself in multiple places within the Ant file, defining it as a variable has one big advantege: you only have to modify its value in one place, and the change will reflect throught the whole script. The debug property will surpress the console output if set to false

Multiple targets

Since Ant allows multiple targets to be defined in one file, you can modify the file content and combine two or more files into one.

Repeatability

You can also use the generated file as a template for further artifact generation. For instance, if you change the COBOL file, the import properties, and the target class name, you can generate new data binding without going through the wizard.


Customization

In order to customize the J2C Ant scripts, you need to know the following:

  • What property to change
  • What property value to set
  • Where can you find the lists of valid property values

Some of the properties can be easily identified from the J2C UI, and you can view the list of possible values in a drop-down list.

Customize data binding Ant script

Change project type

There are three project types that you can set:

  • Java
  • Web
  • EJB™ (Enterprise JavaBeans™ technology)

The Web and EJB projects require the runtimeName to be specified. The runtimeName is a string that you can determine from the Rational Application Developer server runtime value.

  1. From the main menu, select Windows > Preference > Server > Installed runtime.

The code snippet shown in Listing 3 shows you how to create a Java project named MyTaderc99.


Listing 3. Sample code for Java project type
        

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:adapter="http://com.ibm.adapter" default="DataBinding1" 
    name="/MyTaderc99/DFHCOMMAREA.xml">
    <property name="debug" value="true"/>
    <property name="project1" value="MyTaderc99"/>
    <target name="DataBinding1">
        <adapter:createProject projectName="${project1}" projectType="Java"/>

      

The code snippet shown in Listing 4 shows how to create a Web project.

  1. In addition to the projectType, you need to specify the runtimeName.

Listing 4. Sample code for Web project type
        

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:adapter="http://com.ibm.adapter" default="DataBinding1" 
    name="/MyTaderc99/DFHCOMMAREA.xml">
    <property name="debug" value="true"/>
    <property name="project1" value="MyTaderc99"/>
    <target name="DataBinding1">
        <adapter:createProject projectName="${project1}"
  projectType="Web" runtimeName="WebSphere Application Server v6.0"/>
     

If add To EAR is specified when you create the Web project, you need to specify the EARProjectName and addToEAR option besides the runtimeName.

     <adapter:createProject EARProjectName="MyWebEAR" addToEAR="yes"
    projectName="${project1}" projectType="Web" runtimeName=
    "WebSphere Application Server v6.0"/>   
 

The code snippet shown in Listing 5 shows how to create an EJB project.

  1. In addition to the projectType, you need to specify the runtimeName.

Listing 5. Sample code for EJB project type
  

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:adapter="http://com.ibm.adapter" default="DataBinding1" 
    name="/MyTaderc99/DFHCOMMAREA.xml">
    <property name="debug" value="true"/>
    <property name="project1" value="MyTaderc99"/>
    <target name="DataBinding1">
        <adapter:createProject projectName="${project1}" 
    projectType="EJB" runtimeName="WebSphere Application Server v6.0"/>

if add To EAR is specified when you create the EJB Project, you need to specify the EARProjectName and addToEAR option besides the runtimeName.

     <adapter:createProject EARProjectName="MyEJBEAR" addToEAR="yes"
    projectName="${project1}" projectType="EJB" runtimeName=
    "WebSphere Application Server v6.0"/>   
      

Change Generation Style

The Generation Style (Listing 6) is located in the Saving Properties page. The default value is Default.


Listing 6. Generation Style: Ant
  

      <adapter:writeToWorkspace writer="{com/ibm/adapter/cobol/writer}JAVA_WRITER">>
         <adapter:propertyGroup name="COBOLToJavaResourceWriter">
            <adapter:propertyElement name="GenerationStyle" value="Default"/>
  

The possible property values are the same as for the Data Binding wizard, as shown in Figure 6.


Figure 6. Generation Style-UI
the Saving Properties page, showing the style options

If you select Preserve case of names, then the portion of code in the Ant script will look like that shown in Listing 7.


Listing 7. Another Generation Style for Ant
  

      <adapter:writeToWorkspace writer="{com/ibm/adapter/cobol/writer}JAVA_WRITER">>
         <adapter:propertyGroup name="COBOLToJavaResourceWriter">
            <adapter:propertyElement name="GenerationStyle" value="Preserve case of names"/>

  

Customize J2C Java Bean Ant script

Change connector project

In Listing 8 following, the property ra.project is initialized to cicseci602. This is the connector module that is created during importResourceAdapter Ant task. You can easily modify the name of the connector Module by specifying a different name.


Listing 8. Connector Project Name change
       
     <project xmlns:adapter="http://com.ibm.adapter" xmlns:j2c=
     "http://com.ibm.adapter.j2c" 
     default="J2CBeanGeneration1" name="/MyTaderc99/Customer.xml">
     <target name="Init1">
        <property name="debug" value="true"/>
        <property name="project1" value="MyTaderc99"/>
        <property name="ra.project" value="cicseci602"/>
        <property name="ra.runtime" value="WebSphere Application Server v6.0"/>
        <property name="ra.file" value=
        "D:\RAD0629\ResourceAdapters\cics15\cicseci602.rar"/>
     </target>
       

Change Resource Adapter location

In Listing 9 following, the property ra.file specified where the Resource Adapter file is located. If you want to use the Ant script to import another resource adapter, you simply change the value of the ra.file.


Listing 9. Resource Adapter location
       
     <project xmlns:adapter="http://com.ibm.adapter" xmlns:j2c=
     "http://com.ibm.adapter.j2c" 
     default="J2CBeanGeneration1" name="/MyTaderc99/Customer.xml">
     <target name="Init1">
        <property name="debug" value="true"/>
        <property name="project1" value="MyTaderc99"/>
        <property name="ra.project" value="cicseci602"/>
        <property name="ra.runtime" value="WebSphere Application Server v6.0"/>
        <property name="ra.file" value="D:\RAD0629\ResourceAdapters\cics15\cicseci602.rar"/>
     </target>
       

Change connection information for managed connection

Listing 10 shows the connection information portion in the J2C Java Bean Ant script.

You can change connection information like ConnectionURL, ServerName, UserName, Password

You can also set your TraceLevel for debugging.


Listing 10. Connection information
       

<j2c:managedConnectionFactory class=
"com.ibm.connector2.cics.ECIManagedConnectionFactory" target=
"MyDefaultJNDIName">
 <adapter:propertyGroup name="Managed connection property group">
 <adapter:propertyGroup name="Server">
<adapter:propertyElement name="ConnectionURL" value="cheat" />
<adapter:propertyElement name="ServerName" value="cheat" />
</adapter:propertyGroup>
 <adapter:propertyGroup name="UserVerification">
<adapter:propertyElement name="UserName" value="sysad" />
<adapter:propertyElement name="Password" value="sysad" />
</adapter:propertyGroup> 
<adapter:propertyElement name="TraceLevel" value="3" />
<adapter:propertyGroup name="Security" />
</adapter:propertyGroup>
</j2c:managedConnectionFactory>

Figure 7 shows the Connection Properties page in the J2C Java Bean wizard.

The managed connection information and TraceLevel in the above Ant script (Listing 10) are captured from the Connection Properties page of the J2C Java Bean wizard.


Figure 7. Connection Properties page
non-managed connection properties vary by resource adaptor type

Import properties

Figure 8 shows the import Properties portion of the J2C Ant script.

The information is captured from the Importer page of the J2C Java Bean wizard, as well as the CICS IMS Data Binding wizard.


Figure 8. Import properties in Ant script
screen capture of import properties in Customer.xml

Figure 9 shows that the importer properties are located in the Importer page of J2C wizards.


Figure 9. Import properties in Importer page in J2C wizards
import options values

Interaction properties

Figure 10 shows InteractionSpec properties in the Ant script from generated from the J2C Java Bean Ant script.


Figure 10. InteractionSpec properties in Ant Script
InteractionSpec properties shown in the Customer.xml file

Figure 11 shows where the InteractionSpec properties are located in the J2C Java Bean wizard. They are located in the Java Method page of the J2C Java Bean wizard. Some of the properties can be seen when you select the Show Advanced button.


Figure 11. InteractionSpec properties in J2C Java Bean wizard
Advanced pane expanded in the Java Method page

Some of the properties are implicit and do not show up in the J2C UI. One example is the discovery Agent ID.

You will not see any of the agent name "{com/ibm/adapter}CobolDiscoveryAgent" in the UI. However, if you select the language mapping to be COBOL to JAVA or MPO COBOL to Java, then you will see the agent name generated in the Ant script.

Listing 11 shows the agent name when you select COBOL_TO_JAVA or COBOL_MPO_TO_JAVA mapping.


Listing 11. Sample code COBOL showing Discovery Agent
     
        <adapter:discover>
            <adapter:performImport agent="{com/ibm/adapter}CobolDiscoveryAgent">
                <adapter:importResource>
                    <adapter:propertyGroup name="CobolFileGroup">
                        <adapter:propertyElement name="CobolFile" value=
                        "D:\taderc99.cbl"/>
                    </adapter:propertyGroup>
   

Listing 12 shows the agent name when you select C_TO_JAVA or C_MPO_TO_JAVA mapping.


Listing 12. Sample code C showing Discovery Agent
     
        <adapter:discover>
            <adapter:performImport agent="{com/ibm/adapter}CDiscoveryAgent">
                <adapter:importResource>
                    <adapter:propertyGroup name="CFileGroup">
                        <adapter:propertyElement name="CFile" value="D:\taderc99.cpp"/>
                    </adapter:propertyGroup>
   

Listing 13 shows the agent name when you select PL1_TO_JAVA or PL1_MPO_TO_JAVA mapping.


Listing 13. Sample code PL/I showing Discovery Agent
     
       <adapter:discover>
            <adapter:performImport agent="{com/ibm/adapter}PliDiscoveryAgent">
                <adapter:importResource>
                    <adapter:propertyGroup name="PliFileGroup">
                        <adapter:propertyElement name="PliFile" value="D:\taderc99.pli"/>
                    </adapter:propertyGroup>


   

Figure 12 shows where you can find the different mappings from the J2C Java Bean or CICS IMS Data Binding wizard. When you select the different mappings, the agent name generated in the Ant script file will also be different, as shown in the previous three Ant script listings.


Figure 12. Choose mapping
specifying data import configuration properties

Run J2C Ant scripts in command line

The generated J2C Ant scripts can be executed without launching the eclipse workbench. Once generated or modified, you can execute a script from the Microsoft® Windows® command line without bringing up the IDE. Running Rational Application Developer in this way is called headless mode. To run the Ant script, invoke the antRunner application passing the Ant file as argument. A simple batch file for running the generated Ant scripts in headless mode is shown in Figure 14, following:


Listing 14. Sample Test.bat
    

echo off
setlocal

set ECLIPSE="D:\Program Files\IBM\SDP70"
set WORKSPACE=D:\MyWorkspaceANT
set BUILDFILE=D:\Customer.xml

set JAVA_HOME=%ECLIPSE%\jdk
set PATH=%JAVA_HOME%\bin;%PATH%
set CLASSPATH=%JAVA_HOME%\lib;%CLASSPATH%


java -cp %ECLIPSE%\startup.jar org.eclipse.core.launcher.Main -clean -data %WORKSPACE% 
 -application org.eclipse.Ant.core.antRunner -buildfile %BUILDFILE%

Where:
    ECLIPSE environment variable defines the path to the eclipse folder within RAD
    WORKSPACE defines the path where the workspace will be created
    BUILDFILE is the path to your generated Ant script you would like to run.



To run the Ant file generated from the CICS/IMS Data Binding session, modify the values of the following variables in the Test.bat batch file to fit your environment.

  • Replace the value for ECLIPSE with your eclipse root directory (where eclipse.exe is located)
  • Replace the value for WORKSPACE with the workspace name and location
  • Replace the value for BUILDFILE with your J2C Ant script

If the debug property is set to True, you should see progress messages and a BUILD SUCCESSFUL message at the end. You can also browse to the target workspace to see the generated files.

Running Data Binding AntScript from Command Line

You can invoke Test.bat from the command line, as shown in Figure 13.


Figure 13. Invoking Test.bat for DataBinding.xml from Command Line
Run Test.bat to generate DataBinding from Command Line

After the Test.bat completes sucessfully, you can bring up your workspace and all the project and data binding files are created, as shown in Figure 14.


Figure 14. Data bindings are generated
data binding beans are generated

Running a J2C Java Bean AntScript from the command line

To generate a CICS service, you must specify a server runtime in the workspace. The server runtime is used by the importResourceAdapter task to create a connector project. Once the server runtime is set, modify the BUILDFILE variable in the batch file, and point to the Ant file generated based on the J2C Java Bean session. Rerun the batch file. If the build is successful, the generated service files can be observed in the target workspace.

To make sure the server runtime had been specified, you can bring up a workspace by selecting Windows > Preference > Server > Installed Runtimes.

Figure 15 shows where the Installed Runtimes are located.


Figure 15. Setting up server runtime
viewing the installed server runtime environments

Figure 16 shows how you invoke the Ant script via the Test.bat in a command window.


Figure 16. Invoking Test.bat for J2C Java Beans generated
J2C Java Bean Ant script execution

After the Test.bat is completed sucessfully, you can bring up your workspace and find that all the projects and artifacts are created. In Figure 17 below, you will see the project myTaderc99 has been created with a data binding file DFHCOMMAREA.java.


Figure 17. Java Projects with J2C Java Beans and data bindings are generated
J2C Java Beans generated

Migration

In J2C V6011/V6012, sample Ant scripts are provided to generate a service or data binding files. They are not generated automatically, so you need to make modifications manually to ensure that the scripts work.

In Rational Application Developer V7.0, the J2C session recording features generates Ant scripts automatically. A migration tool is provided to convert the V601.x Ant scripts into the new Ant scripts format. The new Ant scripts are more flexible and easier to use.

How to run the <j2c:migrate> task

Migration xml (shown in Listing 15) is an Ant build file that executes the <j2c:migrate> task with the given V6.0.1.x Ant script.

  1. In your code, replace value for source with the V6.1.x old Ant script file that you want to migrate.
  2. Execute the migration.xml either inside Rational Developer Application V7, or use headless mode to run it on a command line.

Listing 15. Migration.xml
        


<?xml version="1.0" encoding="UTF-8"?>
<project name="Migration" default="default" xmlns:j2c="http://com.ibm.adapter.j2c">
	<-- 
		The source file path must be either a workspace relative or a full file system path.
		The original file (source) will be renamed with the .bak extension.
	 -->
 	<target name="default">
		<j2c:migrate source="c:/Script/v6antscript.xml"/>
	</target>
</project>


Tips

Portable Ant scripts

A typical use case of Ant scripts is to use them in a regular repeatable build. The build machine is normally different from the machine that was used to create the original Ant script. The best way to ensure portability is to use Ant variables to factor out the machine-specific information in the script. The keys to watch out for in the J2C Ant scripts are the path of the cobol source file, the server runtime location, and the location of the Resource Adapter. These should have variables map to the location in the execution environment.

Data Binding Ant script

  • In the Data Binding Ant Script, the project1 variable defined. You can modify the value for the project where the data binding files are generated. The Package Name, on the other hand, is a hard-coded value. You can extend it by defining a variable name.
           
    <property name="package1" value="test.data"/> 
    ...
    

    Then, in the write to workspace, you will reference the package variable instead.
    <adapter:propertyElement name="Project Name" value="${project1}" />
    <adapter:propertyElement name="Package Name" value=${package1}" />
    <adapter:propertyElement name="Class Name" value="DFHCOMMAREA" /> 
    

  • If you intend to integrate the Ant script into your build process, the location of the COBOL Source file can also be defined into a variable.
           
    <property name="COBOLFileSrc" value="="D:\taderc99.cbl""/> 
    ...
    <adapter:propertyGroup name="CobolFileGroup">
       <adapter:propertyElement name="CobolFile" value="${COBOLFileSrc}" />
    </adapter:propertyGroup>
    

J2C Java Bean Ant script

In the J2C Java Bean Ant script, the input and output data binding files used for the methods are defined. You can extend them by creating an input and output variable, and then use them in the script.

      <property name="InputDBFile" value="/Taderc99/sample/cics/data/DFHCOMMAREA.java" /> 
      <property name="OuputDBFile" value="/Taderc99/sample/cics/data/DFHCOMMAREA.java" /> 

<j2c:methodName value="getCustomerInfo" />
<j2c:methodInput value="${InputDBFile}" />
<j2c:methodOutput value=="${InputDBFile}"  />

<property name="package1" value="test.data"/> 
...

Cannot locate RAR

If you already have the connector project created in your workspace for a particular Resource Adapter, when you go through the J2C Java Bean wizard, the Resource Adapter will not be imported again. When you generate the Ant script, you have no way of figuring out the location of the resource adapter, because the connector project does not provide such information.

If the ra.file value equals cannotlocaterar, as shown in Figure 18, then you will need to add the Resource Adapter location yourself manually. This is a known limitation.


Figure 18. cannotlocaterar value for ra.file
cannot locate rar value in Customer.xml

Benefits

This article has shown you how to use Ant scripts with Rational Application Developer to gain the benefits of flexibility, repeatability, and maintainability.



Downloads

DescriptionNameSizeDownload method
Batch file for invoking J2C Ant script test.zip1KB HTTP
Data Binding Ant ScriptDataBinding.zip1KB HTTP
Migration Ant task migration.zip1KB HTTP
Viewlet J2C_Session_Recording.zip2472KBHTTP

Information about download methods


Resources

Learn

Get products and technologies

Discuss

About the authors

Ivy Ho

Ivy is currently working on the Java Connector Tooling team in the Rational area. She obtained Project Management Professional (PMP) certification in 2005. She received an honors degree in Mathematics (major in Computer Science and minor in Statistics) from the University of Waterloo.

Laszlo Benedek

Laszlo is currently working on the Adapter Tooling team in the IBM WebSphere area. He has a University and a Master's degree in Computer Science.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational, Web development
ArticleID=177596
ArticleTitle=Working with J2C Ant Scripts in Rational Application Developer V7
publish-date=12052006
author1-email=ivyho@ca.ibm.com
author1-email-cc=
author2-email=lbenedek@ca.ibm.com
author2-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers