TheBestLinks.com
TheBestLinks.com
Apache Ant, Apache Software Foundation, Java programming language, Microsoft ... Print friendly version | Tell a friend
 
Navigation
Search
Toolbox

Apache Ant

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.

Table of contents

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

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.
 
   
Innovate it
This page was last modified 22:15, 9 Aug 2004.
  Content is available under GNU Free Documentation License 1.2.
Powered by MediaWiki