ant是一个基于JAVA的自动化脚本引擎,脚本格式为XML。除了做JAVA编译相关任务外,ANT还可以通过插件实现很多应用的调用。 平时我们在编译Flex文件时都是使用的FlexBuilder提供的编译功能,也可以实现自动编译的功能,但如果项目一大,涉及到一些公共组件的调用比较多时,这种编译就不是很方便了. 在习惯了利用ant自动化编译部署Java应用程序的方便功能以后,自然想到也要利用ant的脚本功能进行Flex的自动编译,以下就是我写的关于编译Flex的build.xml文件(附件中有实例工程压缩文件),实现了自动编译与生成API文档的功能:
- <?xml version="1.0"?>
- <project name="flex_examples" basedir="../" default="compile_modified">
- <property file="./build/build.properties" />
- <!--
- Have you edit the properties file to make sure the paths are right on your system?
- -->
- <target name="properties">
- <fail unless="asdoc.exe">The "asdoc.exe" property must be set in ${build.dir}/build.properties.</fail>
- <fail unless="compc.exe">The "compc.exe" property must be set in ${build.dir}/build.properties.</fail>
- <fail unless="mxmlc.exe">The "mxmlc.exe" property must be set in ${build.dir}/build.properties.</fail>
- </target>
- <!--
- Extension for ANT to allow for tasks like "for" and "propertyregex"
- -->
- <taskdef resource="net/sf/antcontrib/antlib.xml">
- <classpath>
- <pathelement location="libs/ant/ant-contrib.jar" />
- </classpath>
- </taskdef>
- <!--
- Generate the main applications using the library
- -->
- <target name="compile_modified" depends="properties">
- <!--
- Loop over all of the Sample applications in the mains directory,
- compile them, and place the resulting .swf next to the application
- .mxml file.
- -->
- <for param="file">
- <!-- Find the sample applications -->
- <fileset dir="${src.dir}">
- <!--
- The modified selector will only select files that have been
- modified since the mains target was last run. This means we
- can update a single main, then run the mains target and
- only the updated main will get recompiled.
- -->
- <modified/>
- <include name="**/*${application.name.flag}.mxml" />
- <!--
- For only building specific mains, comment out
- the line above, and uncomment the line below and modify
- as appropriate.
- -->
- <!--<include name="**/HorizontalAxisDataSelector_Sample.mxml" />-->
- </fileset>
- <sequential>
- <propertyregex property="mainApplicationName" override="yes" input="@{file}"
- regexp=".*\${file.separator}(.*)${application.name.flag}.mxml" replace="\1" />
- <propertyregex property="mainFolderName" override="yes" input="@{file}"
- regexp="(.*)\${file.separator}(.*)${application.name.flag}.mxml" replace="\1" />
- <exec executable="${mxmlc.exe}" dir="${basedir}">
- <arg line="'@{file}'" />
- <arg line="-o '${mainFolderName}/${mainApplicationName}${application.name.flag}.swf'" />
- <arg line="-l '${lib.dir}'" />
- <arg line="-l '${flexsdk.lib.dir}'" />
- <arg line="-sp '${src.dir}'" />
- <arg line="-optimize" />
- <arg line="-locale ${flexsdk.locale}" />
- <arg line="-l '${flexsdk.locale.dir}'" />
- </exec>
- </sequential>
- </for>
- </target>
- <!--
- Generate ASDoc output for the library
- -->
- <target name="docs" depends="properties">
- <!-- Clean out the contents of the doc directory, without deleting "docs" -->
- <delete includeemptydirs="true">
- <fileset dir="${docs.dir}" includes="**/*" />
- </delete>
- <exec executable="${asdoc.exe}" spawn="no">
- <!-- Place the documentation in the "docs" directory -->
- <arg line="-o '${docs.dir}'" />
- <!-- Specify the main source path as "src" -->
- <arg line="-sp '${src.dir}'" />
- <!-- Document all of the classes in the "src" tree -->
- <arg line="-ds '${src.dir}' " />
- <!-- Include the library name in the window title -->
- <arg line="-window-title '${library.name}' "/>
- <arg line="-templates-path '${flexsdk.templates.dir}' "/>
- </exec>
- </target>
- </project>
The "asdoc.exe" property must be set in ${build.dir}/build.properties. The "compc.exe" property must be set in ${build.dir}/build.properties. The "mxmlc.exe" property must be set in ${build.dir}/build.properties.