Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

Apache Ant - Tutorial

Lars Vogel

Version 1.0

11.12.2010

Revision History
Revision 0.130.11.2008Lars Vogel
Created
Revision 0.2 - 1.012.01.2009- 11.12.2010Lars Vogel
bugfixes and enhancements

Apache Ant Tutorial

This tutorial describes the usage of Ant as a build tool to compile Java code, pack this code into an executable jar and how to create Javadoc. The usage of Ant is demonstrated within Eclipse and from the command line. This tutorial is based on Apache Ant 1.8.x.


Table of Contents

1. Overview
2. Installation
2.1. Linux (Ubuntu / Debian)
2.2. Windows
3. Using Apache Ant
3.1. Overview
3.2. Create example Java project
3.3. Create build.xml
3.4. Run your Ant build from Eclipse
3.5. Run your Ant build from the command line
4. Apache Ant classpath
4.1. Setting the Ant classpath
4.2. Print
5. Running JUnit Tests via Ant
6. Subversion (svn) with Ant
7. Eclipse Ant Editor
8. Thank you
9. Questions and Discussion
10. Links and Literature
10.1. Source Code
10.2. General

1. Overview

Apache Ant (Another Neat Tool) is a build tool, mainly for Java projects. A build tool can be used to automate certain repetitive tasks, e.g. compiling source code, running software tests, creating jar files, javadocs, etc.

A build process typically includes:

  • the compilation of the Java source code into Java bytecode
  • creation of the .jar file for the distribution of the code
  • creation of the Javadoc documentation

Ant uses a xml file for its configuration. This file is usually called "build.xml". Within this build file you specify the targets for ant. A target is a step which ant will perform. You also can specific dependencies. If target A depends on target B, ant will first do B and then A. Also you specify the main target. This target is the target ant will try to execute per default. If this target depends on other targets then ant will automatically perform these task first and so on and so on.