From TheBestLinks.com
de:Ant
Ant is a software tool for automating software build processes. It is similar to Make but is written in the Java language and is primarily intended for use with Java.
The most immediately noticeable difference between Ant and Make is that Ant uses a file in XML format to describe the build process and its dependencies, whereas Make has its own Makefile format. By default the XML file is named build.xml.
Ant is one of the Apache projects.
Sample build.xml file
Below is listed a sample build.xml file for a simple Java "Hello, world" application. It defines three targets - clean, 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. 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.
<?xml version="1.0"?>
<project name="Hello" default="compile">
<target name="clean" description="remove intermediate files">
<delete dir="classes"/>
</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="**/*.java"/>
<manifest>
<attribute name="Main-Class" value="HelloProgram"/>
</manifest>
</jar>
</target>
</project>
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 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:
<delete dir="classes"/>
A common discrepency 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 always use the Unix convention, forward slashes, and then convert path specifiers to the appropriate format for the current platform.
See also
References
- Jessy Tilly, Eric M. Burke: Ant - The Definitive Guide, O'Reilly & Associates, ISBN 0-596-00184-3
- Erik Hatcher, Steve Loughran, Matthew Robinson: 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
- James D. Davidson: Managing Projects with Ant, O'Reilly & Associates, ISBN 0-596-00136-3
- Bernd Matzke: Ant, Addison-Wesley, ISBN 3-8273-2066-6
External links
Related links
Top visited
0 of
0 links
[no links posted yet]
>> place link >>
Discussion
Last posted
0 of
0 messages
[no messages posted yet]
>> post message >>
Watch
You can
add this article to your own "watchlist" and receive e-mail notification about all changes in this page.