how to use jbi ant tasks in your own ant environment?
asant wrapper in Glassfish V2 with Open ESB 2.0 sets all the
environment required for appserver and OpenESB for you to
execute OpenESB administrative Ant scripts within the Ant environment
configured for Glassfish V2. But, do you know you can also run
OpenESB Ant scripts from any Ant environment
that you may be using for building and testing your jbi components and
service assemblies?. It is not required to use asant wrapper to run
OpenESB Ant scripts if you do the required setup in your OpenESB Ant scripts.
The following are few steps that you can add to your Ant scripts
which uses jbi ant tasks to run in any Ant environment.
1. Setup classpath required for
running jbi ant tasks
OpenESB2.0 jbi ant tasks require sun-appserv-ant.jar and
jbi-ant-tasks.jar jar files in Ant classpath to load jbi ant tasks
implementation and its dependencies. It is important to use these jar
files from the same location where they were
installed in GlassFish as these two jar files
depend on the other Glassfish/OpenESB library jar files relative
to
their installation directory in the Glassfish installation.
You can add the following ant script snippet to your ant script to define
jbi ant tasks classpath in glassfish
<property name="glassfish.home" location="D:/Sun/gfv2/glassfish" />
<path id="jbi.ant.tasks.classpath.id"> <pathelement location="${glassfish.home}/lib/sun-appserv-ant.jar"/> <pathelement location="${glassfish.home}/jbi/lib/jbi-ant-tasks.jar"/> </path>
|
2. Load jbi ant task definitions.
jbi-ant-tasks.jar has a antlib xml resource file at
com/sun/jbi/ui/ant/antlib.xml that defines jbi ant task
definitions. So, in your ant script, you can use this antlib xml file
as a resource to load jbi ant tasks implementation. Make sure that you have setup
correct jbi ant tasks classpath in the taskdef task to load jbi
ant tasks from antlib xml. You can use classpathref
attribute in taskdef task to set classpath defined with path id
jbi.ant.tasks.classpath.id defined above. Use the following ant script snippet
<taskdef resource="com/sun/jbi/ui/ant/antlib.xml" classpathref="jbi.ant.tasks.classpath.id"/>
|
3. Use jbi ant tasks in ant
target
After jbi ant tasks are loaded into the Ant environment with the
setup mentioned above, you can call any jbi ant task in your ant script
target. For example, you can use the follows Ant script snippet
to install and start a jbi component.
<target name="install" > <jbi-install-component host="localhost" port="4848" username="admin" password="adminadmin" file="/path/to/my-jbi-component.jar"/> <jbi-start-component host="localhost" port="4848" username="admin" password="adminadmin" name="MyJBIComponent" /> </target>
|
Download and View
I have created a
simple build script that
uses jbi ant tasks to build and install jbi component to
OpenESB. I have used the same build script in a Netbeans or Eclipse
based Ant project system to run ant script from Netbeans or Eclipse
IDE. You can download
JbiBuildProject.zip
zip file that has the Project system that works in Netbeans IDE or
Eclipse. Check out this
demo
video to see the project in action.
Note1: Please set glassfish.home property in
JbiBuildProject/build.xml to your glassfish installation
directory before building JbiBuildProject.
Note2: Please make sure that you have started glassfish before you
invoke jbi ant tasks from the ant script.
How to build/run the JbiBuildProject
From Netbeans IDE:
1. install and configure glassfish v2 in Netbeans IDE
2. start the glassfish from the Runtime tab of the Netbeans IDE
3. unzip JbiBuildProject.zip
4. open JbiBuildProject from Open Project action
5. edit
build.xml in the JbiBuildProject to set the correct glassfish.home
6. invoke Run Project Action from the Project node of the Jbi Build
Project
7. see the output in ant output window
8. check that the MyJBIComponent is shown in the JBI node of the
glassfish from the Runtime Tab of the IDE.
From Eclipse 3.2.1 :
1. install and start glassfish v2 from command line
2. unzip JbiBuildProject.zip
3. open JbiBuildProject by importing the project to your eclipse workspace
4. edit
build.xml in the JbiBuildProject to set the correct glassfish.home
5. run the project from build.xml.
From Command line:
1. install and start glassfish v2 from command line
2. download the
JbiBuildProject.zip
3. unzip
JbiBuildProject.zip to any directory. For example /test
4. cd
/test/JbiBuildProject
5. edit
build.xml to set the correct glassfish.home
6. run
ant which picks up the build.xml in the JbiBuildProject directory as
its default build script
Here is the build script that is used
in the project.
<?xml version="1.0" encoding="UTF-8"?>
<project name="JBI Build Project" default="run" basedir=".">
<description> This project demonstrates the JBI Ant tasks usage in OpenESB2.0 </description>
<property name="glassfish.home" location="D:/Sun/gfv2/glassfish" />
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="-init-jbi-ant-tasks" description="initializes jbi tasks ">
<available file="${glassfish.home}" property="glassfish.home.exists" />
<fail unless="glassfish.home.exists"
message="glassfish.home=${glassfish.home} is not valid. Please set a valid glassfish home." />
<path id="jbi.ant.tasks.classpath.id">
<pathelement location="${glassfish.home}/lib/sun-appserv-ant.jar"/>
<pathelement location="${glassfish.home}/jbi/lib/jbi-ant-tasks.jar"/>
</path>
<taskdef resource="com/sun/jbi/ui/ant/antlib.xml" classpathref="jbi.ant.tasks.classpath.id"/>
<property name="jbi.host" value="localhost" />
<property name="jbi.port" value="4848" />
<property name="jbi.username" value="admin" />
<property name="jbi.password" value="adminadmin" />
<property name="jbi.install.file" location="${dist}/MyJBIComponent.jar" />
<property name="jbi.component.name" value="MyJBIComponent" />
</target>
<target name="install" depends="-init-jbi-ant-tasks, dist" >
<jbi-install-component
host="${jbi.host}" port="${jbi.port}" username="${jbi.username}" password="${jbi.password}"
file="${jbi.install.file}"/>
<jbi-start-component
host="${jbi.host}" port="${jbi.port}" username="${jbi.username}" password="${jbi.password}"
name="${jbi.component.name}" failOnError="false" />
</target>
<target name="uninstall" depends="-init-jbi-ant-tasks, dist" >
<jbi-stop-component
host="${jbi.host}" port="${jbi.port}" username="${jbi.username}" password="${jbi.password}"
name="${jbi.component.name}" failOnError="false" />
<jbi-shut-down-component
host="${jbi.host}" port="${jbi.port}" username="${jbi.username}" password="${jbi.password}"
name="${jbi.component.name}" failOnError="false" />
<jbi-uninstall-component
host="${jbi.host}" port="${jbi.port}" username="${jbi.username}" password="${jbi.password}"
name="${jbi.component.name}"/>
</target>
<target name="list" depends="-init-jbi-ant-tasks" >
<jbi-list-service-engines
host="${jbi.host}" port="${jbi.port}" username="${jbi.username}" password="${jbi.password}"
serviceEngineName="${jbi.component.name}" />
</target>
<target name="init" depends="-init-jbi-ant-tasks">
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init" description="compile the source " >
<javac srcdir="${src}" destdir="${build}" classpath="${glassfish.home}/jbi/lib/jbi.jar"/>
<copy todir="${build}">
<fileset dir="${src}" excludes="**/*.java"/>
</copy>
</target>
<target name="dist" depends="compile" description="generate the jbi component zip file" >
<mkdir dir="${dist}"/>
<jar jarfile="${jbi.install.file}" basedir="${build}"/>
</target>
<target name="clean" description="clean up" >
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
<target name="run" depends="install, list" />
</project>
|