Ant Destillate
- This is an extremely short quick introduction to Ant.
- This introduction assumes you are familiar with XML and Java and know how to adopt the examples for your needs.
- Further, this introduction assumes you are familiar with build automation in general.
Basics
- Ant is a build tool similar to Make.
- While the hierarchy of Make is target-file-commands, Ant's hierarchy is target-tasks-files.
Ant Fundamental Terms
- Project
- The document element of a build.xml describes a project.
- A project consists of one ore more targets.
- There's a default target.
- Target
- A target is a target in the build process, e.g. compile all sources.
- A target has a name.
- A target can depend on other targets that must be reached before the execution of this target.
- A target contains any amount of tasks.
- Task
- A task is a command unit of Ant.
- File based tasks often use filesets and this way process several files at once.
- Most file based tasks use source files and create destination files.
- Most file based tasks only create those destination files that aren't up to date by differing the time stamp between the source files and the destination files.
Installation of Ant and Libraries
- Extract Ant in the desired directory (e.g. /usr/dist/apache/ant)
- Set environment variable ANT_HOME to point to Ant's directory (e.g. export ANT_HOME=/usr/dist/apache/ant/ant1.5.1)
- Include Ant's bin directory in PATH (e.g. export PATH=$PATH:$ANT_HOME/bin)
- Copy or even better link the Jar archives of required libraries to $ANT_HOME/lib
Invocation of Ant
- Simple Invokation
ant (executes default target)- Invoke a specific target
ant target1 target2 (executes target1 and target2)- Print information about the build.xml used
ant -projecthelp
build.xml
Examples
Compilation of Java Sources
Create Documentation
Validate XML Files
When using document type definitions with external referenced entities from the Web it is recommended to create local copies of the external subset and all required files and use an XML Catalog:
Transformation using XSLT
Execute and Document Unit Tests with JUnit
The test classes are compiled with the normal classes. The names of the test classes end on "Test" (XYZText.java / XYZText.class).
Initialisation and Clean-Up of a Project and Updating Sandbox using CVS
These targets are well suited as depends entries at other targets.