Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects.The most immediately noticeable difference between Ant and Make is that Ant uses XML to describe the build process and its dependencies, whereas Make uses Makefile format. By default the XML file is named build.xml.
Sample build.xml file
Below is listed a sample build.xml file for a simple Java "Hello, world" application.
It defines four targets - clean, clobber, compile and jar, each of which has an associated description.
The jar target lists
the compile target as a dependency.
This tells Ant that before it can start the jar target it must first complete the compile target. Within each target are the actions that Ant must take to build that target; these are performed using built in tasks. For example, to build the compile target Ant must first create a directory called Classes. (Ant will only do so if it doesn't already exists) and then invoke java compiler. Therefore, the tasks used are mkdir and javac. These perform a similar task to the command line utilities of the same name.
<?xml version="1.0"?>
<project name="Hello" default="compile">
<target name="clean" description="remove intermediate files">
<delete dir="classes"/>
</target>
<target name="clobber" depends="clean" description="remove all artifact files">
<delete file="hello.jar"/>
</target>
<target name="compile" description="compile the Java source code to class files">
<mkdir dir="classes"/>
<javac srcdir="." destdir="classes"/>
</target>
<target name="jar" depends="compile" description="create a Jar file for the application">
<jar destfile="hello.jar">
<fileset dir="classes" includes="**/*.class"/>
<manifest>
<attribute name="Main-Class" value="HelloProgram"/>
</manifest>
</jar>
</target>
</project>
