Using ANT in your Flash Development Part 2: Basic ANT Concepts
This is the beginning of the “HOW” part, if you want the “WHY”, see my previous post in this series here.
You must define your ANT tasks in an xml file. Typically, this file is called “build.xml” and I like to put it in the root of my projects. Here’s the most basic example of such a file:
<project name=”Basic ANT”>
<target name=”Hello World”>
<echo>Well, hello world!</echo>
</target>
</project>
Running ANT in Eclipse
- Go ahead and create a build.xml file in your Eclipse project now. Paste the code above into the file and save.
- Go to the to menu and select Window->Show View->ANT (if you don’t already have the ANT window opened in your workspace)
- Drag the build.xml file from the Explorer Window to the ANT window.
- You will see the ANT task appear with the title defined in “project name” above, in this case “Basic ANT”. If you open it up, you will see a list of the targets defined in the ANT project.
- Double click on the Hellow World target (aka task).
- You will see something like this:

Hello World Output
The project (name, attributes) is defined in the <project name> node. You must define the name, and optionally the default target and the basedir (base directory) property. Here is a typical project node definition:
<project name=”FCNY USEFUL ANT Tasks” default=”CompileMain” basedir=”.”>
The targets are the actual tasks that get executed. Each target has a name and one or more task definitions.
A task is the bit of code that actually gets executed. There are a huge number of basic built-in tasks in the core library that include things like: basic file operations, echo, building filesets, etc. The tasks we’re interested in most are the Flex ANT tasks. These are what will allow us to compile Flash applications without using the IDE and to generate all manner of workflow tricks.
There is a huge library of optional tasks that are easy to add to do pretty much anything that can be done from the command line: ftp files to a server, perform version control operations, run unit tests, etc.
A property is the equivalent of a variable in ANT projects. The following line defines a property and uses the ${propname} syntax to reference the value of the “basedir” property defined in the property definition above:
<property name=”mainFLA” value=”${basedir}/MainAssets.fla”/>
It is good practice to use property definition files to define and group your properties. In my real world example, I have 2 property files: “default.properties” and “local.properties”. The first defines properties that are global to the project and will not change, such as default project structure settings. The latter defines properties that need to be edited for each users computer, such as the paths to their favorite web browser, the location of their Flex SDK, etc.
Task Dependencies
You can use dependencies to chain tasks together, so that they run in sequence. The concept of dependencies in ANT can be a little confusing. If you define a task “D”:
<target name="D" depends="C,B,A"/>
The target D tasks will be executed after C, B and A are executed, in the order specified. What can be odd is a situation like this:
<target name="C" depends="A, B"/> <target name="D" depends="A, B"/> <target name="F" depends="C, D"/>
If you were to run task F, you may expect to see tasks executed in this order: A, B, C, A, B, D.
But you’d be wrong! What you’d actually see is: A, B, C, D. When D is executed, it sees that the A and B tasks have already been executed, so it won’t run them again.
To use a target multiple times in a single invocation, you need to use antcall. This will allow you to treat targets more as subroutines.
The next blog will explain how the sample project is set up and begin detailing the many example tasks in the project.
My cousin would really appreciate this post. We were not too long ago discussing about this. lol
Video Gamers
3 Jan 10 at 2:55 pm
[...] Another Flash Blog! Using ANT in your Flash Development Part 2: Basic ANT Concepts [...]
blog.wie-gand.de » Blog Archi » Flash /ActionScript / Ant
11 Jan 10 at 3:15 am