The Full Wiki

Apache Ant: Wikis


Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.


From Wikipedia, the free encyclopedia

Apache Ant (Another Neat Tool)
Apache Ant Logo
Developer(s) Apache Software Foundation
Stable release 1.7.1 / 2008-06-27; 18 months ago
Written in Java
Operating system Cross-platform
Type Build Tool
License Apache License 2.0

Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects.

The most immediately noticeable difference between Ant and Make is that Ant uses XML to describe the build process and its dependencies, whereas Make has its Makefile format. By default the XML file is named build.xml.

Ant is an Apache project. It is open source software, and is released under the Apache Software License.



Ant was conceived by James Duncan Davidson while turning a product from Sun into open source. That product, Sun's reference JSP/Servlet engine, later became Apache Tomcat. A proprietary version of make was used to build it on the Solaris Operating Environment, but in the open source world there was no way of controlling which platform was used to build Tomcat. Ant was created as a simple platform-independent tool to build Tomcat from directives in an XML "build file". From this humble beginning, the tool has gone on to become more widespread than the Tomcat product for which it was created. Ant (version 1.1) was officially released as a stand-alone product on July 19, 2000. Today, Ant is the build tool used by most Java development projects [1]. For example, most open source developers include build.xml files with their distribution.

Because Ant made it trivial to integrate JUnit tests with the build process, Ant has made it easy for willing developers to adopt test-driven development, and even Extreme Programming.

Other Java-based build tools include Maven and JavaMake.[2]

The name is an acronym for "Another Neat Tool".[3]

Sample build.xml file

Below is listed a sample build.xml file for a simple Java "Hello, world" application. It defines four targets - clean, clobber, compile and jar, each of which has an associated description. The jar target lists the compile target as a dependency. This tells Ant that before it can start the jar target it must first complete the compile target.

<?xml version="1.0"?>
<project name="Hello" default="compile">
    <target name="clean" description="remove intermediate files">
        <delete dir="classes"/>
    <target name="clobber" depends="clean" description="remove all artifact files">
        <delete file="hello.jar"/>
    <target name="compile" description="compile the Java source code to class files">
        <mkdir dir="classes"/>
        <javac srcdir="." destdir="classes"/>
    <target name="jar" depends="compile" description="create a Jar file for the application">
        <jar destfile="hello.jar">
            <fileset dir="classes" includes="**/*.class"/>
                <attribute name="Main-Class" value="HelloProgram"/>

Within each target are the actions that Ant must take to build that target; these are performed using built-in tasks. For example, to build the compile target Ant must first create a directory called classes (Ant will only do so if it does not already exist) and then invoke the Java compiler. Therefore, the tasks used are mkdir and javac. These perform a similar task to the command-line utilities of the same name.

Another task used in this example is named jar:

 <jar destfile="hello.jar">

This ant task has the same name as the common java command-line utility, JAR, but is really a call to the ant program's built-in jar/zip file support. This detail is not relevant to most end users, who just get the JAR they wanted, with the files they asked for.

Many Ant tasks delegate their work to external programs, either native or Java. They use Ant's own <exec> and <java> tasks to set up the command lines, and handle all the details of mapping from information in the build file to the program's arguments -and interpreting the return value. Users can see which tasks do this (e.g. <cvs>, <signjar>, <chmod>, <rpm>), by trying to execute the task on a system without the underlying program on the path, or without a full Java Development Kit (JDK) installed.


WOProject-Ant[4] is just one of many examples of a task extension written for Ant. These extensions are put to use by copying their jar files into ant's lib directory. Once this is done, these extension tasks can be invoked directly in the typical build.xml file. The WOProject extensions allow WebObjects developers to use ant in building their frameworks and applications, instead of using Apple's Xcode suite.

Antcontrib[5] provides a collection of tasks such as conditional statements and operations on properties as well as other useful tasks.[6]

Other task extensions exist for Perforce, .Net, EJB, and filesystem manipulations, just to name a few.[7]


One of the primary aims of Ant was to solve make's portability problems. In a Makefile the actions required to create a target are specified as shell commands which are specific to the current platform, usually a Unix shell. Ant solves this problem by providing a large amount of built-in functionality which it can then guarantee will behave (nearly) identically on all platforms.

For example, in the sample build.xml file above the clean target deletes the classes directory and everything in it. In a Makefile this would typically be done with the command:

rm -rf classes/

rm is a Unix specific command which will probably not be available if the Makefile is used in a non-Unix environment such as Microsoft Windows which would use:

rmdir /S /Q classes

In an Ant build file the same thing would be accomplished using a built in command:

 <delete dir="classes"/>

