Archive

Archive for the ‘ANT’ Category

How to call Ant script from Java

February 13, 2013 Leave a comment

Here we will see how to call Ant build target with arguments from Java

Have written this CustomAntTask.java class by extending org.apache.tools.ant.Task.
While executing the Ant build.xml script, first it will call this execute() method of CustomAntTask.java class.
Then from callAntBuildTarget() method deploy target of Ant build.xml script will be called with parameters .

CustomAntTask.java

package com.wordpress.rathinasaba.ant;

import java.io.File;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Task;


public class CustomAntTask extends Task{
	
	Project project=new Project();
	
	public final void execute() throws BuildException {
		System.out.println("--- Executing custom deploy Task ----");
		callAntBuildTarget();
	}
	
	private void callAntBuildTarget() {
		try{
			String target="deploy";
			
			File buildFile = new File("build.xml");
			System.out.println("buildFile.getAbsolutePath() ->"+ buildFile.getAbsolutePath());
			project.setUserProperty("ant.file", buildFile.getAbsolutePath());
			project.init();
			ProjectHelper helper = ProjectHelper.getProjectHelper();
			helper.parse(project, buildFile);
			
			project.addReference("ant.projectHelper", helper);
			project.setProperty("BPEL.HOST", "127.0.0.1");
			project.setProperty("OSB.HOST", "127.0.0.2");
			project.setProperty("BPEL.HostPort","7001" );
			project.setProperty("OSB.HostPort", "8001");
			
			project.addBuildListener(getDefaultLogger());
			project.executeTarget(target);
			project.log("=== Build Completed Successfully ===",Project.MSG_INFO);
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getStackTrace());
		}
	}
	
	private static DefaultLogger getDefaultLogger(){
		DefaultLogger consoleLogger=new DefaultLogger();
		consoleLogger.setErrorPrintStream(System.err);
		consoleLogger.setOutputPrintStream(System.out);
		consoleLogger.setMessageOutputLevel(Project.MSG_VERBOSE);
//		consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
		return consoleLogger;
	}
	
}

 

Package the above CustomAntTask.java class as a jar (CustomAntTask.jar) and place in the ant build script classpath.

build.xml

<project name="test" basedir="." default="CallJava">
	<path id="classpath">
		<!-- To refer the all the jars inside folder lib -->
		<fileset dir="${basedir}/lib">
			<include name="**/*.jar" />
		</fileset>
	</path>
	
	<taskdef name="customTask" classname="com.wordpress.rathinasaba.ant.CustomAntTask">
		<classpath>
			<pathelement location="${basedir}/lib/CustomAntTask.jar" />
		</classpath>
	</taskdef>

	<!-- ================================================================================================-->
	<!--        TARGET: CallJava [ This target will call Java ( CustomAntTask.java )]                    -->
	<!-- ================================================================================================ -->
	<target name="CallJava">
		<echo message="=========================================================="/>
		<echo message="                Calling Custom Java Task                       "/>
		<echo message="=========================================================="/>
  		<customTask />
  	</target>
	
	<!-- ================================================================================ -->
	<!--         TARGET: deploy [ This target will be called from java ]                  -->
	<!-- ================================================================================ -->
	<target name="deploy">
		<echo message="=========================================================="/>
		<echo message="   Populating the environment property value from Java    "/>
		<echo message="=========================================================="/>
		
		<property environment="BPEL.HOST" />
		<property environment="OSB.HOST" />
		<property environment="BPEL.HostPort" />
		<property environment="OSB.HostPort" />

		<echo message="BPEL HOST : ${BPEL.HOST}" />
		<echo message="OSB HOST : ${OSB.HOST}" />
		<echo message="BPEL Host Port : ${BPEL.HostPort}" />
		<echo message="OSB host Port : ${OSB.HostPort}" />
	</target>
</project>

 

Execution Result :

Response while executing build.xml script

Buildfile: C:\Saba\workspace\java\ANTSampleBlog\build.xml
CallJava:
     [echo] ==========================================================
     [echo]                 Calling Custom Java Task                       
     [echo] ==========================================================
