Java Reference
In-Depth Information
won't get updates. You can also view or download individual files from the GitHub page via a
web browser.
Automating Compilation with Apache Ant
Problem
You get tired of typing javac and java commands.
Solution
Use the Ant program to direct your compilations.
Discussion
Ant is a pure Java solution for automating the build process. Ant is free software; it is avail-
able in source form or ready-to-run from the Apache Foundation's Ant website . Like make ,
Ant uses a file or files—Ant's are written in XML—listing what to do and, if necessary, how
to do it. These rules are intended to be platform-independent, though you can of course write
platform-specific recipes if necessary.
To use Ant, you must create a file specifying various options. This file should be called
build.xml ; if you call it anything else, you'll have to give a special command-line argument
every time you run Ant. Example 1-1 shows the build script used to build the files in the
starting directory. See Chapter 20 for a discussion of the syntax of XML. For now, note that
the <!-- begins an XML comment, which extends to the --> .
Example 1-1. Ant example file (build.xml)
<project name="Java Cookbook Examples" default="compile" basedir=".">
<!-- Set global properties for this build -->
<property name="src" value="."/>
<property name="build" value="build"/>
<!-- Specify the compiler to use. -->
<property name="build.compiler" value="modern"/>
<target name="init">
Search WWH ::




Custom Search