利用Ant将flex中的mxml文件编译成swf文件的三种方法
今天学习并试验了三种利用Ant将mxml编译成swf的方法
使用Ant编译mxml的几种方法:
1.可执行版的exec
<?xml version="1.0"?>
<project name="Flex Ant Tasks Build Script" default="compileMain">
<!--property file="build.properties" /-->
<property name="dir.src" value="src" />
<property name="dir.build" value="build" />
<property name="FLEX_HOME" value="D:/Program Files/Adobe/Flex Builder 3 Plug-in/sdks/3.2.0" />
<target name="init">
<delete dir="${dir.build}" />
<mkdir dir="${dir.build}" />
</target>
<target name="compileMain" depends="init" description="Compiles the main application files.">
<echo message="Compiling ${dir.build}/main.swf..."/>
<exec executable="${FLEX_HOME}/bin/mxmlc.exe" spawn="false">
<arg line="${dir.src}/main.mxml" />
<arg line="-output ${dir.build}/main.swf" />
</exec></target>
</project>
2.Java版
<?xml version="1.0"?>
<project name="Flex Ant Tasks Build Script" default="compileMain">
<!--property file="build.properties" /-->
<property name="dir.src" value="src" />
<property name="dir.build" value="build" />
<property name="FLEX_HOME" value="D:/Program Files/Adobe/Flex Builder 3 Plug-in/sdks/3.2.0" />
<target name="init">
<delete dir="${dir.build}" />
<mkdir dir="${dir.build}" />
</target>
<target name="compileMain" depends="init" description="Compiles the main application files.">
<echo message="Compiling ${dir.build}/main.swf..."/>
<java jar="${FLEX_HOME}/lib/mxmlc.jar" fork="true" failonerror="true">
<arg value="+flexlib=${FLEX_HOME}/frameworks" />
<arg value="-file-specs=${dir.src}/main.mxml" />
<arg value="-output=${dir.build}/main.swf" />
</java></target>
</project>
3.使用Flex 3 SDK中的mxmlc任务
为了能访问所要build文件中的信息,首先添加一个任务定义
<?xml version="1.0"?>
<project name="Flex Ant Tasks Build Script" default="compileMain">
<!--property file="build.properties" /-->
<property name="dir.src" value="src" />
<property name="dir.build" value="build" />
<property name="FLEX_HOME" value="D:/Program Files/Adobe/Flex Builder 3 Plug-in/sdks/3.2.0" />
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<target name="init">
<delete dir="${dir.build}" />
<mkdir dir="${dir.build}" />
</target>
<target name="compileMain" depends="init" description="Compiles the main application files.">
<echo message="Compiling ${dir.build}/main.swf..."/>
<mxmlc file="${dir.src}/main.mxml" output="${dir.build}/main.swf">
<source-path path-element="${dir.src}" />
</mxmlc></target>
</project>
以上swf的output文件目录可以不指定,如不指定,默认为mxml所在目录