
En lugar de usar el Flex Builder para compilar los swf, se puede invocar Flex SDK desde ANT consiguiendo el mismo resultado. Usar el plugin de eclipse para compilar flex es muy cómodo para el desarrollador, pero es preferible no subir al repositorio de versiones, los binarios generados en local, es mejor hacer la compilación en el build, al igual que se hace en java.
De esta manera es posible invocar al compilador java, pasándole los argumentos necesarios desde ant.
<!-- Uses jar files from Flex SDK to compile -->
<target name="compilemxml" >
<!-- Gets SWF name from mxml file name -->
<basename property="swfname" file="${filename}" suffix=".mxml"/>
<java jar="${FLEX_HOME}/lib/mxmlc.jar" fork="true" maxmemory="128m">
<jvmarg value="-Dapplication.home=${FLEX_HOME}"/>
<arg value="-compiler.services" />
<arg value="${DEPLOY_DIR}/WEB-INF/flex/services-config.xml" />
<arg value="-load-config" />
<arg value="${DEPLOY_DIR}/WEB-INF/flex/flex-config.xml" />
<arg value="-context-root"/>
<arg value="${context.root}"/>
<arg value="-source-path" />
<arg value="${SRC_DIR}"/>
<arg value="-output" />
<arg value="${OUT_DIR}/${swfname}.swf"/>
<arg value="${filename}" />
<arg value="-library-path" />
<arg value="${FLEX_HOME}/frameworks/libs" />
<arg value="${FLEX_HOME}/frameworks/locale/{locale}" />
<arg value="-locale" />
<arg value="en_US" />
<arg value="-licenses.license" />
<arg value="fds" />
<arg value="${fds}" />
</java>
</target>
Un argumento importante es -context-root ya que está referenciado en el services-config.xml:
http://{server.name}:{server.port}/{context.root}/messagebroker/amf
Creando un wrapper para nuestro swf generado: lo único que hay que hacer es coger la plantilla que viene con la FSDK y reemplazar los valores por los que nosostros queramos.
<!-- Create HTML wrapper -->
<target name="wrapper" depends="compilemxml" description="Creates the HTML wrapper">
<!-- Copy the html-wrapper dir except the index.template.html -->
<copy todir="${OUT_DIR}">
<fileset dir="${TEMPLATES_DIR}">
<exclude name="**/index.template.html" />
</fileset>
</copy>
<!-- Copy and rename the index.template.html -->
<copy file="${TEMPLATES_DIR}/index.template.html"
tofile="${OUT_DIR}/${swfname}.html" />
<!-- Replace placeholders in the html with our variables -->
<replaceregexp
file="${OUT_DIR}/${swfname}.html"
flags="gs"
match="\$\{width\}"
replace="100%"/>
<replaceregexp
file="${OUT_DIR}/${swfname}.html"
flags="gs"
match="\$\{height\}"
replace="100%"/>
<replaceregexp
file="${OUT_DIR}/${swfname}.html"
flags="gs"
match="\$\{title\}"
replace="${PROJECT_NAME}"
encoding="utf-8"/>
<replaceregexp
file="${OUT_DIR}/${swfname}.html"
flags="gs"
match="\$\{version_major\}"
replace="9"/>
<replaceregexp
file="${OUT_DIR}/${swfname}.html"
flags="gs"
match="\$\{version_minor\}"
replace="0"/>
<replaceregexp
file="${OUT_DIR}/${swfname}.html"
flags="gs"
match="\$\{version_revision\}"
replace="0"/>
<replaceregexp
file="${OUT_DIR}/${swfname}.html"
flags="gs"
match="\$\{application\}"
replace="${swfname}"/>
<replaceregexp
file="${OUT_DIR}/${swfname}.html"
flags="gs"
match="\$\{bgcolor\}"
replace="white"/>
<replaceregexp
file="${OUT_DIR}/${swfname}.html"
flags="gs"
match="\$\{swf\}"
replace="${swfname}"/>
</target>
También es posible ejecutar Flex SDK, usando los ejecutables (.exe) del compilador que hay en el directorio bin.
Existen unos tasks para ant, aunque yo "he preferido" usar el compilador java.
http://labs.adobe.com/wiki/index.php/Flex_Ant_Tasks