Skip to main content

Building a Flex project with Ant

Here is a quick sample on how to build a simple Flex
"hello world" project with Ant.

The "hello world" project contains a src folder with one Flex application file and an Ant build.xml file:

./project_home/
./src/
app.mxml
build.xml

The app.mxml is the main module of the project. It simply has a label with a "Hello World!" text:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Label text="Hello World!"/>
</mx:Application>
Here is the build.xml source:
<?xml version="1.0"?>
<project name="fx_practice7" default="all">

<!-- Init the build process -->
<target name="init" unless="initialized">
<!-- Name of project and version -->
<property name="FLEX_HOME" location="/Users/mykola/java/flex"/>

<property name="proj.name" value="${ant.project.name}" />
<property name="proj.shortname" value="${ant.project.name}" />
<property name="version.major" value="0" />
<property name="version.minor" value="9" />
<property name="version.revision" value="0" />
<property name="APP_TITLE" value="Sample Application" />
<property name="APP_WIDTH" value="800" />
<property name="APP_HEIGHT" value="600" />

<!-- Global properties for this build -->
<property name="build.dir" location="${basedir}/build" />
<property name="flex_src" location="${basedir}/src" />

<path id="project.classpath">
<pathelement path="${java.class.path}" />
</path>

<taskdef resource="flexTasks.tasks"
classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />

<echoproperties/>

<property name="initialized" value="true" />

<mkdir dir="${build.dir}" />
</target>

<!-- Default target: clean and build the application -->
<target name="all" depends="init">
<antcall target="clean" />
<antcall target="build" />
</target>

<!-- Compile Flex files -->
<target name="compile.flex" depends="init">
<property name="module"
value="${ant.project.name}"
description="The name of the application module." />

<mxmlc file="${flex_src}/${module}.mxml"
keep-generated-actionscript="true"
output="${build.dir}/${ant.project.name}/${module}.swf"
actionscript-file-encoding="UTF-8"
incremental="true"
context-root="${ant.project.name}"
debug="true">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<compiler.source-path path-element="${flex_src}" />
</mxmlc>

<html-wrapper title="${APP_TITLE}"
file="index.html"
application="app"
swf="${module}"
width="${APP_WIDTH}"
height="${APP_HEIGHT}"
version-major="${version.major}"
version-minor="${version.minor}"
version-revision="${version.revision}"
history="true"
template="express-installation"
output="${build.dir}/${ant.project.name}/" />

</target>

<!-- Build the application -->
<target name="build" depends="init">
<antcall target="compile.flex" />
</target>

<!-- Clean build files -->
<target name="clean" depends="init">
<delete dir="${basedir}/generated" />
<delete dir="${build.dir}" />
</target>

<target name="usage" description="Usage documentation">
<echo>
all - clean and build the project
</echo>
</target>
</project>
NOTE: Please update FLEX_HOME and other properties in the build.xml as required for your environment.

To do the build, simply run ant in the project folder. The build output will be stored in the project/build/ folder. To see the result, open index.html in a browser. The index.html is located in the project/build/project_home/ folder.

Comments

Anonymous said…
Thanks for post, it has useful information. My question is, what do I do if I have Javascript classes in my index.html file? Using FlexBuilder you can edit the index.html.template and add my Javscript methods here, which I can then call from my Flex app. How would I go about doing the same thing using ant?

Regards,
Simon
Anonymous said…
Just a small correction to my previous post. It should of course have said, "what if I have javascript methods in the index.html" not javascript classes

Regards,
Simon
Mykola said…
I guess there are 2 options - either change the template in the SDK folder or change the generated index.html. The second is probably a better option. The Flex livedocs chapter called "Using the html-wrapper task" says: "You can customize the output of the wrapper and its supporting files after it is generated by Ant." That task can be automated with ant as well.
Anonymous said…
hey

Really nice tips!

will try to keep it in my mind

thanks!

Popular posts from this blog

How to debug SOAP on Mac with tcpdump

I’ve been using several tools to debug SOAP on Mac and Windows. I would like to share my experience in using some of the tools and show some examples. So far I found four major categories of tools that are useful in debugging SOAP: Interface listeners such as tcpdump and others Proxy tools such as TCPMonitor Servlet filters Application server logging. For example, Weblogic has a special logging option that dumps SOAP requests and responses to the sever log. All of these tools have their own advantages and disadvantages. In this article, I will describe the first type - an interface listener tool called tcpdump. I am planning to describe other three categories in the future posts. The tcpdump is a tool that sniffs IP traffic and dumps it to a file or a standard output stream. It was originally developed by Van Jacobson, Craig Leres and Steven McCanne from the Lawrence Berkeley National Laboratory, University of California, Berkeley, CA. It is open source. The tcpdump documentation...

MySQL macport install on Mac OS X Tiger

I have installed mysql5 macport on the MacBookPro laptop running OS X Tiger 10.4. There are a few steps that needs to be done once the port is installed. These steps are not documented (see Ticket #12694 on macports.org). So, after reading a few blogs and analyzing mysql startup error messages, I figured out what needs to be done in order to get it running. That info might be useful to others, so I’ve decided to publish the solution here. First of all, we need to create the initial database database $ sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql Here is the output of the command: $ sudo ./mysql_install_db --user=mysql Installing MySQL system tables... 071118 0:06:29 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive OK Filling help tables... 071118 0:06:29 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive OK To start mysqld at boot time you hav...

Deploying BlazeDS to Weblogic 10.0

The BlazeDS is a free and open source J2EE application that provides data services to Adobe Flex and AIR applications. I’ve deployed it to Weblogic 10.0 server. I thought somebody else would be interested to do the same. Here is how. In case you need to install Weblogic 10.0, the developers copy is available for free at http://commerce.bea.com/products/weblogicplatform/weblogic_prod_fam.jsp . I have it installed on my Windows XP at D:\bea10 folder. I have created a new domain for my BlazeDS applications. It is easy to do, see http://edocs.bea.com/common/docs100/confgwiz/index.html for details. In my case, the domain name is blazeds and it is located in D:\bea10\user_projects\domains\blazeds folder on my computer. The domain name and the folders names can be difference, I just mentioned them so it is easier to follow the examples.. Once the Weblogic server is installed and a domain is ready, the BlazeDS applications can be deployed. A copy of BlazeDS is available...