Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Apache Ant

From Wikipedia, the free encyclopedia
Java build tool
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Apache Ant" – news ·newspapers ·books ·scholar ·JSTOR
(July 2020) (Learn how and when to remove this message)
Apache Ant
Original author(s)James Duncan Davidson
Developer(s)Apache Software Foundation
Initial release19 July 2000; 24 years ago (2000-07-19)
Stable release
1.10.15 / August 29, 2024; 7 months ago (2024-08-29)[1]
RepositoryAnt Repository
Written inJava
PlatformJava SE
TypeBuild tool
LicenseApache License 2.0
Websiteant.apache.org Edit this on Wikidata

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

Released under anApache License by theApache Software Foundation, Ant is anopen-source project.

History

[edit]

Ant ("Another Neat Tool")[5] was conceived by James Duncan Davidson while preparingSun Microsystems'sreferenceJSP andServlet engine, laterApache Tomcat, for release asopen-source. Aproprietary version of Make was used to build it on theSolaris 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 simpleplatform-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 includedbuild.xml files with their distribution.[citation needed] Because Ant made it trivial to integrateJUnit tests with the build process, Ant allowed developers to adopttest-driven development andextreme programming.

In 2004 Apache created a new tool with a similar purpose calledMaven.

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

Extensions

[edit]

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'slib directory. Once this is done, these task extensions can be invoked directly in the typicalbuild.xml file. The WOProject extensions allowWebObjects developers to use ant in building their frameworks and apps, instead of usingApple'sXcode 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 forPerforce,.NET Framework,EJB, and filesystem manipulations.[14]

Example

[edit]

A samplebuild.xml file is listed below for a simple Java "Hello, world" application. It defines four targets -clean,[15]clobber,compile andjar , each of which has an associated description. Thejar target lists thecompile target as a dependency. This tells Ant that before it can start thejar target it must first complete thecompile 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 calledclasses (which Ant will do only if it does not already exist) and then invoke the Java compiler. Therefore, the tasks used aremkdir andjavac. These perform a similar task to the command-line utilities of the same name.

Another task used in this example is namedjar:

<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

[edit]

Ant is intended to work with all systems for which Java runtimes are available. It is most commonly used withWindows,Linux,macOS and otherUnix 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-specificshell commands. Ant provides built-in functionality that is designed to behave the same on all platforms. For example, in the samplebuild.xml file above, theclean target deletes theclasses directory and everything in it. In a Makefile this would typically be done with the command:

rm -rf classes/

rm is aUnix-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

[edit]
This sectionpossibly containsoriginal research. Pleaseimprove it byverifying the claims made and addinginline citations. Statements consisting only of original research should be removed.(September 2011) (Learn how and when to remove this message)
  • Ant build files, which are written inXML, 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 (calledantlibs) that provide much of the missing functionality. Also, theEclipseintegrated development environment (IDE) can build and execute Ant scripts, while theNetBeans 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

[edit]

References

[edit]
  1. ^"Apache Ant Project News". Retrieved11 December 2024.
  2. ^"Apache Ant - Welcome".ant.apache.org. Retrieved2022-01-25.
  3. ^"Apache Ant - Frequently Asked Questions".ant.apache.org. Retrieved2022-01-25.
  4. ^abMoodie 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 fromthe 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

[edit]

External links

[edit]
Wikibooks has a book on the topic of:Apache Ant
Top-level
projects
Commons
Incubator
Other projects
Attic
Licenses
International
National
Retrieved from "https://en.wikipedia.org/w/index.php?title=Apache_Ant&oldid=1282327126"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp