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:opteclipsepluginscom.oxygenxml.editor_16.1.0.v2014102117toolsant.

  1. Delete the standalone Ant in: C:apache-ant-1.9.2.
  2. There’s another standalone version located in: C:UsersChris.ant. Delete it.
  3. Leave Eclipse Ant in: C:opteclipsepluginsorg.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:opteclipsepluginscom.oxygenxml.editor_16.1.0.v2014102117toolsant.
  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:opteclipsepluginscom.oxygenxml.editor_16.1.0.v2014102117toolsant.
  4. Click Ok, then click Apply, and then click OK.

Update the Ant installation with the latest libraries and dependencies

Open a command promp window (with Administrative previliges), 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:

<Project>
        <Target>
                <Task>
                </Task>
        </Target>
</Project>

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.

<tstamp/>

This sets the standard DSTAMP, TSTAMP, 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.">
        <tstamp>
                <format property="doc_build.time_stamp" pattern="EEEE MMMM dd, yyyy 'at' h:mm:ss a z" />
        </tstamp>
</target>

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

Usage

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

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"/>
        </path>

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

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

                <javadoc
                  classpath="${basedir}/libs/android-support-v4.jar;C:\Android\sdk\platforms\android-19\android.jar"
                  access="public"
                  additionalparam=" -noqualifier java.lang:java.io "
                  author="true"
                  destdir="${dest.dir}"
                  doctitle="3rdParty Mobile SDK Documentation"
                  windowtitle="3rdParty Mobile SDK for Android"
                  nodeprecated="true"
                  nodeprecatedlist="true"
                  noindex="false"
                  nonavbar="false"
                  notree="false"
                  overview="${basedir}/overview.html"
                  packagenames="com.3rdPartymobilesdk"
                  source="7"
                  sourcepath="${src.dir}"
                  splitindex="true"
                  use="true"
                  version="true">
                        <link href="http://download.oracle.com/javase/7/docs/api/"/>
                        <header><![CDATA[${javadoc.header}]]></header>
                        <footer><![CDATA[${javadoc.footer}]]></footer>
                        <bottom><![CDATA[${javadoc.bottom}]]></bottom>
                </javadoc>

        </target>

</project>