The following example build file follows these guidelines. This build file would be stored on disk as "MyProject.xml".
<project name="MyProject" default="dist" basedir="."> <description> simple example build file </description> <!-- set global properties for this build --> <!-- where the source files are --> <property name="src" location="src"/> <!-- where the compiled classes go --> <property name="build" location="build"/> <!-- where to place the finished jar file --> <property name="dist" location="dist"/> <!-- ========== Dist Target =================================== The dist target compiles all the source code and creates a jar file for distribution. --> <target name="dist" depends="clean, compile" description="generate the distribution" > <!-- Create the distribution directory --> <mkdir dir="${dist}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/> </target> <!-- ========== Init Target ==================================== This target initializes the build by creating a time stamp for use in the jar file name and creating the directory to hold the compiled classes. --> <target name="-init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <mkdir dir="${build}"/> </target> <!-- ========== Compile Target ================================= The compile target compiles all files in the source directory into the build directory. --> <target name="compile" depends="-init" description="compile the source " > <!-- Compile the java code from ${src} into ${build} --> <javac srcdir="${src}" destdir="${build}"/> </target> <!-- ========== Clean Target ==================================== The clean target deletes all files from the build directory and the dist directory. --> <target name="clean" description="clean up" > <!-- Delete the ${build} and ${dist} directory trees --> <delete dir="${build}"/> <delete dir="${dist}"/> </target> </project>