Apache Ant

Last updated
Apache Ant
Original author(s) James Duncan Davidson
Developer(s) Apache Software Foundation
Initial release19 July 2000;23 years ago (2000-07-19)
Stable release
1.10.14 / August 20, 2023;6 months ago (2023-08-20) [1]
Repository Ant Repository
Written in Java
Platform Java SE
Type Build tool
License Apache License 2.0
Website ant.apache.org   OOjs UI icon edit-ltr-progressive.svg

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]

Contents

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

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.[ citation needed ] 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

Below is listed a sample build.xml file 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"?><projectname="Hello"default="compile"><targetname="clean"description="remove intermediate files"><deletedir="classes"/></target><targetname="clobber"depends="clean"description="remove all artifact files"><deletefile="hello.jar"/></target><targetname="compile"description="compile the Java source code to class files"><mkdirdir="classes"/><javacsrcdir="."destdir="classes"/></target><targetname="jar"depends="compile"description="create a Jar file for the application"><jardestfile="hello.jar"><filesetdir="classes"includes="**/*.class"/><manifest><attributename="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:

<jardestfile="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:

<deletedir="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

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

Related Research Articles

JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development, and is one of a family of unit testing frameworks which is collectively known as xUnit that originated with SUnit.

Jakarta Server Pages is a collection of technologies that helps software developers create dynamically generated web pages based on HTML, XML, SOAP, or other document types. Released in 1999 by Sun Microsystems, JSP is similar to PHP and ASP, but uses the Java programming language.

In software development, Make is a build automation tool that builds executable programs and libraries from source code by reading files called makefiles which specify how to derive the target program. Though integrated development environments and language-specific compiler features can also be used to manage a build process, Make remains widely used, especially in Unix and Unix-like operating systems.

<span class="mw-page-title-main">Apache Tomcat</span> Java-based HTTP web server environment

Apache Tomcat is a free and open-source implementation of the Jakarta Servlet, Jakarta Expression Language, and WebSocket technologies. It provides a "pure Java" HTTP web server environment in which Java code can also run. Thus it is a Java web application server, although not a full JEE application server.

<span class="mw-page-title-main">JAR (file format)</span> Java archive file format

A JAR file is a package file format typically used to aggregate many Java class files and associated metadata and resources into one file for distribution.

<span class="mw-page-title-main">Apache Groovy</span> Programming language

Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk. It can be used as both a programming language and a scripting language for the Java Platform, is compiled to Java virtual machine (JVM) bytecode, and interoperates seamlessly with other Java code and libraries. Groovy uses a curly-bracket syntax similar to Java's. Groovy supports closures, multiline strings, and expressions embedded in strings. Much of Groovy's power lies in its AST transformations, triggered through annotations.

Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. The Maven project is hosted by The Apache Software Foundation, where it was formerly part of the Jakarta Project.

In software engineering, a WAR file is a file used to distribute a collection of JAR-files, JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static web pages and other resources that together constitute a web application.

<span class="mw-page-title-main">CMake</span> Cross-platform, compiler-independent build system generator

In software development, CMake is cross-platform free and open-source software for build automation, testing, packaging and installation of software by using a compiler-independent method. CMake is not a build system itself; it generates another system's build files. It supports directory hierarchies and applications that depend on multiple libraries. It can invoke native build environments such as Make, Qt Creator, Ninja, Android Studio, Apple's Xcode, and Microsoft Visual Studio. It has minimal dependencies, requiring only a C++ compiler on its own build system.

Microsoft Build Engine, or MSBuild, is a set of free and open-source build tools for managed code under the Common Language Infrastructure as well as native C and C++ code. It was first released in 2003 and was a part of .NET Framework. MSBuild is included with Visual Studio, but can also be run independently through MSBuild's command-line interface.

Classpath is a parameter in the Java Virtual Machine or the Java compiler that specifies the location of user-defined classes and packages. The parameter may be set either on the command-line, or through an environment variable.

Build automation is the process of automating the creation of a software build and the associated processes including: compiling computer source code into binary code, packaging binary code, and running automated tests.

Judoscript is a general purpose programming language designed primarily for scripting tasks on the Java platform. It was conceived and developed by James Jianbo Huang, starting in late 2001. Judoscript was one of the first so-called Java scripting languages; but its most striking characteristics is its audacious multi-domain support philosophy and practice.

The Android SDK is a software development kit for the Android software ecosystem that includes a comprehensive set of development tools. These include a debugger, libraries, a handset emulator based on QEMU, documentation, sample code, and tutorials. The SDK is part of the official Android Studio IDE but its various tools and resources can be used independently.

The Java Development Kit (JDK) is a distribution of Java technology by Oracle Corporation. It implements the Java Language Specification (JLS) and the Java Virtual Machine Specification (JVMS) and provides the Standard Edition (SE) of the Java Application Programming Interface (API). It is derivative of the community driven OpenJDK which Oracle stewards. It provides software for working with Java applications. Examples of included software are the Java virtual machine, a compiler, performance monitoring tools, a debugger, and other utilities that Oracle considers useful for Java programmers.

Java code coverage tools are of two types: first, tools that add statements to the Java source code and require its recompilation. Second, tools that instrument the bytecode, either before or during execution. The goal is to find out which parts of the code are tested by registering the lines of code executed when running a test.

<span class="mw-page-title-main">Bazel (software)</span> Software tool that automates software builds and tests

Bazel is a free and open-source software tool used for the automation of building and testing software. Google uses the build tool Blaze internally and released an open-sourced port of the Blaze tool as Bazel, named as an anagram of Blaze. Bazel was first released in March 2015 and was in beta status by September 2015. Version 1.0 was released in October 2019.

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file. Grunt was created by Ben Alman and is written in Node.js. It is distributed via npm. As of October 2022, there were more than 6,000 plugins available in the Grunt ecosystem.

References

  1. "Apache Ant Project News" . Retrieved 30 August 2023.
  2. "Apache Ant - Welcome". ant.apache.org. Retrieved 2022-01-25.
  3. "Apache Ant - Frequently Asked Questions". ant.apache.org. Retrieved 2022-01-25.
  4. 1 2 Moodie 2005, pp. 5–9, Chapter §1 Introducing Ant.
  5. "Why do you call it Ant? – Apache Ant FAQ".
  6. Peter Donald. "Myrmidon: The Ant2.0 Proposal".
  7. MacNeill, Conor (4 August 2005). "The Early History of Ant Development".
  8. Wiley (2002). Java Tools for eXtreme Programming. p. 76.
  9. "WOProject-Ant – WOProject / WOLips – Confluence". Archived from the original on 2009-01-08.
  10. "Ant-Contrib".
  11. "Ant-Contrib Tasks".
  12. Moodie 2005, pp. 266–267, Chapter §10 Writing Custom Tasks - Using Third-Party Custom Tasks.
  13. "ant-contrib.unkrig.de".
  14. "Overview of Ant Tasks".
  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