Saturday, May 12, 2012

Creating ANT BUILD Configuration.....

"build.properties" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>



lib.dir=WebContent/WEB-INF/lib
src.dir=src
conf.dir=WebContent/WEB-INF
web.content=WebContent
project.name=Struts2SpringDemo
build.dir=build
dist.dir=dist
javadoc.dir = JavaDocs
*********************************************************************************
"build.xml" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<?xml version="1.0" encoding="UTF-8"?>
<project name="Struts2SpringDemo" default="war" basedir=".">
    
    <property file="build.properties"/>
    <!--<property file="version.properties"/>-->
    <!--
        Tasks to be done!
        1. clean
        2. init
        3. compile
        4. copy
        5. war
        6. clean-javadoc
        7. javadoc
    -->
    <!-- setting the classpath for compiling java files -->
    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>  
    
    <!-- deleting the existing dist and build directories -->
    <target name="clean">
        <echo>******Cleaning the ${build.dir} and ${dist.dir}******</echo>
        <delete dir="${build.dir}"/>
        <delete dir="${dist.dir}"/>
    </target>
    
    <!-- deleting the existing docs directories -->
    <target name="clean-javadoc">
        <echo>******Cleaning the ${javadoc.dir}******</echo>        
        <delete dir="${javadoc.dir}"/>
    </target>
    
    <!-- creating the dist and build directories -->
    <target name="init" depends="clean">
        <echo>******Creating the required directories******</echo>
        <mkdir dir="${dist.dir}"/>
        <mkdir dir="${build.dir}/WEB-INF/classes"/>
        <mkdir dir="${build.dir}/WEB-INF/lib"/>
    </target>
    
    <!-- compile the source code -->
    <target name="compile" depends="init">
        <echo>******Compile the source files******</echo>
        <javac debug="on" srcdir="${src.dir}" destdir="${build.dir}/WEB-INF/classes" includes="**/*">
            <classpath refid="classpath"/>            
        </javac>
    </target>
    
    <!-- copy the all relative files and creating a package for war file -->
    <target name="copy" depends="compile">
        <echo>******Copying the source files into ******${build.dir}**</echo>
        <copy todir="${build.dir}/WEB-INF">
            <fileset dir="${conf.dir}"/>
        </copy>
        <copy todir="${build.dir}">
            <fileset dir="${web.content}"/>
        </copy>      
        <copy todir="${build.dir}/WEB-INF/lib">
            <fileset dir="${lib.dir}"/>
        </copy>
        <copy todir="${build.dir}/WEB-INF/classes">
            <fileset dir="${src.dir}" includes="**/*.properties"/>
        </copy>
        <copy todir="${build.dir}/WEB-INF/classes">
            <fileset dir="${src.dir}" includes="**/*.xml"/>
        </copy>
<copy todir="${build.dir}/WEB-INF/classes">
            <fileset dir="${src.dir}" includes="**/*.xsl"/>
        </copy>
    </target>
    
    <!-- the ant war task. with all resources in place, create the war file -->
    <target name="war" depends="copy">
        <echo>******Building the war file******${project.name}.war**</echo>
        <war destfile="${dist.dir}/${project.name}.war" webxml="${build.dir}/WEB-INF/web.xml">
            <fileset dir="${build.dir}"/>
        </war>
    </target>
    
    <!-- the ant javadoc task. Generates JavaDocs for the Browser App code -->
    <target name="javadoc" description="Generates JavaDocs for the Browser App code" depends="clean-javadoc">
        <echo>*****Generating docs for Struts2SpringDemo app*****</echo>
        <mkdir dir="${javadoc.dir}"/>        
        <javadoc
            destdir="${javadoc.dir}"
            author="false"
            version="false"
            access="private"
            use="true"
            source="1.6+"
            windowtitle="Struts2SpringDemo App API">
            <classpath refid="classpath"/>
            <fileset dir="${src.dir}" defaultexcludes="yes">
                <include name="com/**"/> 
                <exclude name="com/**/*.properties"/>
                <exclude name="com/**/*.xml"/>
            </fileset>            
            <doctitle><![CDATA[<h1>Struts2SpringDemo application Api</h1>]]></doctitle>
            <bottom><![CDATA[<i>Copyright &#169; 2012 Abhinav Mishra. All Rights Reserved.</i>]]></bottom>
        </javadoc>
    </target>
</project>
********************************************************************
"build-all.xml" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<?xml version="1.0" encoding="UTF-8"?>
<project name="struts2spring-build-all" default="all">   
    <!-- no need to run target "clean" as individual build files are calling clean target -->
    <!-- THIS BUILD FILE IS FOR RUNNING ALL THE BUILD FILES TO CREATE RESPECTIVE JARS/WARS -->
    <target name="all">
       
        <echo>******STARTED RUNNING THE STRUTS2SPRING APPLICATION BUILD******</echo>
<ant antfile="./code/Struts2SpringDemo/build.xml" useNativeBasedir="true" />
    </target>

    <target name="clean">
<echo>******STARTED RUNNING THE STRUTS2SPRING APPLICATION CLEAN******        </echo>
        <ant antfile="./code/Struts2SpringDemo/build.xml" useNativeBasedir="true" />
    </target>
</project>

No comments:

Post a Comment

Thanks for your comments/Suggestions.