Skip to main content

Overview

Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other.

The main usage of Ant is in building Java applications, which fits well with the AIR environment.

Installation

Firstly check your Java installation, by typing the following in a terminal window:

java --version

If java is installed it should output the version information to your terminal window. You should have a JDK installed for AIR development so normally this is already available.

Next, install Ant.

Homebrew

The easiest way to install ant on macOS is to use Homebrew:

brew install ant

Manual

To download ANT go to http://ant.apache.org/bindownload.cgi. Extract the downloaded file into a location, for example, ~/sdks/ant. Then create an ANT_HOME environment variable to this location and add $ANT_HOME/bin to PATH:

This is similar to your AIR_HOME environment variable and should be set in the same file as you did when installing AIR, by adding the following to either ~.zshrc or ~/.bashrc:

export ANT_HOME=~/sdks/ant
export PATH="${PATH}":"${ANT_HOME}/bin"

Once complete, restart your terminal and type ant to your terminal to confirm it is available.

Ant Script Format

Ant is driven by an XML-based script format that specifies a series of tasks for the build. Ant by default looks for a script file called build.xml in the current directory. A build script should have a project as the main node and at least one target which contains a series of commands to run through as part of the build.

<?xml version="1.0"?>
<project name="example" default="main" >

<target name="main" >
<!-- commands here -->
</target>

</project>

Properties File

Generally it is good practice to define all configuration variables in a "properties" file and then include this file in your ant script.

For example:

build.config
project.name=MyApplication
version=1.0.0

Then in your script:

build.xml
<project name="example" default="main" >

<property file="build.config" />

<target name="main" >
<!-- commands here -->
<echo message="Building ${project.name} v${version}" />
</target>

</project>

Environment

As you have setup your AIR SDK environment variables it is easy to access them using the env variables in ant.

build.xml
<project name="example" default="main" >

<property environment="env."/>

<fail unless="env.AIR_HOME" message="AIR_HOME needs to be defined as an environment variable or in the Ant build." />
<fail unless="env.AIR_TOOLS" message="AIR_TOOLS needs to be defined as an environment variable or in the Ant build." />

<property name="air.adt" value="${env.AIR_HOME}/bin/adt" />
<property name="air.apm" value="${env.AIR_TOOLS}/apm" />

</project>

This allows you to access the AIR build tools and package manager easily based on your current environment.