使用ANT批量编译Flex应用和模块(Use ANT to batch compiling application and modules of Flex)

使用ANT批量编译Flex应用和模块(Use ANT to batch compiling application and modules of Flex)
ANT提供了对mxmlc命令的支持,可以直接用来编译使用Flex为UI的JavaEE应用,如果你在Flex中也使用Module来作为你每个功能的组织形式,你不妨考虑用如下脚本去编译你的应用:
< target  name ="compileUI"   >
        
< echo  message ="start to compile Flex UI"   />
        
< for  param ="file" >
            
< path >
                
< fileset  dir ="${flexsrc.dir}" >
                    
< include  name ="**/*.mxml"   />
                
</ fileset >
            
</ path >
            
< sequential >         
                
< propertyregex  override ="yes"  property ="compile.target.name"  input ="@{file}"  regexp ="(.*)src(.*)(mxml)"  replace ="\1bin\2swf"   />
               
  < mxmlc  file ="@{file}"  output ="${compile.target.name}"
                    services
="${service.file}"  context-root ="${context.root}" >
                    
< load-config  filename ="${FLEX_HOME}/frameworks/flex-config.xml"   />
                    
< static-link-runtime-shared-libraries > false </ static-link-runtime-shared-libraries >
                    
< source-path  path-element ="${flexsrc.dir}"   />
                    
<!--  use incremental compiling -->
                    
< compiler .incremental > true </ compiler.incremental >
                    
< compiler .debug > false </ compiler.debug >
                    
                    
<!--  指定外部依赖库文件,这些库文件将不会编译进目标SWF中  -->
                    
< compiler .external-library-path dir ="${flexlib.dir}" >
                        
< include  name ="**/*.swc"   />
                    
</ compiler.external-library-path >
                
</ mxmlc >
                
<!--  清除缓存文件  -->
                
<!--
                <delete file="${compile.target.name}.cache" />
                
-->
                
< echo  message ="Compiled @{file} =====>>   ${compile.target.name}"   />
                
            
</ sequential >
        
</ for >

    
</ target >


注意事项:
1,必须使用ant-contrib包来支持for任务,使用for任务时,别忘了如下声明:
< path  id ="ant.classpath" >
        
< fileset  dir ="${ant.lib.dir}" >
            
< include  name ="*.jar"   />
        
</ fileset >
    
</ path >
    
< taskdef  resource ="net/sf/antcontrib/antlib.xml"  classpathref ="ant.classpath"   />

2,编译每个mxml时,可用propertyregex来得到output文件名,
3,source-path一定不能写错,或随便写,如果这样的话,会出现如下错误:
              Error: A file found in a source-path must have the same package structure
4,如果在运行的过程中出现Java heap size或permGen不足的情况,可以指定如下系统参数:
              ANT_OPTS=-XX:MaxPermSize=256M -Xmx1024m

你可能感兴趣的:(使用ANT批量编译Flex应用和模块(Use ANT to batch compiling application and modules of Flex))