Apache 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. It is open source software, and is released under the Apache Software License.

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="**/*.class"/>
            <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 (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:

<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 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.

History


Ant was invented by James Duncan Davidson while turning a product from Sun into open source. The product later became Jakarta Tomcat; it was Sun's reference JSP/Servlet engine. While closed source, Make could be 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 tool to take an XML "build file" and use it to build Tomcat, regardless of which platform the developer was using. From this humble beginning, the tool has gone on to become more ubiquitous -and perhaps successful- than the Tomcat product for which it was created. It has proven to become the underpinning of open source Java; developers expect a "build.xml" file with every project.

Because it makes 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. Its sole potential competitor is currently Maven.

Limitations

  • Being an XML based tool, Ant build files must be written in XML. This is a barrier to new users, but also a problem in very large projects, when build files can get very large and complex. This may be a problem common to all XML-languages, but the granularity of Ant's tasks (compared to, say Maven), means that the scalibility problems arrive early.
  • Many of the older tasks, the core ones that are used every day, such as <javac>, <exec> and <java> have bad defaults, default values for options that are not consistent with more recent tasks. This is the curse of backwards compatibility: 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}). Again, this is a backwards compatibility issue, even though it is recognised that having the tool halt in such a situation would usually be the best action, at least to the extent that the mythical "Ant2.0" product would fail on unassigned properties.
  • It is not a generic workflow language, and should not be used as such. In particular, it has limited fault handling rules, and no persistence of state -so it cannot be safely used to manage a multi-day build.
  • No amount of automation can hide the fact that modern Java development has excessive complexity. Ant does make it easier to generate deployment descriptors for Enterprise Applications, *SOAP clients from WSDL files, precompile [[JavaServer Pages|JSP] templates. But at some point, one has to consider whether it is all worth it: are Ant and Maven damage-limitation tools to try and make the complexity of Java systems development barely manageable.

See also

References

External links

pl:Ant

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools