Professional Documents
Culture Documents
ch
1/6
“Apache Ant is a Java-based build tool. In theory, it is kind of like Make, but without
Make's wrinkles.
Why another build tool when there is already make, gnumake, nmake, jam, and others?
Because all those tools have limitations that Ant's original author couldn't live with when
developing software across multiple platforms. Make-like tools are inherently shell-based
-- they evaluate a set of dependencies, then execute commands not unlike what you
would issue in a shell. This means that you can easily extend these tools by using or
writing any program for the OS that you are working on. However, this also means that
you limit yourself to the OS, or at least the OS type such as Unix, that you are working
on.” – Apache Ant developer team.
build tools
When developing a large scale project, the compilation, packaging and distribution
generation can become very time consuming. Build tools offer a way of expressing a set
of tasks which must be accomplished for a certain goal (e.g. documentation generation,
full project compilation, etc…), and to write these in a build file.
Tasks depend on other tasks so that an order of task execution can be computed
automatically (removing that burden off the programmers!). For instance, suppose we
want to generate a full distribution of a program, the set of tasks might be:
1 5
An XML dialect is composed of tags (a name surrounded by ‘<’ and ‘>’). Every tag must
be opened and closed:
<hello></hello>
or in short
<hello />
the space before the ‘/>’ construct is not mandatory, but I recommend to adopt this
convention. For a full explanation consult Java & XML [1].
<hello text="welcome">
<image path="pub/welcome.png" />
</hello>
Bear in mind that this is a very short introduction to XML, for more information, consult
the W3C Recommendations [2].
<?xml version="1.0"?>
<project name="Project Name" default="default target" basedir=".">
<description>Project description</description>
...
</project>
Where the first line is called the prolog (specifying which version of XML we are using).
The description is not mandatory but very strongly recommended.
javac
Compile a Java source tree.
Where srcdir is the source directory and destdir is the destination directory. Many
options are available.
javadoc
Generate the documentation from Java sources.
jar
Generates a jar file.
mkdir
Create a directory.
delete
Delete a file of a directory.
zip
Compress a set of files and creates a zip archive.
<zip destfile="${backup}/${project}-${DSTAMP}-${TSTAMP}.zip">
<zipfileset dir="${src}" prefix="src">
<include name="**/*" />
</zipfileset>
</zip>
Java programming course (SIN) Pascal Perez (IN) – pascal.perez@epfl.ch
4/6
In addition, the time stamp (<tstamp />) task declares the two properties ${DSTAMP}
and ${TSTAMP} which, by default, represent the day stamp in the yyyymmdd format and
the time stamp in the hhmm format.
<?xml version="1.0"?>
<project name="CirKuit 2D" default="compile" basedir=".">
<description>CirKuit 2D build file</description>
<!-- Compile the java code from ${src} into ${classes} -->
<target name="compile" depends="init"
description="Compile the project">
<javac srcdir="${src}" destdir="${classes}" />
</target>
$ ant
$ ant jar
$ ant doc
$ ant backup and
$ ant clean
Java programming course (SIN) Pascal Perez (IN) – pascal.perez@epfl.ch
6/6
ant - installation
First of all, you must download ant from the Apache Ant website [3] or from a mirror.
The binary distribution is easier to install… and the source distribution requires ant for its
build process!
Extract all files of the archive and place them in a “reasonable” directory (further
mentioned as installdir) for instance
To be able to use the binaries in the command prompt, you must add to the PATH
environment variable a path to installdir/bin and add a ANT_HOME variable.
bashrc
export ANT_HOME=installdir
export PATH=${PATH}:${ANT_HOME}/bin
cshrc
set ANT_HOME installdir
set PATH ${PATH}:${ANT_HOME}/bin
Windows
Start > Parameters > Control Panel System and open the “Advanced” tab. A button label
“environment variables” let’s you access the system’s environment’s variables.
bibliography
[1] McLaughlin, Brett. Java & XML. Trans. Alexandre Gachet. Paris: O’Reilly, 2002.
[2] “Extensible Markup Language (XML) 1.0 (Second Edition).” 6 October 2000
<http://www.w3.org/TR/2000/REC-xml-20001006>.