The <project> element is the root element in Ant build files. The name attribute of the project element indicates the project name. Each project element can contain multiple <target> elements.
A target represents a single stage in the build process. A build process can have multiple targets. Here we have two targets compile and compress.
The default attribute of project element indicates the default target to be executed. Here the default target is compress.
When you see the compress target, it in turn depends on the compile target, that is indicated by the depends attribute. So the compile target will be executed first.
The compile target has two task elements <javac> and <echo>. The javac task is used to compile the java files. The attribute srcdir="." indicates all the java files in the current directory. Echo task is used to display message on the console.
The compress target also performs two tasks, first the <jar> element as the name indicates, is used to build the jar file. The attributes destfile="HelloWorld.jar" , basedir="." and includes="*.class" indicates all the .class files in the current directory should be compressed into HelloWorld.jar file. Later the echo task is used to display the success message on the console.
To run the build.xml file, open the command prompt, go to the example directory, type the command "ant". You will see the following information.