Running your Ant script

Once you have saved the settings for your J2C bean and your data binding classes in an Ant file, you can run this Ant script separately.

Before you begin

You must select Save settings in an Ant script in the J2C bean creation wizard.
Important: The Save session as Ant script option is not available for MFS-based applications.

Procedure

  1. Right-click the Ant file that you want to run, and select Run As > External Tools Configurations....
  2. In the launch attributes window, open the JRE tab and select Run in the same JRE as the Workspace. Click Apply and then Run.
    Note: You only need to set the JRE the first time you run the Ant script. When you run it the next time, simply right-click your Ant file and select Run As > 2 Ant Build

Example

Running your ant script from the command line

Once generated or modified, your Ant scripts can be executed without launching the IDE; this is called the Headless mode. To run the Ant script, you simply invoke the antRunner application, passing the Ant file as argument.

  1. Create a simple batch file, Test.bat, for running the generated Ant script in headless mode (or use the example in ../IBM/IBMIMShared/plugins/com.ibm.j2c.cheatsheet.content):
    echo off
    setlocal
    
    set ECLIPSE=d:\IBM\SDP75
    set WORKSPACE=d:\WorkspaceANT
    set BUILDFILE=d:\INPUTMSG.xml
    
    
    set JAVA_HOME=%ECLIPSE%\jdk\jre
    set PATH=%JAVA_HOME%\bin;%PATH%
    set CLASSPATH=%JAVA_HOME%\lib;%CLASSPATH%
    set EQUINOXJAR=%ECLIPSE%\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar
    
    java  -showversion -Xms50M -Xmx350M -XX:MaxPermSize=128m -cp "%EQUINOXJAR%" 
    
    org.eclipse.core.launcher.Main  -data %WORKSPACE%  -application org.eclipse.ant.core.antRunner -
    
    buildfile %BUILDFILE%

    Linux: Create a antgenerate.sh file (or use the example in ../IBM/IBMIMShared/plugins/com.ibm.j2c.cheatsheet.content):

    #!/bin/bash
    ECLIPSE="/opt/IBM/SDP/"
    WORKSPACE="/home/temp/workspace/ant"
    BUILDFILE="/home/temp/antscript/Customer.xml"
    JAVA_HOME="$ECLIPSE/jdk"
    JAVA="$JAVA_HOME/jre/bin/java"
    EQUINOXJAR="$ECLIPSE/plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar"
    
    PATH="$PATH:$JAVA_HOME/bin"
    export PATH
    CLASSPATH="$CLASSPATH:$JAVA_HOME/lib"
    export CLASSPATH
    "$JAVA" -cp "$EQUINOXJAR" org.eclipse.core.launcher.Main -os linux -ws gtk -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 is created
    • BUILDFILE is the path to your generated Ant script you would like to run.

    Make sure that the org.eclipse.equinox.launcher JAR file exists.

    You can modify the variables in the batch file to fit your environment:

    • Replace ECLIPSE with your eclipse root
    • Replace WORKSPACE with the workspace name and location
    • Replace BUILDFILE with your J2C Ant script
  2. Open a command window, and invoke Test.bat from the command line.
  3. After the Test.bat is completed successfully, you can open your workspace and all the project and data binding files are created.

What to do next

Known limitation of the Ant script: 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 is be imported again. When you generate the Ant script, the script has no way of figuring out the location of the resource adapter since the connector project does not provide such information. If the ra.file value equals cannotlocaterar, then you need to manually add the resource adapter location to the generated J2C Java bean ant script yourself. This is a known limitation. Your Ant file contains the line: property name="ra.file" value="Cannot Locate RAR "
<target name="Init1">
        <property name="debug" value="true"/>
        <property name="project1" value="Test"/>
        <property name="j2c.runtime" value="WebSphere Application Server v7.0"/>
        <property name="ra.project" value="cicseci7102"/>
        <property name="ra.runtime" value="WebSphere Application Server v7.0"/>
        <property name="ra.file" value="Cannot Locate RAR" />
    </target>
Known limitation of the Ant script: Cannot Locate RAR
If you run ant script from command line, and you need to import resource adapter into the workspace, you may get this error:
importResourceAdapter1: 
[j2c:importResourceAdapter] Creating connector project cicseci6022 ...done 

J2CBeanGeneration1: 
[j2c:generateService] Generate service: 
[j2c:generateService] Registry returned Resource Adapter descriptor: null 
[j2c:generateService] Wait for Resource Adapter registry processing ... 
[j2c:generateService] Done after 120 seconds. 
[j2c:generateService] Registry returned Resource Adapter descriptor: null 
[j2c:generateService] Could not retrieve a Resource Adapter for project: cicseci 
6022 
[j2c:generateService] Generate service ...failed 
BUILD SUCCESSFUL 
This is because the system times out during the resource adapter import.

Workarounds

Select one of these methods to resolve this problem:
  • Rerun the ant script on the command line, and the script runs successfully.
  • Create a workspace, create a resource adapter project, and import the resource adapter first, then run the ant script.

Feedback