Apache Ant

Original author(s)| James Duncan Davidson
Developer(s)| Apache Software Foundation
Initial release| 19 July 2000; 25 years ago (2000-07-19)
Stable release|

1.10.15 / August 29, 2024; 20 months ago (2024-08-29)[1]

Repository| Ant Repository
Written in| Java
Platform| Java SE
Type| Build tool
License| Apache License 2.0

Apache Ant is a software tool for automating software build processes for Java applications[2] which originated from the Apache Tomcat project in early 2000 as a replacement for the Make build tool of Unix.[3] It is similar to Make, but is implemented using the Java language and requires the Java platform. Unlike Make, which uses the Makefile format, Ant uses XML to describe the code build process and its dependencies.[4]

Released under an Apache License by the Apache Software Foundation, Ant is an open-source project.

## Contents

* 1 History
* 2 Extensions
* 3 Example
* 4 Portability
* 5 Limitations
* 6 See also
* 7 References
* 8 Further reading
* 9 External links

## History

Ant ("Another Neat Tool")[5] was conceived by James Duncan Davidson while preparing Sun Microsystems's reference JSP and Servlet engine, later Apache Tomcat, for release as open-source. 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 [6] and Mutant by Conor MacNeill, none of which were able to find large acceptance with the developer community.[7]

At one time (2002), Ant was the build tool used by most Java development projects.[8] 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.

In 2004 Apache created a new tool with a similar purpose called Maven.

Gradle, which is similar software, was created in 2008, which in contrary uses Groovy (and a few other languages) code instead of XML.

## Extensions

WOProject-Ant[9] 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 suite.

`Antcontrib`[10] provides a collection of tasks such as conditional statements and operations on properties as well as other useful tasks.[11][12]

`Ant-contrib.unkrig.de`[13] implements tasks and types for networking, Swing user interfaces, JSON processing and other.

Other task extensions exist for Perforce, .NET Framework, EJB, and filesystem manipulations.[14]

## Example

A sample `build.xml` file is listed below for a simple Java "Hello, world" application. It defines four targets - `clean`,[15] `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>
<target name="clobber" depends="clean" description="remove all artifact files">
<delete file="hello.jar"/>
</target>
<target name="compile" description="compile the Java source code to class files">
<mkdir dir="classes"/>
<javac srcdir="." destdir="classes"/>
</target>
<target name="jar" depends="compile" description="create a Jar file for the application">
<jar destfile="hello.jar">
<fileset dir="classes" includes="**/*.class"/>
<manifest>
<attribute name="Main-Class" value="HelloProgram"/>
</manifest>
</jar>
</target>
</project>

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`:

