2010-11-25 91 views
3

我正在尝试使用Ant编译我的Flex 4项目。我可以编译主应用程序,我可以编译我的一些模块。任何在子包中都有依赖的模块没有说Error: Type was not found or was not a compile-time constant。我使用Flash Builder 4在Windows上完成了所有的开发工作,因此我可以编译所有内容,但是我需要将编译工作转移到基于Linux的无头的服务器上(这是Ant进来的地方)。使用Ant编译Flex模块

我创建了一个简单的项目来测试我的问题:

src-> Main.mxml 
|->modules 
     |-> module1-> Module1.mxml 
     |-> module2-> Module2.mxml 
       |-> subPackage-> SubClass.as 

模块1不使用其他类则Flex框架类,其中单词数有子类的实例。编译主应用程序工作正常,Module1也是如此。当它试图编译Module2时,我得到错误Error: Type was not found or was not a compile-time constant: SubClass.

我的全Ant脚本是:

<project name="Test" basedir="."> 

<property file="build.properties" /> 
<target name="properties"> 
    <fail unless="mxmlc">The "mxmlc" property must be set in build.properties.</fail> 
</target> 

<target name="build-app" depends="properties"> 
    <exec executable="${mxmlc}" dir="${src.dir}" failonerror="true"> 

     <!-- Point to the mxml file --> 
     <arg line="${app.name}.mxml" /> 

     <!-- Don\t generate debug swf --> 
     <arg line="-debug=false" /> 

     <!-- Generate optimized swf --> 
     <arg line="-optimize=true" /> 

     <!-- Don't build incrementally --> 
     <arg line="-incremental=false" /> 

     <!-- Place the built .swf file in the "bin" directory --> 
     <arg line="-output '${build.dir}/${app.name}.swf'" /> 

     <!-- 
      Create a linker report that lists all the classes already in the main app 
      This gets passed to the modules so that they don't load up the shared libs again. 
     --> 
     <arg line="-link-report='${temp.dir}/link-report.xml'"/> 

    </exec> 
</target> 

<target name="build-modules" description="Build Modules"> 
    <build.module dir="${module.dir}/module1" file="Module1"/> 
    <build.module dir="${module.dir}/module2" file="Module2"/> 
</target> 

<macrodef name="build.module"> 
    <attribute name="dir" /> 
    <attribute name="file" /> 
    <sequential> 
     <echo>@{file}</echo> 
     <exec executable="${mxmlc}" dir="${src.dir}" failonerror="true"> 
      <!-- Point to the mxml file --> 
      <arg line="'@{dir}/@{file}.mxml'" /> 

      <!-- Don't generate debug swf --> 
      <arg line="-debug=false" /> 

      <!-- Generate optimized swf --> 
      <arg line="-optimize=true" /> 

      <!-- Don't build incrementally --> 
      <arg line="-incremental=false" /> 

      <!-- Place the built .swf file in the "bin" directory --> 
      <arg line="-output '${module.build.dir}/@{file}.swf'" /> 

      <!-- Exclude all classes that are already in the main application --> 
      <arg line="-load-externs='${temp.dir}/link-report.xml'"/> 
     </exec> 
    </sequential> 
</macrodef> 

我完全茫然,为什么这是行不通的。

感谢,

--Ryan

+0

你是什么意思的“分装”?这些类是在同一个基本源目录中,还是不同的? – 2010-11-26 10:00:59

+0

在src目录中有一个名为“modules”的目录,其中有2个名为“module1”和“module2”的目录。 “module2”包含一个名为“subPackage”的目录,其中包含类“SubClass.as”。换句话说,所讨论的3个类是:modules.module1.Module1; modules.module2.Module2; modules.module2.subPackage.SubClass。 – Ryan 2010-11-30 13:47:55

回答

3

大量的研究,试验和错误和咒骂后,我终于找到了解决办法。最初我试图使用ANTs <exec>命令编译模块。在我的最终解决方案中,我确实将其更改为使用ANT的<mxmlc>目标(从flex SDK目录ant/lib/flexTasks.jar中的flexTasks.jar)。

<macrodef name="build.module"> 
    <attribute name="moduleDir" /> 
    <attribute name="dir" /> 
    <attribute name="file" /> 
    <sequential> 
     <echo>@{file}</echo> 
     <mxmlc file="@{moduleDir}/@{dir}/@{file}.mxml" 
       output='${module.build.dir}/@{dir}/@{file}.swf' 
       optimize="true" 
       debug="false" 
       load-externs="${temp.dir}/link-report.xml" 
       incremental="false" 
       fork="true" maxmemory="${maxMem}"> 
      <compiler.source-path path-element="${src.dir}"/> 
      <source-path path-element="${FLEX_HOME}/frameworks"/> 
      <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true"> 
       <include name="libs" /> 
      </compiler.library-path> 
      <source-path path-element="${src.dir}"/> 
      <compiler.library-path dir="${libs.dir}/" append="true"> 
       <include name="*" /> 
      </compiler.library-path> 
     </mxmlc> 
    </sequential> 
</macrodef> 

在这个新的宏中,我添加了更多的编译器选项。在设置源路径和编译器库选项(这告诉编译器要链接什么)后,一切运行良好。