[customTask] --- Executing custom Task ----
[customTask] --- Calling deploy target of Ant Build script ---
[customTask] buildFile.getAbsolutePath() ->C:\Saba\workspace\java\ANTSampleBlog\build.xml
[customTask] Build sequence for target(s) `deploy' is [deploy]
[customTask] Complete build sequence is [deploy, CallJava, ]
[customTask] deploy:
[customTask]      [echo] ==========================================================
[customTask]      [echo]    Populating the environment property value from Java    
[customTask]      [echo] ==========================================================
[customTask]  [property] Loading Environment BPEL.HOST.
[customTask]  [property] Loading Environment OSB.HOST.
[customTask]  [property] Loading Environment BPEL.HostPort.
[customTask]  [property] Loading Environment OSB.HostPort.
[customTask]      [echo] BPEL HOST : 127.0.0.1
[customTask]      [echo] OSB HOST : 127.0.0.2
[customTask]      [echo] BPEL Host Port : 7001
[customTask]      [echo] OSB host Port : 8001
[customTask] === Build Completed Successfully ===
BUILD SUCCESSFUL
Total time: 328 milliseconds
Advertisements
Categories: ANT Tags: , ,

How to create and call Custom ANT Task

February 5, 2013 Leave a comment

Here will see how to create Custom ANT Task and how to call this Custom ANT Task from ANT build script.

Jars required:
ant.jar

Create Custom Ant Task
Created a CustomAntTask.java class by extending the org.apache.tools.ant.Task

CustomAntTask.java

package com.wordpress.rathinasaba.ant;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class CustomAntTask extends Task{

	private String fileName;
	private String targetName;
	
	public final void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public final void setTargetName(String targetName) {
		this.targetName = targetName;
	}

	public final void execute() throws BuildException {
		println("---- Executing Custom ANT Task ----");
		println("----FileName :"+this.fileName);
		println("----TargetName :"+this.targetName);
	}
	
	private static void println(String content){
		System.out.println(content);
	}
	
}

Call Custom Ant Task from ant script

created a CustomAntTask.jar by packaging the above mentioned CustomAntTask.java class and placed that jar in ant build classpath.

build.properties

project.file.name=Sample.properties
ant.action=deploy

 
build.customTask.xml

<project name="CustomTaskTest" basedir="." default="CallCustomTask">
	<property file="build.properties"/>
	<path id="classpath">
		<!-- To refer the all the jars inside folder lib-->
		<fileset dir="${basedir}/lib">
			<include name="**/*.jar" />
		</fileset>
	</path>

	<!-- ================================================================================ -->
	<!--              Add CustomAntTask class in taskdef                                  -->
	<!-- ================================================================================ -->
	<taskdef name="customTask" classname="com.wordpress.rathinasaba.ant.CustomAntTask">
		<classpath>
			<pathelement location="${basedir}/lib/CustomAntTask.jar" />
		</classpath>
	</taskdef>

	<target name="CallCustomTask">
		<customTask fileName="${project.file.name}" targetName="${ant.action}" />
	</target>
</project>

Folder structure while executing ant script

CustomAntTask

CustomAntTask

SOA 11G MDS Deployment through ANT Script

August 25, 2012 Leave a comment

Here I have given the ANT script to deploy shared resources to MDS.

This script can be used to deploy all shared resources to MDS or
to deploy particular folder to MDS.
 
1. My MDS Folder structure
 

MDSFolderStructure

MDSFolderStructure


 

2. Resource structure of MDS Deployment
 
The below is the way I have kept the resources to be deployed to MDS while executing the Ant script.
 
Inside the MDS folder , I have followed same folder structure as mentioned above.
 

MDSDeploymentStructure

MDSDeploymentStructure

 

3. build.properties
 

mds.application=mds-application
# mds.all key is for deployment
mds.all=MDS/apps
# specify the path for undeploying MDS resources
#example like (/apps/int/util/DVM or /apps/int/util/resources)
#mds.folderName=
# Specify the path to place MDS backup as jar
#mds.export.backup.dir=
#SOA 11G installation location
wls.bea.home=C:/Saba/soa11g/soa11.1.1.5/Middleware
oracle.home=${wls.bea.home}/Oracle_SOA1
java.passed.home=${wls.bea.home}/jdk160_24
wl.home=${wls.bea.home}/wlserver_10.3
#Admin Server Hostname and Port number
admin.server.host=localhost
admin.server.port=7011
# connection information for the managed server, used for soa-deployment
managed.server.host=localhost
managed.server.port=8011
# User and credentials for the servers
server.user=weblogic
server.password=welcome1

 
4. build.xml
 

<?xml version="1.0" encoding="UTF-8" ?>
<project name="mds-application" default="display" basedir=".">    
	<!-- build.properties -->
	<property file="build.properties" />
	<property name="deploy.dir" value="${basedir}/deploy" />
	<property name="mds.deploy.dir" value="${deploy.dir}" />
	<property name="mds.faultpolicies.dir" value="int/util/fault-policies" />
	<property name="mds.dvm.dir" value="int/util/DVM" />
	<property name="mds.xref.dir" value="int/util/XREF" />
	<property name="mds.schema.dir" value="int/util/resources" />
	<property name="mds.soaConstant.dir" value="int/util/constants" />
	
	<!-- This will display the targets available -->
	<target name="display">
		<input message="Please enter target to Run MDS" addproperty="target" defaultvalue="deployAll" validargs="deployAll,deployFaultPolicy,deployDVM,deployXREF,deployXSDWSDL,deploySOAConstant,undeployMDS,exportMDS" />
		<antcall target="${target}"/>
	</target>
	
	<target name="clean">
		<echo>remove and create local MDS temp</echo>
		<delete dir="${mds.deploy.dir}"/>	
	</target>
	<target name="init" depends="clean">
		<echo>remove and create local MDS temp</echo>
		<mkdir dir="${mds.deploy.dir}"/>	
	</target>
	
	<target name="buildAll" depends="init">
		<echo>+++++++ copy required files to ${mds.deploy.dir} +++++++++</echo>
		<copy todir="${mds.deploy.dir}" verbose="true" overwrite="true">
			<fileset dir="${basedir}/${mds.all}/" includes="**/*"/>
		</copy>               
		<echo>create zip from file MDS store</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.jar" compress="false">         
			<fileset dir="${mds.deploy.dir}" includes="**/*" />
		</zip>
		<echo>create zip with MDS jar</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.zip" compress="false">
			<fileset dir="${mds.deploy.dir}" includes="*.jar" />
		</zip>	
	</target>
	
	<target name="buildFaultPolicy" depends="init">
		<echo>+++++++ copy required files to ${mds.deploy.dir} +++++++++</echo>
		<copy todir="${mds.deploy.dir}" verbose="true" overwrite="true">
			<fileset dir="${basedir}/${mds.all}/" includes="**/${mds.faultpolicies.dir}/**"/>
		</copy>               
		<echo>create zip from file MDS store</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.jar" compress="false">         
			<fileset dir="${mds.deploy.dir}" includes="**/*" />
		</zip>
		<echo>create zip with MDS jar</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.zip" compress="false">
			<fileset dir="${mds.deploy.dir}" includes="*.jar" />
		</zip>	
	</target>
	
	<target name="buildDVM" depends="init">
		<echo>+++++++ copy required files to ${mds.deploy.dir} +++++++++</echo>
		<copy todir="${mds.deploy.dir}" verbose="true" overwrite="true">
			<fileset dir="${basedir}/${mds.all}/" includes="**/${mds.dvm.dir}/**"/>
		</copy>               
		<echo>create zip from file MDS store</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.jar" compress="false">         
			<fileset dir="${mds.deploy.dir}" includes="**/*" />
		</zip>
		<echo>create zip with MDS jar</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.zip" compress="false">
			<fileset dir="${mds.deploy.dir}" includes="*.jar" />
		</zip>	
	</target>
	
	<target name="buildXREF" depends="init">
		<echo>+++++++ copy required files to ${mds.deploy.dir} +++++++++</echo>
		<copy todir="${mds.deploy.dir}" verbose="true" overwrite="true">
			<fileset dir="${basedir}/${mds.all}/" includes="**/${mds.xref.dir}/**"/>
		</copy>               
		<echo>create zip from file MDS store</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.jar" compress="false">         
			<fileset dir="${mds.deploy.dir}" includes="**/*" />
		</zip>
		<echo>create zip with MDS jar</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.zip" compress="false">
			<fileset dir="${mds.deploy.dir}" includes="*.jar" />
		</zip>	
	</target>
	
	<target name="buildXSDWsdl" depends="init">
		<echo>+++++++ copy required files to ${mds.deploy.dir} +++++++++</echo>
		<copy todir="${mds.deploy.dir}" verbose="true" overwrite="true">
		     <fileset dir="${basedir}/${mds.all}/" includes="**/${mds.schema.dir}/**"/>
		</copy>               
		<echo>create zip from file MDS store</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.jar" compress="false">         
		    <fileset dir="${mds.deploy.dir}" includes="**/*" />
		</zip>
		<echo>create zip with MDS jar</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.zip" compress="false">
			<fileset dir="${mds.deploy.dir}" includes="*.jar" />
		</zip>	
	</target>
	
	<target name="buildSOAConstant" depends="init">
		<echo>copy required files to ${mds.deploy.dir}</echo>
		<copy todir="${mds.deploy.dir}" verbose="true" overwrite="true">
			<fileset dir="${basedir}/${mds.all}/" includes="**/${mds.soaConstant.dir}/**"/>
		</copy>               
		<echo>create zip from file MDS store</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.jar" compress="false">         
			<fileset dir="${mds.deploy.dir}" includes="**/*" />
		</zip>
		<echo>create zip with MDS jar</echo>
		<zip destfile="${mds.deploy.dir}/${mds.application}.zip" compress="false">
			<fileset dir="${mds.deploy.dir}" includes="*.jar" />
		</zip>	
	</target>
	
	<target name="genericDeployer">
		<echo>deploy MDS application ${mds.application}</echo>
		<echo>deploy on	http://${managed.server.host}:${managed.server.port}/soa-infra/deployer	with user ${server.user}</echo>
		<echo>deploy sarFile ${mds.deploy.dir}\${mds.application}.zip</echo>
		<ant antfile="${oracle.home}/bin/ant-sca-deploy.xml" inheritAll="false"	target="deploy">
			<property name="wl_home" value="${wl.home}" />
			<property name="oracle.home" value="${oracle.home}" />
			<property name="serverURL" value="http://${managed.server.host}:${managed.server.port}/soa-infra/deployer"/>
			<property name="user" value="${server.user}" />
			<property name="password" value="${server.password}" />
			<property name="overwrite" value="true" />
			<property name="forceDefault" value="false" />
			<property name="sarLocation" value="${mds.deploy.dir}/${mds.application}.zip"/>
		</ant>
	</target>
	
	<!-- This target is to deploy all required sources to MDS -->
	<target name="deployAll" depends="buildAll">
		<antcall target="genericDeployer"/>
	</target>
	
	<!-- This target is to deploy fault-policies files to MDS -->
	<target name="deployFaultPolicy" depends="buildFaultPolicy">
		<antcall target="genericDeployer"/>
	</target>
	
	<!-- This target is to deploy DVM files to MDS -->
	<target name="deployDVM" depends="buildDVM">
		<antcall target="genericDeployer"/>
	</target>
	
	<!-- This target is to deploy XREF files to MDS -->
	<target name="deployXREF" depends="buildXREF">
		<antcall target="genericDeployer"/>
	</target>
	
	<!-- This target is to deploy Schemas and WSDLs files to MDS -->
	<target name="deployXSDWSDL" depends="buildXSDWsdl">
		<antcall target="genericDeployer"/>
	</target>
	
	<!-- This target is to deploy SOA Constants file to MDS -->
	<target name="deploySOAConstant" depends="buildSOAConstant">
		<antcall target="genericDeployer"/>
	</target>
	
	<target name="undeployMDS">
		<echo>undeploy MDS application ${mds.application}</echo>
		<ant antfile="${oracle.home}/bin/ant-sca-deploy.xml" inheritAll="false"	target="removeSharedData">
			<property name="wl_home" value="${wl.home}" />
			<property name="oracle.home" value="${oracle.home}" />
			<property name="serverURL" value="http://${managed.server.host}:${managed.server.port}/soa-infra/deployer"/>
			<property name="user" value="${server.user}" />
			<property name="password" value="${server.password}" />
			<property name="folderName" value="${mds.folderName}" />
		</ant>
	</target>
	<target name="exportMDS">
	    <tstamp>
	      <format property="start.timestamp" pattern="yyyy-MM-dd_HHmm" />
	    </tstamp>
	    <echo>
		================================================================================
			EXPORT MDS: ${local.mds.export}/MDSbackup.${start.timestamp}.jar
		================================================================================
	    </echo>
	    <ant antfile="${oracle.home}/bin/ant-sca-deploy.xml" inheritAll="false" target="exportSharedData">
	      <property name="serverURL"        value="${serverURL}"/>
	      <property name="jarFile"          value="${mds.export.backup.dir}/MDSbackup.${start.timestamp}.jar"/>
	      <property name="pattern"          value="**"/>
	      <property name="user"             value="${server.user}"/>
	      <property name="password"         value="${server.password}"/>
	    </ant>
	  </target>
</project>

SOA 11G: Composites Deployment using ANT

August 8, 2012 Leave a comment

Here I have given the ANT script for soa 11g composites depoyment by reading the entry from the text file. We can use this ant script to deploy multiple composite project in a shot. This ant script will read the text file line by line and deploy the projects.

1.build.properties


project.file.name=ProcessList.txt
wls.bea.home=/u01/oracle/product/fmw/soa11.1.1.6
wl_home=${wls.bea.home}/wlserver_10.3
oracle.home=${wls.bea.home}/Oracle_SOA1
java.home=/u01/oracle/product/jdk/jdk1.6.0_30

#Weblogic server username and password
server.user=weblogic
server.password=welcome1
#serverURL=http://:
serverURL=http://localhost:8011
#server.host=
server.host=localhost
#server.port=
server.port=8011

 
2.ProcessList.txt file structure


{processName},{partition},{version},{Is it default process},{project location from where the build.xml is}
SayHello,default,1.0.0,true,applications/sample/SayHello

 
3.build.xml

<?xml version="1.0" encoding="iso-8859-1"?>
<project name="soaDeployAll" basedir="." default="help">
  <property environment="env"/>
  <property name="sca.location" value="${basedir}/"/>
	<path id="classpath">
		<!-- To refer the all the jars inside folder lib-->
		<fileset dir="${basedir}/lib">
			<include name="**/*.jar"/>
		</fileset>
	</path>
 <taskdef resource="net/sf/antcontrib/antcontrib.properties" uri="http://ant-contrib.sourceforge.net">
  	<classpath>
  		<pathelement location="${basedir}/lib/ant-contrib-1.0b3.jar"/>
  	</classpath>
  </taskdef>
  <taskdef resource="net/sf/antcontrib/antlib.xml">
  	<classpath>
  	  		<pathelement location="${basedir}/lib/ant-contrib-1.0b3.jar"/>
  	  	</classpath>
  </taskdef>


  <!-- ================================================================================ -->
  <!-- TARGET: help                                                                     -->
  <!-- ================================================================================ -->

  <target name="help">
    <echo>
    Usable targets are:

    help                   - This help
    deployComposites       - Packages and deploys composites in 'ProcessList.txt'
    undeployComposites     - Undeploys composites in 'ProcessList.txt'
    listDeployedComposites - Lists deployed composites
	------------------------------------------------------
   	|	Usage example:                                  |
    ------------------------------------------------------

    export ORACLE_HOME=${oracle.home}
    export ANT_HOME=${ORACLE_HOME}/modules/org.apache.ant_1.7.1
    export PATH=${ANT_HOME}/bin:$PATH
    export CURRENT_FOLDER=`pwd`
    export JAVA_HOME=${ORACLE_HOME}/jdk1.6.0_21

    ant help -verbose
    ant deployComposites -verbose
    ant undeployComposites -verbose
    ant listDeployedComposites -verbose

    </echo>

  </target>


  <!-- ================================================================================ -->
  <!-- Check for an load property files                                                 -->
  <!-- ================================================================================ -->

  <available file="build.properties" property="file.exists" value="true" />
  <fail unless="file.exists" message="ERROR: Filename 'build.properties' does not exist." />
  <property file="build.properties"/>  
  <!-- ================================================================================ -->
  <!-- TARGET: deployComposites                                                         -->
  <!-- ================================================================================ -->

  <target name="deployComposites">
	
    <available file="${project.file.name}" property="file.exists" value="true" />
    <fail unless="file.exists" message="ERROR: Filename '${project.file.name}' does not exist."/>
    <loadfile property="allprocesses" srcFile="${project.file.name}"/>

    <var name="errorCount" value="0"/>
    <var name="processCount" value="0"/>
    <var name="errorProcessNames" value="(none)"/>
  	<if>
  		<equals arg1="${replace.env.prop}" arg2="true"/>
  		<then>
  			<antcall target="replace"/>
  		</then>
  	</if>
  	
    <trycatch property="tryName" reference="exception_ref">
      <try>
        <for list="${allprocesses}" param="processName" delimiter="${line.separator}">
          <sequential>
  	     <propertyregex property="composite.name"      input="@{processName}" regexp="([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)" select="\1" override="true"/>
            <propertyregex property="composite.partition" input="@{processName}" regexp="([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)" select="\2" override="true"/>
            <propertyregex property="composite.revision"  input="@{processName}" regexp="([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)" select="\3" override="true"/>
            <propertyregex property="default.composite"   input="@{processName}" regexp="([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)" select="\4" override="true"/>
            <propertyregex property="project.loctaion"         input="@{processName}" regexp="([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)" select="\5" override="true"/>
            <math result="processCount" operand1="${processCount}" operation="+" operand2="1" datatype="int"/>
			
            <echo>
			 ===================================================================================
				PACKAGE COMPOSITE #${processCount}: ${composite.name} ${composite.revision}
			 ===================================================================================
            </echo>
            <copy todir="${basedir}/${project.loctaion}/SCA-INF/classes/META-INF/" file="${basedir}/includes/adf-config.xml" overwrite="true"/>
          	
            <ant antfile="${oracle.home}/bin/ant-sca-package.xml" target="package" inheritall="false">
              <property name="oracle.home" value="${oracle.home}"/>	
              <property name="compositeDir" value="${basedir}/${project.loctaion}"/>
              <property name="scac.application.home" value="${basedir}/${project.loctaion}"/>
              <property name="scac.input" value="${basedir}/${project.loctaion}/composite.xml"/>
              <property name="compositeName" value="${composite.name}"/>
              <property name="revision" value="${composite.revision}"/>
              <property name="java.passed.home" value="${java.home}"/>
              <property name="wl_home" value="${wl_home}"/>
            </ant>

            <echo>
			 ================================================================================
				 DEPLOY COMPOSITE #${processCount}: ${composite.name} 
			 ================================================================================
            </echo>
            <ant antfile="${oracle.home}/bin/ant-sca-deploy.xml" target="deploy" inheritall="false">
              <property name="user" 		value="${server.user}"/>
              <property name="password" 	value="${server.password}"/>
              <property name="serverURL" 	value="${serverURL}/soa-infra/deployer"/>
              <property name="sarLocation" 	value="${basedir}/${project.loctaion}/deploy/sca_${composite.name}_rev${composite.revision}.jar"/>
              <property name="overwrite" 	value="true"/>
              <!--<property name="configplan" 	value="${basedir}/${project.loctaion}/${composite.name}_cfgplan.xml"/>-->
            </ant>

            <sleep seconds="3" />
          </sequential>
        </for>
      </try>
      <catch>
        <property name="exception" refid="exception_ref" />
        <property name="message" value="ERROR IN TRYCATCH BLOCK:${line.separator}${exception}" />
        <echo></echo>
        <echo message="${message}" />
        <math result="errorCount" operand1="${errorCount}" operation="+" operand2="1" datatype="int"/>
        <var name="errorProcessNames" value="${composite.name}"/>
      </catch>
    </trycatch>

    <echo>
		**************************************************************
		*  ANT TARGET NAME	: deployComposites
		*  FAILED PROCESS	: ${errorProcessNames}
		*
		**************************************************************
    </echo>
  </target>


  <!-- ================================================================================ -->
  <!-- TARGET: undeployComposites                                                       -->
  <!-- ================================================================================ -->

  <target name="undeployComposites">

    <available file="${project.file.name}" property="file.exists" value="true" />
    <fail unless="file.exists" message="ERROR: Filename '${project.file.name}' does not exist." />
    <loadfile property="allprocesses" srcFile="${project.file.name}"/>

    <var name="errorCount" value="0"/>
    <var name="processCount" value="0"/>
    <var name="errorProcessNames" value="*"/>

    <for list="${allprocesses}" param="processName" delimiter="${line.separator}">
      <sequential>
        <propertyregex property="composite.name"      input="@{processName}" regexp="([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)" select="\1" override="true"/>
        <propertyregex property="composite.partition" input="@{processName}" regexp="([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)" select="\2" override="true"/>
        <propertyregex property="composite.revision"  input="@{processName}" regexp="([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)" select="\3" override="true"/>
        <math result="processCount" operand1="${processCount}" operation="+" operand2="1" datatype="int"/>

        <trycatch property="tryName" reference="exception_ref">
          <try>

            <echo>
			================================================================================
			UNDEPLOY COMPOSITE #${processCount}: ${composite.name}
			================================================================================
            </echo>
            <ant antfile="${oracle.home}/bin/ant-sca-deploy.xml" target="undeploy" inheritall="false">
              <property name="user"             value="${server.user}"/>
              <property name="password"         value="${server.password}"/>
              <property name="serverURL"        value="${serverURL}/soa-infra/deployer"/>
              <property name="compositeName"    value="${composite.name}"/>
              <property name="partition"        value="${composite.partition}"/>
              <property name="revision"         value="${composite.revision}"/>
            </ant>
          </try>
          <catch>
            <property name="exception" refid="exception_ref" />
            <property name="message" value="ERROR IN TRYCATCH BLOCK:${line.separator}${exception}" />
            <echo></echo>
            <echo message="${message}" />
            <math result="errorCount" operand1="${errorCount}" operation="+" operand2="1" datatype="int"/>
            <var name="errorProcessNames" value="${errorProcessNames}${line.separator}*     ${composite.name}"/>
          </catch>
        </trycatch>
        <sleep seconds="1" />
      </sequential>
    </for>
    <echo>
		***********************************************************************************
		*
		*  	ANT TARGET NAME		   : undeployComposites
		*  	TOTAL NUMBER OF ERRORS : ${errorCount} of ${processCount} processes
		*  	FAILED PROCESSES	   : ${errorProcessNames}
		*
		***********************************************************************************
    </echo>
  </target>

  <!-- ================================================================================ -->
  <!-- TARGET: listDeployedComposites                                                   -->
  <!-- ================================================================================ -->

  <target name="listDeployedComposites">
  	<trycatch property="tryName" reference="exception_ref">
  	      <try>
		    <ant antfile="${oracle.home}/bin/ant-sca-mgmt.xml" target="listDeployedComposites" inheritall="false">
		      <property name="host" 	value="${server.host}"/>
		      <property name="port" 	value="${server.port}"/>
		      <property name="user" 	value="${server.user}"/>
		      <property name="password"	value="${server.password}"/>
		    </ant>
  	      </try>
	      <catch>
	         <property name="exception" refid="exception_ref" />
	         <property name="message" value="ERROR IN TRYCATCH BLOCK:${line.separator}${exception}" />
	         <echo>=========================</echo>
	         <echo message="${message}" />
	      </catch>
	  </trycatch>    	
  </target>
</project>

Create WAR file using ANT script

December 31, 2011 Leave a comment

In this post we will see how to build WAR (Web Archive) file using ANT script.
 
build.xml file to create WAR file

<?xml version="1.0" ?> 
<project name="SampleWebApp" default="war">

	<path id="compile.classpath">
		<fileset dir="WebContent/WEB-INF/lib">
			<include name="*.jar"/>
		</fileset>
	</path>
	
	<target name="clean">
		<delete dir="dist" />
		<delete dir="build" />
	</target>
	
	<target name="init">
		<mkdir dir="build/classes"/>
		<mkdir dir="dist" />
	</target>
	
	<target name="compile" depends="init" >
		<javac destdir="build/classes" debug="true" srcdir="src">
			<classpath refid="compile.classpath"/>
		</javac>
	</target>
	
	<target name="war" depends="compile">
		<war destfile="dist/SampleWebApp.war" webxml="WebContent/WEB-INF/web.xml">
			<fileset dir="WebContent"/>
			<lib dir="WebContent/WEB-INF/lib"/>
			<classes dir="build/classes"/>
		</war>
	</target>
	
	<target name="clean">
		<delete dir="dist" />
		<delete dir="build" />
	</target>
</project>

Create MANIFEST.MF file using ANT script

October 15, 2011 Leave a comment

Here I have give the ANT script snippet to create MANIFEST.MF file in jar

<target name="jar" depends="compile">
        <jar destfile="${dist}/MyApplication.jar" basedir="${build}">
        	<manifest file="MANIFEST.MF">
        	    <attribute name="Built-By" value="${user.name}"/>
        	    	<section name="common">
	        	      <attribute name="Specification-Title" value="MyApplictaion"/>
	        	      <attribute name="Specification-Version" value="${version}"/>
	        	      <attribute name="Specification-Vendor" value="Sample Org."/>
	        	      <attribute name="Implementation-Title" value="CustomerUtility"/>
	        	      <attribute name="Implementation-Version" value="${version} ${TODAY}"/> 
	        	      <attribute name="Implementation-Vendor" value="Sample Corp."/>
        	    	  <attribute name="Class-Path" value="./lib/jasper.jar  ./lib/servlet-api.jar" />	
        	    	</section>
        	  </manifest>
        </jar>
    </target>

Create Jar using ANT Script

October 15, 2011 Leave a comment

Here I have given the ANT script to create the jar file.

<project name="BuildJar" basedir="." default="jar">
	<property name="build" value="${basedir}/build"/>
	<property name="dist" value="${basedir}/dist"/>
	<property name="src" value="${basedir}/src"/>
	<path id="classpath">
		<!-- To refer the jar by name -->
		<pathelement location="${basedir}/lib/fabric-runtime.jar"/>
		<pathelement location="${basedir}/lib/orabpel.jar"/>
		<pathelement location="${basedir}/lib/spring-beans-1.2.6.jar"/>
		<!-- To refer the all the jars inside folder lib-->
		<fileset dir="${basedir}/lib">
			<include name="**/*.jar"/>
		</fileset>
	</path>
	
	<target name="clean">
		<!-- deleting the folder while initiating build -->
        <delete dir="${build}"/>
		<delete dir="${dist}"/>
    </target>

	<target name="init" depends="clean">
		<!--Compiled classes will go to build folder -->
		<mkdir dir="${build}"/>
		<!--Resultant jar will go to dist folder -->
		<mkdir dir="${dist}"/>
    </target>
	
    <target name="compile" depends="init">
    	<!--compiling the files under the ${src} folder -->
        <javac srcdir="${src}" destdir="${build}" classpathref="classpath"/>
    </target>

    <target name="jar" depends="compile">
        <jar destfile="${dist}/MyApplication.jar" basedir="${build}"/>
    </target>
</project>

 

target –> It must have “name” attribute. The target is made up of one or more Tasks like invoke a command or another program.

 

depends –> one target can be dependant with another target like “Jar” target depends on “compile” and “compile” depends on “init” etc.
The target mentioned inside “depends” attribute will be executed first before executing the current target.
Example if the current target is “Jar”, the “compile” target will be executed before “Jar” target.