Saturday, September 27, 2014

Updating EAR with Environment Specific deployment descriptor using ANT Script


  1. EAR contains a web application.
  2. The EAR need to be deployed in three client environments e.g. Development, UAT and Production
  3. The different environments required filters in web.xml. But the URL of filters are different for different environment. 
  4. So, before deployment, the web.xml of Development should be there in Web Application (WAR) and same applies before deployment in UAT and Production.
  1. Write an Ant Script to update the WAR file with respective web.xml and update the EAR with updated WAR File.
Ant Script:

ant -Dtar=apptar.tar -Dxml=PRO movwebx -f build.xml all

ant -f build.xml all


<project  name="UPDATE_EAR" default="dist" basedir=".">
    <property name="upd_ear.dir" value="upd_ear"/>

    <target name="mkchdir">
<echo>CREATING TMP FOLDER</echo>   
        <mkdir dir="upd_ear"/>

    <target name="mov" depends="mkchdir">
        <move file="${tar}" todir="${upd_ear.dir}"/>

    <target name="tarxvf" depends="mov">
<echo>UN TAR ${tar} IN TMP FOLDER</echo> 
        <unjar src="${upd_ear.dir}/${tar}" dest="${upd_ear.dir}"/>

    <target name="earxvf" depends="tarxvf">
<echo>UN JAR appear.ear IN TMP FOLDER</echo> 
        <unjar src="${upd_ear.dir}/appear.ear" dest="${upd_ear.dir}"/>

    <target name="warxvf" depends="earxvf">
<echo>UN JAR appwar.war IN TMP FOLDER</echo> 
        <unwar src="${upd_ear.dir}/appwar.war" dest="${upd_ear.dir}"/>

    <target name="movwebx" depends="warxvf">
<echo>MOVE web_${xml}.xml to web.xml</echo> 
        <move file="${upd_ear.dir}/WEB-INF/web_${xml}.xml"  tofile="${upd_ear.dir}/WEB-INF/web.xml" />

   <target name="updwar" depends="movwebx"> 
  <echo>UPDATE web.xml of ${xml} IN appwar.war</echo> 
<zip destfile="${upd_ear.dir}/appwar.war" update="true">
<fileset dir="${upd_ear.dir}"> 
<include name="WEB-INF/web.xml" /> 

   <target name="updear" depends="updwar"> 
      <echo>UPDATING appear.ear WITH appwar.war</echo>   
 <zip destfile="${upd_ear.dir}/appear.ear" update="true">
<fileset dir="${upd_ear.dir}"> 
<include name="appwar.war" /> 

   <target name="movear" depends="updear">
         <echo>MOVING EAR FILE</echo>   
        <move file="${upd_ear.dir}/appear.ear"  todir="." />

   <target name="movtar" depends="movear">
         <echo>MOVING TAR FILE</echo>   
        <move file="${upd_ear.dir}/${tar}"  todir="." />

    <target name="delchdir" depends="movtar">
        <echo>DELETING TMP FOLDER</echo>   
        <delete dir="${upd_ear.dir}"/>
   <target name="updateear" depends="delchdir"/>


No comments:

Post a Comment

Amazon Best Sellors

Weblogic - Server Creation - Issues

Datasource creation using python script.  Python Script was failing after creating Datasource. From UI Admin Console, if I try to activat...