Apache Ant

Apache Ant

Infobox Software
name = Apache Ant (Another Neat Tool)



caption =
developer = Apache Software Foundation
latest release version = 1.7.1
latest release date = June 27, 2008
latest preview version =
latest preview date =
operating system = Cross-platform
programming language = Java
genre = Build Tool
license = Apache License 2.0
website = http://ant.apache.org

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.

History

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 - and perhaps more successful - 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. It has become the underpinning of open source Java; developers expect a "build.xml" file with every project.

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. [ [http://www.experimentalstuff.com/Technologies/JavaMake/ experimentalstuff.com: A Make Tool for the Java™ Language ] ]

The name is an acronym for "Another Neat Tool". [ [http://ant.apache.org/faq.html#ant-name "Why do you call it Ant?"] , Apache Ant FAQ]

ample 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. 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": 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.

Extensions

WOProject-Ant [ [http://www.objectstyle.org/confluence/display/WOL/WOProject-Ant WOProject-Ant - WOProject / WOLips - Confluence ] ] 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 [ [http://ant-contrib.sourceforge.net Ant-Contrib Tasks ] ] provides a collection of tasks such as conditional statements and operations on properties as well as other useful tasks. [ [http://ant-contrib.sourceforge.net/tasks/tasks/index.html Ant-Contrib Tasks ] ]

Other task extensions exist for Perforce, .Net, EJB, filesystem manipulations, just to name a few. [ [http://ant.apache.org/manual/tasksoverview.html Overview of Ant Tasks ] ]

Portability

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. In an Ant build file the same thing would be accomplished using a built in command: 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.

Limitations

*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 Ant uses 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 , and —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. ${unassigned.property}).

*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. [http://ant-contrib.sourceforge.net/ Antcontrib] provides a [http://ant-contrib.sourceforge.net/tasks/tasks/ variable task] to go around this problem.

*Reuse of build file fragment is hard. Ant1.7 makes it easier, with <import> and <macrodef>, but this does run the risk of providing even more complexity for new Ant users to get into trouble with.

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

References

ee also

*Build Automation
*Maven
*Nant, Ant-like tool targeted at the .NET environment rather than Java
* [http://sf.net/projects/want/ want] , an Ant-like XML-based tool for building programs, written in Delphi, and targeted at Delphi
* [http://ant.apache.org/ivy Ivy] , a dependency manager which integrates tightly with Ant.
* [http://hbtechs.blogspot.com/ Ant Automation] , a good handy example of automation with Ant.

Books

*Steve Loughran,Erik Hatcher: "Ant in Action (Second Edition of Java Development with Ant)", Manning Publications 2007, ISBN 1-932394-80-X
*Jessy Tilly, Eric M. Burke: "Ant - The Definitive Guide", O'Reilly & Associates, ISBN 0-596-00184-3
*Erik Hatcher, Steve Loughran: "Java Development with Ant", Manning Publications, ISBN 1-930110-58-8
*Glenn Niemeyer, Jeremy Poteet: "Extreme Programming with Ant", Sams, ISBN 0-672-32562-4
*Alan Williamson: "Ant - Developer's Handbook", Sams, ISBN 0-672-32426-1
*Bernd Matzke: "Ant", Addison-Wesley, ISBN 3-8273-2066-6

External links

* [http://ant.apache.org/ Official website of Apache Ant]
* [http://wiki.apache.org/ant/FrontPage Apache Ant wiki]
* [http://code.google.com/p/winant/ WinAnt - Windows installer for Apache Ant]
* [http://www.exubero.com/ant/antintro-s5.html Introduction to Ant] (slide show)
* [http://www.softwaresecretweapons.com/jspwiki/Wiki.jsp?page=LinguineMapsForApacheAnt Linguine Maps visualization library will automatically produce easy to read diagrams from Ant build files.]
* [http://www.onlamp.com/pub/a/onlamp/2004/11/18/gnumake_3e.html make: The Evolution and Alternatives]
* [http://sourceforge.net/projects/antro antro - a profiler for Ant scripts]

*
* [http://ideoplex.com/focus/java#ant Ant tutorial]
* [http://phing.info Phing] Ant clone for PHP web applications


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Apache Ant — (Another Neat Tool) Desarrollador Apache Software Foundation http://ant.apache.org …   Wikipedia Español

  • Apache Ant — (Another Neat Tool) Тип Билд утилиты Разработчик …   Википедия

  • Apache Ant — Entwickler Apache Software Foundation Aktuelle Version 1.8.2 (27. Dezember 2010) …   Deutsch Wikipedia

  • Apache Ant — es una herramienta usada en programación para la realización de tareas mecánicas y repetitivas, normalmente durante la fase de compilación y construcción (build). Es similar a Make pero sin las engorrosas dependencias del sistema operativo. Esta… …   Enciclopedia Universal

  • Apache Ant — Pour les articles homonymes, voir ant. Ant …   Wikipédia en Français

  • Apache Maven — Developer(s) Apache Software Foundation Stable release 3.0.3[1] / March 3, 2011 …   Wikipedia

  • Apache Maven — Тип Автоматизация сборки Разработчик …   Википедия

  • Ant (Apache) — Apache Ant Pour les articles homonymes, voir ant. Ant …   Wikipédia en Français

  • ANT (Apache) — Apache Ant Pour les articles homonymes, voir ant. Ant …   Wikipédia en Français

  • Ant (logiciel) — Apache Ant Pour les articles homonymes, voir ant. Ant …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”