<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. `<csv>`, `<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.

## Portability

Ant is intended to work with all systems for which Java runtimes are available. It is most commonly used with Windows, Linux, macOS and other Unix operating systems but has also been used on other platforms such as OS/2, OpenVMS, Solaris, HP-UX.[16]

Ant was designed to be more portable than Make.[4] Compared to Make, Ant uses less platform-specific shell 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-specific command unavailable in some other environments. Microsoft Windows, for example, would use:

rmdir /S /Q classes

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

<delete dir="classes"/>

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

This section possibly contains original research. Please improve it by verifying the claims made and adding inline citations. Statements consisting only of original research should be removed. (September 2011) (Learn how and when to remove this template message)

|

* Ant build files, which are written in XML, 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 `<javac>`, `<exec>` and `<java>`—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. `${unassigned.property}`).
* Ant has limited fault handling rules.
* Lazy property evaluation is not supported. For instance, when working within an Antcontrib `<for>` 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 integrated development environment (IDE) can build and execute Ant scripts, while the NetBeans 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, a JVM build tool built with Groovy

## References

1. ↑ "Apache Ant Project News". https://ant.apache.org/antnews.html.
2. ↑ "Apache Ant - Welcome". https://ant.apache.org/.
3. ↑ "Apache Ant - Frequently Asked Questions". https://ant.apache.org/faq.html#history.
4. ↑ 4.0 4.1 Moodie 2005, pp. 5–9, Chapter §1 Introducing Ant.
5. ↑ "Why do you call it Ant? – Apache Ant FAQ". https://ant.apache.org/faq.html#ant-name.
6. ↑ Peter Donald. "Myrmidon: The Ant2.0 Proposal".
7. ↑ MacNeill, Conor (4 August 2005). "The Early History of Ant Development". http://codefeed.com/blog/?p=98.
8. ↑ Wiley (2002). Java Tools for eXtreme Programming. p. 76.
9. ↑ "WOProject-Ant – WOProject / WOLips – Confluence". http://www.objectstyle.org/confluence/display/WOL/WOProject-Ant.
10. ↑ "Ant-Contrib". https://ant-contrib.sourceforge.net.
11. ↑ "Ant-Contrib Tasks". http://ant-contrib.sourceforge.net/tasks/tasks/index.html.
12. ↑ Moodie 2005, pp. 266–267, Chapter §10 Writing Custom Tasks - Using Third-Party Custom Tasks.
13. ↑ "ant-contrib.unkrig.de". http://ant-contrib.unkrig.de.
14. ↑ "Overview of Ant Tasks". https://ant.apache.org/manual/tasksoverview.html.
15. ↑ Moodie 2005, pp. 121–125, Chapter §5 Building a Project - Assembling the project - Manipulating the File Location.
16. ↑ Apache Ant Manual. Section "System Requirements".

## Further reading

* Loughran, Steve; Hatcher, Erik (July 12, 2007). Ant in Action (2nd ed.). Manning Publications. pp. 600. ISBN 978-1-932394-80-1.
* Holzner, Steven (April 13, 2005). Ant – The Definitive Guide (2nd ed.). O'Reilly Media. pp. 334. ISBN 978-0-596-00609-9. http://oreilly.com/catalog/9780596006099/.
* Moodie, Matthew (2005). Pro Apache Ant (1st ed.). Apress. ISBN 1-59059-559-9. https://archive.org/details/proapacheant0000mood/page/n1/mode/2up.
* Bell, Alexis T. (July 7, 2005). ANT Java Notes: An Accelerated Intro Guide to the Java ANT Build Tool (1st ed.). Virtualbookworm.com Publishing. pp. 268. ISBN 978-1-58939-738-5. http://www.virtualbookworm.com/mm5/merchant.mvc?Screen=PROD&Store_Code=bookstore&Product_Code=antjava.
* Hatcher, Erik; Loughran, Steve (August 2002). Java Development with Ant (1st ed.). Manning Publications. pp. 672. ISBN 978-1-930110-58-8. https://archive.org/details/javadevelopmentw0000hatc/page/672.
* Niemeyer, Glenn; Poteet, Jeremy (May 29, 2003). Extreme Programming with Ant: Building and Deploying Java Applications with JSP, EJB, XSLT, XDoclet, and JUnit (1st ed.). SAMS Publishing. pp. 456. ISBN 978-0-672-32562-5. http://www.informit.com/store/product.aspx?isbn=0672325624.
* Williamson, Alan (November 1, 2002). Ant – Developer's Handbook (1st ed.). SAMS Publishing. pp. 456. ISBN 978-0-672-32426-0. http://www.informit.com/store/product.aspx?isbn=0672324261.
* Matzke, Bernd (September 2003). ANT: The Java Build Tool In Practice (1st ed.). Charles River Media. pp. 280. ISBN 978-1-58450-248-7. https://archive.org/details/antjavabuildtool0000matz/page/280.

## External links

| Wikibooks has a book on the topic of: Apache Ant

|

* No URL found. Please specify a URL here or add one to Wikidata.

* v
* t
* e

Apache Software Foundation

Top-level
projects|

* Accumulo
* ActiveMQ
* Airflow
* Ambari
* Ant
* Apex
* Aries
* Apache HTTP Server
* APR
* Avro
* Axis
* Axis2
* Beam
* Bloodhound
* Brooklyn
* Buildr
* Calcite
* Camel
* CarbonData
* Cassandra
* Cayenne
* Chemistry
* CloudStack
* Cocoon
* Cordova
* CouchDB
* cTAKES
* CXF
* Derby
* Directory
* Drill
* Empire-db
* Felix
* Flex
* Flink
* Flume
* Forrest
* Geronimo
* Giraph
* Gump
* Hadoop
* Hama
* HBase
* Helix
* Hive
* Impala
* Jackrabbit
* James
* Jini
* JMeter
* Kafka
* Karaf
* Kudu
* Kylin
* Lucene
* Mahout
* Marmotta
* Maven
* MINA
* mod perl
* MyFaces
* NetBeans
* Nutch
* ODE
* OFBiz
* Oozie
* OpenEJB
* OpenJPA
* OpenNLP
* OрenOffice
* ORC
* PDFBox
* Parquet
* Phoenix
* POI
* Pig
* Pivot
* Qpid
* Roller
* RocketMQ
* Samza
* ServiceMix
* Shiro
* SINGA
* Sling
* Solr
* Spark
* Stanbol
* Storm
* SpamAssassin
* Sqoop
* Struts 1
* Struts 2
* Subversion
* SystemML
* Tapestry
* Thrift
* Tika
* Tomcat
* Trafodion
* Traffic Server
* UIMA
* Velocity
* Wicket
* Xalan
* Xerces
* Yetus
* ZooKeeper

Commons|

* BCEL
* BSF
* Daemon
* Jelly
* Logging

Incubator|

* MXNet
* Taverna
* XAP

Other projects|

* Batik
* Chainsaw
* FOP
* Ivy
* Log4j

Attic|

* Abdera
* AxKit
* Beehive
* Bluesky
* iBATIS
* Cactus
* Click
* Continuum
* Deltacloud
* Etch
* Excalibur
* Harmony
* HiveMind
* Jakarta
* Lenya
* Shale
* Shindig
* Slide
* stdcxx
* Tuscany
* Wave
* Wink
* XMLBeans

Licenses|

* Apache License

* Category

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Apache Ant. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Software:Apache_Ant&oldid=4140189"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template