You can use the Flex Ant tasks in your existing projects or create new Ant projects that use them. There are three tasks that you can use in your Ant projects:
To use the custom Flex Ant tasks in your Ant projects, you must add the flexTasks.jar file to your project's lib directory, and then point to that JAR file in the taskdef task. A taskdef task adds a new set of task definitions to your current project. You use it to add task definitions that are not part of the default Ant installation. In this case, you use the taskdef task to add the mxmlc, compc, and html-wrapper task definitions to your Ant installation. In addition, for most projects you set the value of the FLEX_HOME variable so that Ant can find your flex-config.xml file and so that you can add the frameworks directory to your source path.
<taskdef resource="flexTasks.tasks" classpath="${basedir}/flexTasks/lib/flexTasks.jar" />
<property name="FLEX_HOME" value="C:/flex/sdk"/> <property name="APP_ROOT" value="myApps"/>
<target name="main">
<mxmlc file="${APP_ROOT}/Main.mxml" keep-generated-actionscript="true">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
</mxmlc>
</target>
The following shows the complete example:
<?xml version="1.0" encoding="utf-8"?>
<!-- mySimpleBuild.xml -->
<project name="My App Builder" basedir=".">
<taskdef resource="flexTasks.tasks"
classpath="${basedir}/flexTasks/lib/flexTasks.jar"/>
<property name="FLEX_HOME" value="C:/flex/sdk"/>
<property name="APP_ROOT" value="myApp"/>
<target name="main">
<mxmlc file="${APP_ROOT}/Main.mxml" keep-generated-actionscript="true">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
</mxmlc>
</target>
</project>
This example shows how to use different types of options for the mxmlc task. You can specify the value of the keep-generated-actionscript option as an attribute of the mxmlc task's tag because it does not take any child tags. To specify the values of the load-config and source-path options, you create child tags of the mxmlc task's tag. For more information on using options, see Working with compiler options.
> ant -buildfile mySimpleBuild.xml main
If you did not copy the flexTasks.jar file to Ant's lib directory as described in Installation, you must include the JAR file by using Ant's -lib option. For example:
> ant -lib c:/ant/lib/flexTasks.jar -buildfile mySimpleBuild.xml main
The output of these commands should be similar to the following:
Buildfile: mySimpleBuild.xml
main:
[mxmlc] Loading configuration file C:\flex\sdk\frameworks\flex-config.xml
[mxmlc] C:\myfiles\flex2\ant_tests\apps\Main.swf (150035 bytes)
BUILD SUCCESSFUL
Total time: 10 seconds
>