Java Reference
In-Depth Information
You want to be able to compile your Java source files and clean the build
directories. You will set up a simple build.xml file to describe these tasks, as
shown in listing B.1. Place this file in the location in which you will run Ant.
Listing B.1
build.xml
<project name="JMXBook" default="compile" basedir=".">
<!-- set global properties for this build -->
<property name="src" value="."/>
<property name="build" value="build"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<!-- ============[ Compile the Build ]=============== -->
<target name="compile" depends="init">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" />
</target>
<!-- ============[ Compile the Build ]=============== -->
<!-- =============[ Clean the Installation ]=============== -->
<target name="clean">
<!-- Delete the ${build} directory trees -->
<delete dir="${build}"/>
</target>
<!-- =============[ Clean the Build ]=============== -->
</project>
When invoked, Ant will examine this XML file to perform the tasks being asked
of it. The next two sections will walk you through the important parts of the XML
file so you can tailor it to your specific environment.
B.2.1
Compiling
The first element of the XML file, <project> , describes the project related to this
XML file. In this case, you define the project as the JMXBook project. This element
also lets you indicate that Ant should run the compile directive by default. So,
you can just type Ant at the command line, and the compile section of the XML
will be executed.
Search WWH ::




Custom Search