Friday, June 5, 2015

Sample build.xml to create war file based on eclipse directory structure

Yesterday I got a chance to write sample build.xml for one of my colleague. He has default build.xml for his project which is written by someone based on random directories (similar to war directory structure). This build.xml is used to pack the directory sturctures and place it into the tomcat server webapp directory. In this type scenario he did not able to debugging his application from eclipse.

I suggested them to create one more build.xml based on eclipse directory structure for production or uat deployment. For development purpose try to setup a tomcat server and debugging your application in eclipse without worrying about deployment. I provided that sample build.xml below. Please look it and provide your comments.

<?xml version="1.0" encoding="UTF-8"?>
<project name = "tems" basedir = "." default = "war">
   
    <property name="project-name" value="${ant.project.name}" />
    <property name="builder" value="Achappan Mahalingam" />

    <property name="war-file-name" value="${project-name}.war" />
    <property name="source-directory" value="src" />
    <property name="classes-directory" value="build/classes" />
    <property name="web-directory" value="WebContent" />
    <property name="web-xml-file" value="WebContent/WEB-INF/web.xml" />
    <property name="libs-directory" value="WebContent/WEB-INF/lib" />
    <property name="build-directory" value="build" />


    <target name = "info">
          <echo message = ""/>
          <echo message = "${project-name} Build File"/>
          <echo message = "-----------------------------------"/>
          <echo message = "Run by ${builder}"/>
       </target>

    <target name="war" depends="info">
        <mkdir dir="${build-directory}" />
        <delete file="${build-directory}/${war-file-name}" />
        <war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
            <classes dir="${classes-directory}" />
            <fileset dir="${web-directory}">
                <exclude name="WEB-INF/web.xml" />
            </fileset>
        </war>
    </target>
</project>

No comments: