Java Reference
In-Depth Information
Let me start with a “Hello, World” example in the next listing, based on a sample from the
Ant tutorial provided by Apache at the Ant website.
Listing 5.1. build.xml: A simple Ant build file for a “Hello, World” Java application
<project name="HelloWorld" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="mjg.HelloWorld"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}"
includeantruntime="false"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar"
basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
</project>
By default, this file is called build.xml and resides in the root directory of the project. The
root element of the project file is called <project> , which is given a name , a base dir-
ectory, and the name of a default task to run if none is supplied on the command line.
 
Search WWH ::




Custom Search