利用Ant自动编译Flex程序

本文介绍了一种使用Ant脚本引擎自动化编译Flex应用程序的方法。通过配置特定的build.xml文件,可以实现Flex项目的自动编译及API文档的生成。此外,文章还详细解释了如何利用Ant的任务和插件来提高编译效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值