Apache Ant Java

Apache Ant Cookbook

Apache Ant is a software tool for automating software build processes (like GNU Make). I used Ant to build the Adroid version of a doc set from within the Eclipse IDE.

Note: The name Ant is an acronym that stands for Another Neat Tool.

Installation and setup

The oXygen XML Editor uses it’s own version of Ant. To get oXygen to work properly, you have to make it’s Ant installation the primary Ant installation located in C:\opt\eclipseplugins\com.oxygenxml.editor_16.1.0.v2014102117\tools\ant.

  1. Delete the standalone Ant in: C:\apache-ant-1.9.2.
  2. There’s another standalone version located in: C:\Users\Chris\.ant. Delete it.
  3. Leave Eclipse Ant in: C:\opt\eclipseplugins\org.apache.ant_1.9.2.v201404171502. You should leave this so you can set controls for it (i.e., set preferences in Eclipse). You can set it up to use oXygen’s Ant installation.

Set the environment variable

In Windows

  1. Create the new environment variable ANT_HOME=C:\opt\eclipseplugins\com.oxygenxml.editor_16.1.0.v2014102117\tools\ant.
  2. Add it to the path statement: ;%ANT_HOME%/bin.

In Eclipse

  1. In Eclipse, navigate to: Windows > Preferences > Ant > Runtime.
  2. Click Ant Home….
  3. Navigate to C:\opt\eclipseplugins\com.oxygenxml.editor_16.1.0.v2014102117\tools\ant.
  4. Click Ok, then click Apply, and then click OK.

Update the Ant installation with the latest libraries and dependencies

Open a command prompt window (with Administrative privileges), and execute the following command:

ant -f fetch.xml -Ddest=system

Note: ant.bat is the batch file that serves as the wrapper script for Windows.

Ant script structure

Ant scripts have the following structure:


Doc build timestamp

I wanted each doc build to include the time that I generated the docs. For more information, see the documentation for tstamp. To accomplish this, you use the TODAY property in your Ant project, but first you need to initialize it. You do this by adding the following statement to your Ant project.


This sets the standard DSTAMPTSTAMP, and TODAY properties according to the default formats. I added it to the init target to make its use obvious.

<target name="init" description="Ant build project setup.">
                <format property="doc_build.time_stamp" pattern="EEEE MMMM dd, yyyy 'at' h:mm:ss a z" />

Notice that I created my own property called doc_build.time_stamp.


I use my new doc build timestamp property inside the target that I created for building the HTML docs.

<property name="javadoc.footer" value="&lt;strong&gt;Built:&lt;/strong&gt;&#09;${doc_build.time_stamp}." />


build.xml is the default name used by Ant for the Ant project file.

My build.xml

Here’s the XML in my build.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<project name="3rdParty Mobile SDK" default="HTML Docs" basedir=".">

        <property name="src.dir"        value="${basedir}/src"/>
        <property name="dest.dir"       value="${basedir}/doc"/>
        <property name="lib.dir"        value="${basedir}/lib"/>

        <path id="classpath">
                <fileset dir="${lib.dir}" includes="**/*.jar"/>

        <target name="init" description="Ant build project setup.">
                        <format property="doc_build.time_stamp" pattern="EEEE MMMM dd, yyyy 'at' h:mm:ss a z" />

        <target name="HTML Docs" depends="init" description="Compile the HTML version of the docs.">
                <property name="javadoc.header" value="&lt;strong&gt;3rdParty Mobile SDK&lt;/strong&gt;&#09;v1.0" />
                <property name="javadoc.footer" value="&lt;strong&gt;Built:&lt;/strong&gt;&#09;${doc_build.time_stamp}." />
                <property name="javadoc.bottom" value='Copyright &amp;copy; 2013 - &lt;script&gt; var currYear=new Date(); document.write(currYear.getFullYear()); &lt;/script&gt;, 3rdParty Corp., All rights reserved.' />

                  additionalparam=" -noqualifier "
                  doctitle="3rdParty Mobile SDK Documentation"
                  windowtitle="3rdParty Mobile SDK for Android"
                        <link href=""/>


Apache Ant Java

Apache Ant

ANT is the Java equivalent of Make. Once you create a javadoc.xml file, you can use it to generate the Javadocs instead of having to go through the Javadoc Gererating Wizard in Eclipse.

Environment Variable and PATH for Eclipse’s version of Ant

ANT_HOME=C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730

Eclipse Ant Editor and Ant Viewer

Eclipse has two very cool features for building and running Ant files.

  1. In Eclipse, click Window > Show View > Ant.
  2. In the new Ant window, right-click on the root folder item, and click open in XML Editor. Eclipse’s built-in XML Editor displays syntax-formatted XML, and has a cool Design tab feature that allows you to manipulate the entities.

The Latest Version of Ant

You don’t have to download and install Ant. It’s bundled with Eclipse (albeit, its an not the latest version of Ant – v1.7). At the time of this writing, the latest version of Ant is v1.8.4.

If you install it, you’ll get a warning message when you try to change the Ant configuration in Eclipse (Windows > Preferences > Ant > Runtime > Ant Home…) – to point to the new ANT_HOME. Apparently the new installation is missing “tools.jar”, which Eclipse needs.

In Eclipse, Windows > Preferences > Ant; “Some tasks, such as “javac”, require the tools.jar library to be on the Ant runtime classpath to execute successfully.”

  1. To fix this, in Eclipse, navigate to Windows > Preferences > Ant > Runtime > Classpath > Global Entries.
  2. Click “Add external Jars…”.
  3. Type “C:\Program Files\Java\jdk1.7.0_21\lib\tools.jar”, and click “Open”.

Download and Install

At the time of this writing, the latest version of Ant is apache-ant-1.9.1.

  1. Download Apache Ant, and extract the zip file to C:\. It’ll end up with in C:\apache-ant-1.9.1.
  2. Set the “ANT_HOME” environment variable to “C:\apache-ant-1.9.1”.
  3. Path ;%ANT_HOME%\bin Make sure that you also the JAVA_HOME environment variable set to the JDK. This is required for running Ant. ..Note: You’d think that JAVA_HOME should point to the JRE, not to the JDK, but apparently that’s not the case. It should point to the JDK.
  4. Check your installation by opening a command line and typing “ant -version” into the commend line. The system should find the command ant and show the version number of your installed Ant.

I did this, and I got the following error:

“C:\Users\Chris>ant -version
Unable to locate tools.jar. Expected to find it in %JDK_HOME%\lib\tools.jar Apache Ant(TM) version 1.9.1 compiled on May 15 2013”

I fixed it by simply copying C:\Program Files\Java\jdk1.7.0_21\lib\tools.jar to C:\Program Files\Java\jre7\lib\.

Using Ant to build the docs from the Command Line

  1. Open a command prompt.
  2. Type: C:\Users\Chris\src\java_3rdParty>ant -f javadoc.xml

Using Ant to build the docs from the Run dialog

  1. Open the Run dialog by pressing the Windows Key + R (on the Kinesis Advantage keyboard, that’s Right Alt + R).

  2. Paste the following command line into the Open field, and the click OK.

    %ANT_HOME%\bin\ant -F %USERHOME%\src\java_3rdParty\javadoc.xml

  3. When the Permission dialog appears, just click OK.