Apache Ant

Apache Ant is a command line tool for automating software build processes. It is similar to Make but is implemented in Java and uses XML for scripting the build process. Although it is typically used for building Java projects, it is generic and extensible enough to be used for any type of project. For example the Flex SDK includes a set of Ant tasks for building flex projects from the command line.

The best way to use Ant for Haxe building is to install the AntHX library which provides additional Ant tasks for building Haxe projects. More information on the AntHX wiki page.

The advantages of using Ant are:

  • rich set of capabilities and add-on, e.g. file copy, generation, ftp, etc.
  • easier to build multi-language projects
  • industry standard: most IDE provide support for Ant building

The drawbacks of using Ant are:

  • requires the Java Development Kit (JDK) and not just the Java Runtime Environment (JRE)
  • learning curve: takes some time to master, best is to reuse existing build script

Full documentation and installation instructions are available on the Apache Ant site.

Example: generating ImportAll.hx

Note: see also examples on AntHX wiki page.

In order to create a swf library with haxe one has to create a class file that imports all other classes to be placed within the swf and then compile that class. Using regular Ant it is possible to dynamically generate such class file. Here is a copy of the target to use within an Ant build file.

<property name="src.subdir" value="${src.dir}${file.separator}src-subdir"/>
<property name="import-all.filename" value="ImportAll.hx"/>
<target name="flash-std-gen-import-all"
                description="Generates dummy class importing all other classes">
        <pathconvert property="import.flash.standard.classes"
                        pathsep="${line.separator}">
                <fileset dir="${src.subdir}">
                        <include name="**/*.hx"/>
                        <exclude name="${import-all.filename}"/>
                </fileset>
                <packagemapper
                        from="${basedir}${file.separator}${src.subdir}${file.separator}*.hx"
                        to="import *;"/>
        </pathconvert>
        <echo message="${import.flash.standard.classes}"
                file="${src.subdir}/${import-all.filename}"/>
</target>

Note: in the above example the properties src.subdir and import-all.filename are defined using a property element. However properties are generally defined in a separate .properties file.

FlashDevelop and Ant

FlashDevelop provides support for Ant in several manners:

  • Ant Panel Plugin: adds a panel from which Ant targets can be executed.
  • In project properties, use a pre-build command line such as:
    "C:\Program Files\Java\apache-ant-1.8.0\bin\ant.bat"
    and set the project to "No output, only run pre/post build commands".

Note: Proper parsing of Ant output is available since FlashDevelop 3.1.

version #8442, modified 2010-04-23 00:28:15 by fmjrey