A common discrepancy between different platforms is the way in which directory paths are specified. Unix uses a forward slash (/) to delimit the components of a path, whereas Windows uses a backslash (\). Ant build files let authors choose their favorite convention, forward slashes or back slashes for directories, semicolon or colon for path separators. It converts everything to the appropriate format for the current platform.


  • Ant build files are written in XML. For unfamiliar users, both XML itself and the complex structure (hierarchical, partly ordered, and pervasively cross-linked) of Ant documents can be a barrier to learning. A GUI called Antidote was available for a time, but never gained a following and has been retired from the Apache project. Moreover, the language of Ant is quite verbose, and the build files of large or complex projects become unmanageably large. Good design and modularization of build files can improve readability but not reduce size. Other build tools like Maven use more concise scripts at the expense of generality and flexibility.
  • Many of the older tasks—the core ones that are used every day, such as <javac>, <exec> and <java>—use default values for options that are not consistent with more recent tasks. Changing those defaults would break existing tasks.
  • When expanding properties in a string or text element, undefined properties are not raised as an error, but left as an unexpanded reference (e.g. ${}).
  • Ant has limited fault handling rules, and no persistence of state, so it cannot be used as a workflow tool for any workflow other than classic build and test processes.
  • The Ant target model does not treat artifacts as targets. In most build tools a target is an artifact created by the build—a program, library, intermediate object file, PDF documentation, etc.—and rules specify the dependencies between targets and the tasks to run to build a target when it is out of date. In Ant a target is a group of tasks rather than an artifact. This means that Ant is sometimes unable to determine the relationship between an artifact and the task sequence to build the artifact and this logic must be implemented by the programmer using Ant's control structures.
  • Once a property is defined it cannot be changed by any of the core tasks. Antcontrib provides a variable task to go around this problem.
  • Lazy property evaluation is not supported. For instance, when working within a <for> loop, a property cannot be re-evaluated for a sub-value which may be part of the iteration.
  • Reuse of build file fragment is hard. Ant 1.6 made it easier, with <import> and <macrodef>, which some might argue creates even more complexity for new Ant users.
  • In makefiles, any rule to create one file type from another file type can be written inline within the makefile. For example, you may transform a document into some other format by using rules to execute another tool. Creating a similar task in ant is both more powerful and complex. A separate task must be written in Java and included with the ant build file in order to handle the same type of functionality. This also enhances the readability of the build file by hiding some of the details of how a task is executed on each platform.

Some of these limitations may not apply on the most recent Ant versions. Also NetBeans IDE uses Ant for its build system, which greatly simplifies Ant use within the IDE (Ant scripts generated by NetBeans can be used outside of the IDE).



See also

External links


Study guide

Up to date as of January 14, 2010

From Wikiversity

[Ant] is a tool used to build and deploy software.




Up to date as of January 23, 2010

From Wikibooks, the open-content textbooks collection

Apache Ant (or simply Ant) is an XML-based build scripting language used heavily by the Open Source community. Ant automates tasks such as compiling source code, building deployment packages and automatically checking dependencies of what items need to be updated in a build set.


This wikibook was based on a presentation created by Dan McCreary for the Minnesota Java Open Source User Group. Dan felt strongly that a gentle introduction to Ant was necessary for new people to easily learn Ant. The existing Ant documentation, although useful for advanced Ant users, did not meet the needs of most beginners. For example in the Apache documentation, advanced concepts such as token filters were placed directly in the introduction for beginners. The introductory material also did not contain full examples with complete sample build files and expected output. Something else was needed. At the same time the introductory material assumed that the reader was familiar with XML. This material covers some of the material you need to know about XML to build Ant scripts.

This Wikibook is also designed to work with other XML-related programming wikibooks such as XML Schema and XForms.

Book Structure

This document has an introduction page for people just getting started. Mostly hello world information to get a flavor for what Ant is and how it is used. At the end there are six sections:

  1. Introduction
    1. Background - History and motivation for Apache Ant Development stage: 100% (as of Sept 6th, 2006)
    2. Adoption - How and why organizations should adopt Apache Ant Development stage: 100% (as of Sept 6th, 2006)
    3. XML Summary - A short review of XML syntax for people that are not familiar with XML. This section can easily be skipped by users that already know about XML file structure. Development stage: 100% (as of Sept 6th, 2006)
  2. Getting Started
    1. Installation How to download and install Apache Ant Development stage: 100% (as of Sept 6th, 2006)
    2. Testing How to test Apache Ant Development stage: 100% (as of Sept 6th, 2006)
    3. Hello World How to run a small ant program that prints "Hello World!" Development stage: 100% (as of Sept 6th, 2006)
  3. Core Concepts - Core Terms and Concepts useful to Ant developers
    1. Terminology - Terminology (projects, targets and tasks) Development stage: 100% (as of Sept 6th, 2006)
    2. Build File Structure- The structure of a build file Development stage: 75% (as of Sept 6th, 2006)
    3. Using Properties Property Development stage: 100% (as of Sept 6th, 2006)
    4. Depends Setting up Dependencies Development stage: 100% (as of Sept 6th, 2006)
    5. Fileset Using Fileset Development stage: 100% (as of Sept 6th, 2006)
  4. Ant Best Practices - Best practices such as how to set up an Ant file Development stage: 100% (as of Sept 6th, 2006)
    1. Standard Targets - A list of standard targets such as init and clean Development stage: 100% (as of Sept 6th, 2006)
    2. Local Property Files - how to use a local property file Development stage: 100% (as of Sept 6th, 2006)
    3. Local File Systems - removing local file system dependencies
  5. Ant Cookbook - A set of small complete working example programs that demonstrate examples of how to use Apache Ant
    1. Depends - shows how to use the targets depends attribute Development stage: 100% (as of Sept 6th, 2006)
    2. Property - shows how to use an Ant property Development stage: 100% (as of Sept 6th, 2006)
    3. Fileset - shows how to use an Ant fileset Development stage: 100% (as of Sept 6th, 2006)
    4. XML - how Ant can be used to process XML documents Development stage: 100% (as of Sept 6th, 2006)
      1. XMLwellformed - how to use Apache ant to check an XML file for well formedness Development stage: 100% (as of Sept 6th, 2006)
      2. XMLvalidate - how to use Apache ant to validate an XML file agains an XML Schema Development stage: 100% (as of Sept 6th, 2006)
      3. XSLT - how to use Apache ant to run an XML transform Development stage: 100% (as of Sept 6th, 2006)
      4. Passing Parameters to XSLT - How to pass parameters to an XSLT transform from Apache Ant Development stage: 50% (as of Sept 6th, 2007)
  6. References - where to get more information on Apache Ant Development stage: 25% (as of Sept 6th, 2006)

See Also


Got something to say? Make a comment.
Your name
Your email address