A typical ant build file

Today I got a build requirement from dev, “hey help me to setup autmated build for my ancient project.”

The project is a very classical SSH project. I spent half an hour to setup it with Ant. Basically, clean, compile and dist.

===

<?xml version="1.0"?>  
<project name="xxx" basedir="." default="clean">  
      <property name="name" value="FirstCapital"/>  
      <property name="war.dir" value="target"/>  
      <property name="src.dir" value="src"/>  
      <property name="client.dir" value="client"/>  
      <property name="build.dir" value="classes"/>  
      <property name="webcontent.dir" value="WebContent"/>  
      <property name="dist.dir" value="dist"/>  
      <property environment="env"/>    
      <path id="master-classpath">  
        <fileset dir="${webcontent.dir}/WEB-INF/lib" includes="*.jar"/>			         
      </path>     
  
      <target name="clean" description="Clean output dirs (build, target, dist)">  
          <delete dir="${build.dir}"/>  
          <delete dir="${war.dir}"/>  
          <delete dir="${dist.dir}"/>  
          <delete file="client/${name}.jar"/>  
      </target>  
	  
      <target name="build" description="Compile main source tree java files into class files, generate jar files">  
          <mkdir dir="${build.dir}"/>  
          <mkdir dir="${war.dir}"/>  
          <javac destdir="${build.dir}" debug="true"  
                  deprecation="false" optimize="false" failonerror="true" encoding="utf-8" nowarn="true">  
              <src path="${src.dir}"/>  
              <classpath refid="master-classpath"/>  
          </javac>  
          <mkdir dir="${war.dir}/WEB-INF/lib"/>  
          <mkdir dir="${war.dir}/WEB-INF/classes"/>  
          <jar jarfile="${war.dir}/WEB-INF/lib/${name}.jar" compress="true" basedir="${build.dir}"/>  
          <copy todir="${war.dir}" preservelastmodified="true">  
              <fileset dir="${webcontent.dir}">  
                  <include name="**/**"/>  
                  <include name="**.**"/>  
              </fileset>  
          </copy>  
          <copy todir="${war.dir}/WEB-INF/classes" preservelastmodified="true">  
              <fileset dir="${src.dir}">  
                  <include name="*.xml"/>  
                  <include name="**/*.properties"/>  
                  <include name="**/*.vm"/>  
                  <exclude name="**/.*"/>  
              </fileset>  
          </copy>          
         
          <copy file="${war.dir}/WEB-INF/lib/${name}.jar" tofile="${client.dir}/${name}.jar"/>  
      </target>  
	  
      <target name="dist" depends="build" description="Build the web application archive">  
          <mkdir dir="${dist.dir}"/>  
          <war warfile="${dist.dir}/${name}.war" basedir="${war.dir}" webxml="${webcontent.dir}/WEB-INF/web.xml">  
              <include name="**/**"/>  
              <exclude name="WEB-INF/web.xml"/>  
          </war>  
      </target>  
      <target name="all" depends="clean,build,dist" description="Clean,build,dist"/>  
</project>