Aug 10, 2009

Ant to automate Flex builds

Today I wanted to automate my flex builds in order to save my and my team's time. Thus I did the obvious thing: Googling :) . However after 3 hours of Googling, I found that there is no clear writeup available for a newbie. Thus I am writing this step by step guide to automate your Flex builds using Apache Ant.


  1. Install Flex builder (I know you must be having this already. Adding for the sake of initiation)
  2. Download Apache Ant current bin from
  3. Extract the zip folder at any location.
  4. Define these environmental variables: ANT_HOME, FLEX_HOME, JAVA_HOME. For more info, go to Apache Ant documentation.
  5. Create your Flex/ActionScript project and run it. If everything works fine, go to step 6, else remove the errors from your code and then go to step 6.
  6. Now copy flexTasks.jar from Flex installation directory (in my XP machine it is "C:\Program Files\Adobe\Flex Builder 3\sdks\3.0.0\ant\lib") and paste in the "libs" folder of your project.
Good to go, now we will continue with ANT specific configurations which will make your project builds automatic.

Create build script (xml):

  1. By default ANT looks for build.xml file as a build script. However you can define any xml file as a build script file in the command line while executing ANT commands.
  2. For an example, take a look at the XML Syndication build.xml and files.
  3. The first element is project which is the starting point of ant execution. Its name can be any value (generally you would like to put your project name there). basedir reflects the base directory of the project. default attribute contains a target name (I have covered targets later in this post) which will run by default OR as the first executable.
    • property defines a file which contains all static constants / properties to use during execution. For our case, these properties are defined in file.
    • element defines the path of flexTasks.jar file. ( ). In order to get rid of this element, simply copy-paste the flexTasks.jar file from Flex installation directory to ANT's lib folder.
    • Now comes the targets. It is nothing but a task block which will be run by ant during run time. Target name is actually its identifier so that it can be referred to in the script file (build.xml) using its name. Targets / tasks can be dependent on other tasks / targets to get completed. This is handled using depends attribute.
    • Now you can run your custom tasks to run under element. e.g. In AS3SyndicaitonLib project's target named "properties" checks for property values set in Target named "lib" fires Flex compile command (compc.exe) giving various parameters needed (-o, -el, sp, -is).
Running build script:
  1. Open command prompt and write this command to run build.xml as ant script:
    • $ ant -buildfile "/build.xml"
  2. If you don't have flexTasks.jar in your project's libs folder, update the above command to:
    • $ ant -lib ${basedir}/libs/flexTasks.jar -buildfile "/build.xml"
That's it. Enjoy :)

For more, read Adobe Flex Help, Adobe Developer Connection, Adobe Cookbooks, Gunua's blog.

No comments:

Post a Comment

I love comments.