Automating Compilation with Ant
Problem
You get tired of typing javac and java commands.
Solution
Use the Ant program to direct your compilations.
Discussion
The intricacies of makefiles and their importabilities have led to the development of a pure-Java solution for automating the build process. Ant is free software; it is available in source form or ready-to-run from the Apache Foundation’s Jakarta project web site, at http://jakarta.apache.org/ant/. Like make, Ant uses a file or files -- 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 15-30 line 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 arguments every time
you run Ant. Example 1-1 shows the build script used
to build the files in the starting directory.
See Section 21.1 for discussion of the XML syntax.
For now, note that the <!- - tag begins an
XML comment, which extends to the - -> tag.
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. Using jikes is supported but requires rt.jar in classpath. --> <property name="build.compiler" value="modern"/> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access