Srinivasan Chikkala's Weblog
Archives
« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today
Click me to subscribe
Search

Links
 

Today's Page Hits: 17

« JBI ant tasks in... | Main | JBI Examples - Devel... »
Wednesday Mar 07, 2007
How to use JBI Ant tasks in your own Ant environment?
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
<!-- set the Glassfish home -->
<property name="glassfish.home" location="D:/Sun/gfv2/glassfish" />
<!-- define the jbi ant tasks classpath path -->
<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
<!-- Load jbi task definitions -->
<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" >
<!-- Install the component -->
<jbi-install-component host="localhost" port="4848" username="admin" password="adminadmin"
file="/path/to/my-jbi-component.jar"/>
<!-- Start the installed component -->
<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.

build.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved. -->
<project name="JBI Build Project" default="run" basedir=".">
  <description> This project demonstrates the JBI Ant tasks usage in OpenESB2.0 </description>
  
  <!-- ### Set the Glassfish home ### -->
  <property name="glassfish.home" location="D:/Sun/gfv2/glassfish" />  
  
  <!-- Set global properties for compile and distribution -->
  <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." />
    
    <!-- Define the jbi tasks classpath path -->
    <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>    
    <!-- Load jbi task definitions -->
    <taskdef resource="com/sun/jbi/ui/ant/antlib.xml" classpathref="jbi.ant.tasks.classpath.id"/>   
    
    <!-- JMX Connection properties to use in jbi tasks. -->
    <property name="jbi.host" value="localhost" />
    <property name="jbi.port" value="4848" />            
    <property name="jbi.username" value="admin" />
    <property name="jbi.password" value="adminadmin" />
    
    <!-- component install file and component name properties used in JBI component admin. -->
    <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" >
    <!-- Install the component -->
    <jbi-install-component 
      host="${jbi.host}" port="${jbi.port}" username="${jbi.username}" password="${jbi.password}" 
      file="${jbi.install.file}"/>
    <!-- Start the installed component -->
    <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" >
    <!-- Stop and shutdown the component before uninstalling -->
    <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" />     
    <!-- uninstall the component -->
    <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" >
    <!-- Shows the jbi component installed with ${jbi.component.name} in the OpenESB runtime -->
    <jbi-list-service-engines 
      host="${jbi.host}" port="${jbi.port}" username="${jbi.username}" password="${jbi.password}" 
      serviceEngineName="${jbi.component.name}" />
    <!-- use this if the component you installed is of type binding-component
    <jbi-list-binding-components 
      host="${jbi.host}" port="${jbi.port}" username="${jbi.username}" password="${jbi.password}" 
      bindingComponentName="${jbi.component.name}" />
    -->
  </target>
  
  <target name="init" depends="-init-jbi-ant-tasks">
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>
  
  <target name="compile" depends="init"  description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}" classpath="${glassfish.home}/jbi/lib/jbi.jar"/>
    <copy todir="${build}">  <!-- copy resources from ${src} -->
      <fileset dir="${src}" excludes="**/*.java"/>
    </copy>
  </target>
  
  <target name="dist" depends="compile" description="generate the jbi component zip file" >
    <!-- Create the distribution directory and -->
    <mkdir dir="${dist}"/>
    <!-- Put everything in ${build} into the ${jbi.install.file} file -->
    <jar jarfile="${jbi.install.file}" basedir="${build}"/>
  </target>  
  
  <target name="clean" description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>  
  
  <target name="run" depends="install, list" />
  
</project>




Posted at 09:18PM Mar 07, 2007 by Srinivasan Chikkala in OpenESB  |  Comments[0]

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed