Thursday, September 3, 2009

Compiling a Flex Application with Ant

This blog summarizes how to compile a Flex application using ant.

Creating the build.xml File
The build.xml file:
<project name="fishbaitTestModule" basedir="." default="compile_flex_project">

<!-- Properties -->
<property environment="env" />
<property name="flexhome_dir" location="${env.FLEX_HOME}" />
<property name="src_dir" location="${basedir}/../test-src" />
<property name="libs_dir" location="${basedir}/libs" />
<property name="deploy_dir" location="${basedir}/deploy" />

<!-- Define the flex ant task -->
<taskdef resource="flexTasks.tasks" classpath="${libs_dir}/flexTasks.jar"/>

<target name="clean">
<delete dir="${deploy_dir}" />

<target name="init" depends="clean">
<mkdir dir="${deploy_dir}" />

<!-- Don't touch. Required by flex ant task -->
<property name="FLEX_HOME" location="${flexhome_dir}" />
<target name="compile_flex_project" depends="init">
<mxmlc file="${src_dir}/testSuites/FishBaitTestModule.mxml" output="${deploy_dir}/FishBaitTestModule.swf">
<load-config filename="${flexhome_dir}/frameworks/flex-config.xml"/>
<source-path path-element="${flexhome_dir}/frameworks"/>

<compiler.source-path path-element="${src_dir}"/>


<!-- List of SWC files or directories that contain SWC files. -->
<compiler.library-path dir="${basedir}/libs" append="true">
<include name="AirMonkeyLibrary.swc" />
<include name="MonkeyFlexUnitLibrary.swc" />
<include name="fluint.swc" />


How To Use The Script
  • create FLEX_HOME environment variable on your system (we tested this on WinXP) and point it to Flex root folder.
  • copy files flexTasks.jar and flexTasks.tasks into libs_dir folder. You can obtain these files from Adobe.
  • Note: the ant FLEX_HOME property just above the compile_flex_project target needs to be there; it seems that the mxmlc task uses and requires it, even if you already have envvar with the same name setup on your system.
  • the src_dir, libs_dir properties point to folders where the Flex source, required SWC files are located, respectively. The deploy_dir is where the SWF files will be created, your compiled application.
  • FYI: If you are running your Ant script from Eclipse, the Ant you're running is installed in ...\eclipse\plugins\org.apache.ant_1.7.0.v200803061910 or similar folder.

No comments: