Amazon

Saturday, September 27, 2014

Updating EAR with Environment Specific deployment descriptor using ANT Script

Scenario:

  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.
Solution:
  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>

    <target name="mov" depends="mkchdir">
<echo>MOVING TAR IN TMP FOLDER</echo> 
        <move file="${tar}" todir="${upd_ear.dir}"/>
    </target>

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

    <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>

    <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>

    <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>
 

   <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" /> 
</fileset>
</zip>
  </target>

  
   <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" /> 
</fileset>
</zip>
   </target>

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

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

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

</project>

Amazon Best Sellors

TOGAF 9.2 - STUDY [ The Open Group Architecture Framework ] - Chap 01 - Introduction

100 Feet View of TOGAF  What is Enterprise? Collection of Organization that has common set of Goals. Enterprise has People - organized by co...