Apache Ant is a software tool for
automating software build processes for Java applications which originated from the
Apache Tomcat project in early 2000 as a replacement for the
Make build tool of
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
. It is similar to Make, but is implemented using the
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
language and requires the Java platform. Unlike Make, which uses the
Makefile format, Ant uses
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
to describe the code build process and its dependencies.
Released under an
Apache License
The Apache License is a permissive free software license written by the Apache Software Foundation (ASF). It allows users to use the software for any purpose, to distribute it, to modify it, and to distribute modified versions of the software ...
by the
Apache Software Foundation
The Apache Software Foundation ( ; ASF) is an American nonprofit corporation (classified as a 501(c)(3) organization in the United States) to support a number of open-source software projects. The ASF was formed from a group of developers of the ...
, Ant is an
open-source project.
History
Ant ("Another Neat Tool") was conceived by James Duncan Davidson while preparing
Sun Microsystems
Sun Microsystems, Inc., often known as Sun for short, was an American technology company that existed from 1982 to 2010 which developed and sold computers, computer components, software, and information technology services. Sun contributed sig ...
's
reference
A reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''nam ...
JSP and
Servlet engine, later
Apache Tomcat, for release as
open-source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
. A
proprietary version of Make was used to build it on the
Solaris platform, but in the open-source world, there was no way of controlling which platform was used to build Tomcat; so Ant was created as a simple
platform-independent tool to build Tomcat from directives in an XML "build file". Ant (version 1.1) was officially released as a stand-alone product on July 19, 2000.
Several proposals for an Ant version 2 have been made, such as AntEater by James Duncan Davidson, Myrmidon by Peter Donald and Mutant by Conor MacNeill, none of which were able to find large acceptance with the developer community.
At one time (2002), Ant was the build tool used by most Java development projects. For example, most open source Java developers included
build.xml
files with their distribution. Because Ant made it trivial to integrate
JUnit tests with the build process, Ant allowed developers to adopt
test-driven development and
extreme programming
Extreme programming (XP) is a software development methodology intended to improve software quality and responsiveness to changing customer requirements. As a type of agile software development,"Human Centred Technology Workshop 2006 ", 2006, ...
.
In 2004 Apache created a new tool with a similar purpose called
Maven.
Gradle
Gradle is a build automation tool for multi-language software development. It manages tasks like compilation, packaging, testing, deployment, and publishing. Supported languages include Java (as well as JDK-based languages Kotlin, Groovy, Sc ...
, which is similar software, was created in 2008, which in contrary uses
Groovy
''Groovy'' (or, less commonly, ''groovie'' or ''groovey'') is a slang colloquialism popular during the 1960s and 1970s. It is roughly synonymous with words such as "excellent", "fashionable", or "amazing", depending on context.
History
The word ...
(and a few other languages) code instead of XML.
Extensions
WOProject-Ant is just one of many examples of a task extension written for Ant. These extensions are installed by copying their
.jar
files into ant's
lib
directory. Once this is done, these task extensions can be invoked directly in the typical
build.xml
file. The WOProject extensions allow
WebObjects developers to use ant in building their frameworks and apps, instead of using
Apple's Xcode
Xcode is a suite of developer tools for building apps on Apple devices. It includes an integrated development environment (IDE) of the same name for macOS, used to develop software for macOS, iOS, iPadOS, watchOS, tvOS, and visionOS. It w ...
suite.
Antcontrib
provides a collection of tasks such as conditional statements and operations on properties as well as other useful tasks.
Ant-contrib.unkrig.de
implements tasks and types for networking,
Swing user interfaces,
JSON
JSON (JavaScript Object Notation, pronounced or ) is an open standard file format and electronic data interchange, data interchange format that uses Human-readable medium and data, human-readable text to store and transmit data objects consi ...
processing and other.
Other task extensions exist for
Perforce,
.NET Framework,
EJB, and filesystem manipulations.
Example
A sample
build.xml
file is listed below 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.
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
(which Ant will do only 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
:
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 and 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. , , , ), 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.
Portability
Ant is intended to work with all systems for which Java runtimes are available. It is most commonly used with
Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
,
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
,
macOS
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
and other
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
operating systems but has also been used on other platforms such as OS/2, OpenVMS,
Solaris, HP-UX.
[
Apache Ant Manual.
Sectio]
"System Requirements"
Ant was designed to be more portable than Make. Compared to Make, Ant uses less platform-specific
shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
Science Biology
* Seashell, a hard outer layer of a marine ani ...
commands. Ant provides built-in functionality that is designed to behave the same 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
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
-specific command unavailable in some other environments.
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
, for example, would use:
rmdir /S /Q classes
In an Ant build file the same goal would be accomplished using a built-in command:
Additionally, Ant does not differentiate between forward slash or backslash for directories and semicolon or colon for path separators. It converts each to the symbol appropriate to the platform on which it executes.
Limitations
*Ant build files, which are written in
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
, can be complex and verbose, as they are hierarchical, partly ordered, and pervasively cross-linked. This complexity can be a barrier to learning. The build files of large or complex projects can become unmanageably large. Good design and modularization of build files can improve readability but not necessarily reduce size.
*Many of the older tasks, such as , and —use default values for options that are not consistent with more recent versions of the tasks. Changing those defaults would break existing Ant scripts.
*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.
*
Lazy property evaluation is not supported. For instance, when working within an Antcontrib loop, a property cannot be re-evaluated for a sub-value which may be part of the iteration. (Some third-party extensions facilitate a workaround; AntXtras flow-control tasksets do provide for cursor redefinition for loops.)
*In makefiles, any rule to create one file type from another can be written inline within the makefile. For example, one may transform a document into some other format by using rules to execute another tool. Creating a similar task in Ant is more 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. However, this separation can enhance the readability of the Ant script by hiding some of the details of how a task is executed on different platforms.
There exist third-party Ant extensions (called ''antlibs'') that provide much of the missing functionality. Also, the
Eclipse
An eclipse is an astronomical event which occurs when an astronomical object or spacecraft is temporarily obscured, by passing into the shadow of another body or by having another body pass between it and the viewer. This alignment of three ...
integrated development environment
An integrated development environment (IDE) is a Application software, software application that provides comprehensive facilities for software development. An IDE normally consists of at least a source-code editor, build automation tools, an ...
(IDE) can build and execute Ant scripts, while the
NetBeans
NetBeans is an integrated development environment (IDE) for Java (programming language), Java. NetBeans allows applications to be developed from a set of modular software components called ''modules''. NetBeans runs on Microsoft Windows, Windows, ...
IDE uses Ant for its internal build system. As both these IDEs are very popular development platforms, they can simplify Ant use significantly. (As a bonus, Ant scripts generated by NetBeans can be used outside that IDE as standalone scripts.)
See also
*
Build automation
**
List of build automation software
*
Apache Jelly, a tool for turning XML into executable code
*
Apache Ivy, a dependency manager which integrates tightly with Ant, subproject of Ant
*
Apache Maven, a project management and build automation tool primarily for Java
*
NAnt, Ant-like tool targeted at the .NET Framework environment rather than Java
*
Gradle
Gradle is a build automation tool for multi-language software development. It manages tasks like compilation, packaging, testing, deployment, and publishing. Supported languages include Java (as well as JDK-based languages Kotlin, Groovy, Sc ...
, a JVM build tool built with Groovy
References
Further reading
*
*
*
*
*
*
*
*
External links
*
{{Authority control
Ant
Ants are Eusociality, eusocial insects of the Family (biology), family Formicidae and, along with the related wasps and bees, belong to the Taxonomy (biology), order Hymenoptera. Ants evolved from Vespoidea, vespoid wasp ancestors in the Cre ...
Build automation
Compiling tools
Cross-platform free software
Free software programmed in Java (programming language)
Java (programming language) libraries
Java development tools
Software using the Apache license
XML software