Apache Ant - SPLessons


Chapter 8

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks



shape Introduction

Basically, when a project is build, a lot of configurations are required like creating a folder structure, copying jar into respective folder and many more. These configurations can be done by ANT Build XML in one shot by using build.xml.

shape Description

Now, start building a skeleton build file for the project. Endtoendskeleton.xml is the build file(so called build.xml) for this project. This file should be always in parallel to the src file.

shape Conceptual

shape Examples


<?xml version="1.0" encoding="UTF-8"?>
<project name="End to End Build" default="sendmail" basedir=".">
    <target name="init">
        <tstamp />
        <property file="build.properties" />
    <target name="startrecorder"></target>
    <target name="prepare" depends="init, startrecorder">
        <mkdir dir="${build.dir.classes}" />
        <mkdir dir="${reports.dir}" />
    <target name="fetch" depends="init"></target>
    <target name="compile" depends="prepare, fetch"></target>
    <target name="test" depends="compile">
        <junit failureproperty="testsFailed" />
    <target name="war" depends="test" unless="testsFailed"></target>
    <target name="deploy" depends="war" unless="testsFailed"></target>
    <target name="stoprecorder"></target>
    <target name="sendmail" depends="deploy, stoprecorder"></target>
    <target name="clean" depends="init">
        <delete dir="${build.dir}" />
        <delete dir="${reports.dir}" />
  • In the project tag of the above build file, the current directory is specified as the base directory, name of project and default task defines the last task performed and sends the mail. All other tasks are executed without depending on each other.
  • The first task called is the init task in which required properties will be defined for the entire build. The timestamp will be defined in init for capturing the date of execution.
  • Then the property file called build.properties is loaded using property task defines all build properties.
  • Next, recorder starts as soon as you log in. Then, the prepare target creates new directories.
  • After creation, the build process starts by fetching the source code from CVS.Then building war file depends on testing the project. If the test is passed, the war file can be deployed to remote server.
  • After deploying, zip the files and attach them to the mails and send. This process depends on deploy and stop recorder, which stops the logging process.
  • One can clean the directories using clean targets.


shape Key Points

  • build.xml file configures all the activities done by ANT.