flex 编译自动

ant是一个基于JAVA的自动化脚本引擎,脚本格式为XML。除了做JAVA编译相关任务外,ANT还可以通过插件实现很多应用的调用。

平时我们在编译Flex文件时都是使用的FlexBuilder提供的编译功能,也可以实现自动编译的功能,但如果项目一大,涉及到一些公共组件的调用比较多时,这种编译就不是很方便了.

在习惯了利用ant自动化编译部署Java应用程序的方便功能以后,自然想到也要利用ant的脚本功能进行Flex的自动编译,以下就是我写的关于编译Flex的build.xml文件(附件中有实例工程压缩文件),实现了自动编译与生成API文档的功能:

Xml代码 复制代码 收藏代码
  1. <?xml version="1.0"?>  
  2. <project name="flex_examples" basedir="../" default="compile_modified">  
  3.   
  4.     <property file="./build/build.properties" />  
  5.   
  6.     <!--  
  7.         Have you edit the properties file to make sure the paths are right on your system?  
  8.     -->  
  9.     <target name="properties">  
  10.         <fail unless="asdoc.exe">The "asdoc.exe" property must be set in ${build.dir}/build.properties.</fail>  
  11.         <fail unless="compc.exe">The "compc.exe" property must be set in ${build.dir}/build.properties.</fail>  
  12.         <fail unless="mxmlc.exe">The "mxmlc.exe" property must be set in ${build.dir}/build.properties.</fail>  
  13.     </target>  
  14.        
  15.     <!--   
  16.         Extension for ANT to allow for tasks like "for" and "propertyregex"  
  17.     -->  
  18.     <taskdef resource="net/sf/antcontrib/antlib.xml">  
  19.         <classpath>  
  20.             <pathelement location="libs/ant/ant-contrib.jar" />  
  21.         </classpath>  
  22.     </taskdef>  
  23.        
  24.     <!--  
  25.         Generate the main applications using the library  
  26.     -->  
  27.     <target name="compile_modified" depends="properties">  
  28.         <!--    
  29.             Loop over all of the Sample applications in the mains directory,   
  30.             compile them, and place the resulting .swf next to the application   
  31.             .mxml file.   
  32.         -->  
  33.         <for param="file">  
  34.             <!-- Find the sample applications -->  
  35.             <fileset dir="${src.dir}">  
  36.                 <!--    
  37.                     The modified selector will only select files that have been   
  38.                     modified since the mains target was last run. This means we   
  39.                     can update a single main, then run the mains target and   
  40.                     only the updated main will get recompiled.   
  41.                 -->  
  42.                 <modified/>  
  43.                 <include name="**/*${application.name.flag}.mxml" />  
  44.                 <!--    
  45.                     For only building specific mains, comment out   
  46.                     the line above, and uncomment the line below and modify   
  47.                     as appropriate.   
  48.                 -->  
  49.                 <!--<include name="**/HorizontalAxisDataSelector_Sample.mxml" />-->  
  50.             </fileset>  
  51.                        
  52.             <sequential>  
  53.                 <propertyregex property="mainApplicationName" override="yes" input="@{file}"  
  54.                                         regexp=".*\${file.separator}(.*)${application.name.flag}.mxml" replace="\1" />  
  55.                 <propertyregex property="mainFolderName" override="yes" input="@{file}"  
  56.                                         regexp="(.*)\${file.separator}(.*)${application.name.flag}.mxml" replace="\1" />  
  57.            
  58.                 <exec executable="${mxmlc.exe}" dir="${basedir}">  
  59.                     <arg line="'@{file}'" />  
  60.                     <arg line="-o '${mainFolderName}/${mainApplicationName}${application.name.flag}.swf'" />  
  61.                        
  62.                     <arg line="-l '${lib.dir}'" />  
  63.                     <arg line="-l '${flexsdk.lib.dir}'" />  
  64.                     <arg line="-sp '${src.dir}'" />  
  65.                        
  66.                     <arg line="-optimize" />  
  67.   
  68.                     <arg line="-locale ${flexsdk.locale}" />  
  69.                     <arg line="-l '${flexsdk.locale.dir}'" />  
  70.                 </exec>  
  71.             </sequential>  
  72.         </for>  
  73.            
  74.     </target>  
  75.        
  76.     <!--  
  77.         Generate ASDoc output for the library  
  78.     -->  
  79.     <target name="docs" depends="properties">  
  80.         <!-- Clean out the contents of the doc directory, without deleting "docs" -->  
  81.            
  82.         <delete includeemptydirs="true">  
  83.             <fileset dir="${docs.dir}" includes="**/*" />  
  84.         </delete>  
  85.            
  86.         <exec executable="${asdoc.exe}" spawn="no">  
  87.             <!-- Place the documentation in the "docs" directory -->  
  88.             <arg line="-o '${docs.dir}'" />  
  89.                
  90.             <!-- Specify the main source path as "src" -->  
  91.             <arg line="-sp '${src.dir}'" />  
  92.                
  93.             <!-- Document all of the classes in the "src" tree -->  
  94.             <arg line="-ds '${src.dir}' " />  
  95.                
  96.             <!-- Include the library name in the window title -->  
  97.             <arg line="-window-title '${library.name}' "/>  
  98.                
  99.             <arg line="-templates-path '${flexsdk.templates.dir}' "/>  
  100.         </exec>  
  101.     </target>  
  102.   
  103.        
  104. </project>  
原文地址:https://www.cnblogs.com/moonvan/p/2301704.html