【问题标题】:Compiling mxml files with ant and flex sdk使用 ant 和 flex sdk 编译 mxml 文件
【发布时间】:2008-09-16 23:10:27
【问题描述】:

我刚刚开始使用 flex,并且正在使用 SDK(不是 Flex Builder)。我想知道从 ant 构建脚本编译 mxml 文件的最佳方法是什么。

【问题讨论】:

    标签: apache-flex ant mxml


    【解决方案1】:

    Flex SDK 附带一组 ant 任务。更多信息:

    http://livedocs.adobe.com/flex/3/html/help.html?content=anttasks_1.html

    这是一个使用 ant 编译 Flex SWC 的示例:

    http://www.mikechambers.com/blog/2006/05/19/example-using-ant-with-compc-to-compile-swcs/

    麦克室

    【讨论】:

    • 我可以在某处获取 mxmlc SWC 文件还​​是必须自己编译?我可以使用 mxmlc ant 标记很好地编译 actionscript,但相同的脚本不适用于 mxml 文件。我试图在我的目标中使用 java jar 文件但没有成功。谢谢!
    【解决方案2】:

    我肯定会使用 Flex 中包含的 ant 任务,它们使您的构建脚本更加简洁。这是一个示例构建脚本,它将编译然后运行您的 flex 项目

    <?xml version="1.0"?>
    
    <project name="flexapptest" default="buildAndRun" basedir=".">
    
        <!-- 
            make sure this jar file is in the ant lib directory 
            classpath="${ANT_HOME}/lib/flexTasks.jar" 
        -->
        <taskdef resource="flexTasks.tasks" />
        <property name="appname" value="flexapptest"/>
        <property name="appname_main" value="Flexapptest"/>
        <property name="FLEX_HOME" value="/Applications/flex_sdk_3"/>
        <property name="APP_ROOT" value="."/>
        <property name="swfOut" value="dist/${appname}.swf" />
        <!-- point this to your local copy of the flash player -->
        <property name="flash.player" location="/Applications/Adobe Flash CS3/Players/Flash Player.app" />
    
        <target name="compile">
            <mxmlc file="${APP_ROOT}/src/${appname_main}.mxml"
                output="${APP_ROOT}/${swfOut}" 
                keep-generated-actionscript="true">
    
                <default-size width="800" height="600" />
                <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
                <source-path path-element="${FLEX_HOME}/frameworks"/>
                <compiler.library-path dir="${APP_ROOT}/libs" append="true">
                    <include name="*.swc" />
                </compiler.library-path>
            </mxmlc>
        </target>
    
        <target name="buildAndRun" depends="compile">
            <exec executable="open">
                <arg line="-a '${flash.player}'"/>
                <arg line="${APP_ROOT}/${swfOut}" />
            </exec>
        </target>
    
        <target name="clean">
            <delete dir="${APP_ROOT}/src/generated"/>
            <delete file="${APP_ROOT}/${swfOut}"/>
        </target>
    
    </project>
    

    【讨论】:

      【解决方案3】:

      还有另一种选择 - 它称为Project Sprouts

      这是一个使用 Ruby、RubyGems 和 Rake 构建的系统,提供了 Maven 和 ANT 中的许多功能,但语法更简洁,构建脚本更简单。

      例如,上面显示的 ANT 脚本在 Sprouts 中将如下所示:

      require 'rubygems'
      require 'sprout'
      
      desc 'Compile and run the SWF'
      flashplayer :run => 'bin/SomeProject.swf'
      
      mxmlc 'bin/SomeProject.swf' do |t|
        t.input = 'src/SomeProject.as'
        t.default_size = '800 600'
        t.default_background_color = '#ffffff'
        t.keep_generated_actionscript = true
        t.library_path << 'libs'
      end
      
      task :default => :run
      

      安装 Ruby 和 RubyGems 后,您只需调用此脚本:

      rake
      

      要删除生成的文件,请运行:

      rake clean
      

      查看可用任务:

      rake -T
      

      Sprouts 安装后的另一个巨大好处是,它提供了项目、类和测试生成器,可以通过几个简单的命令行操作让任何开发框准备好运行。

      # Generate a project and cd into it:
      sprout -n mxml SomeProject
      cd SomeProject
      
      # Compile and run the main debug SWF:
      rake
      
      # Generate a new class, test case and test suite:
      script/generate class utils.MathUtil
      
      # Compile and run the test harness:
      rake test
      

      【讨论】:

      • 感谢 rake 的介绍,但我搜索了有关 ant 的信息。顺便说一句,shell 脚本“mxmlc”将是一行。
      【解决方案4】:

      如果您对 Maven 持开放态度,请尝试使用 flex-compiler-mojo 插件:

      http://code.google.com/p/flex-mojos/

      克里斯蒂安

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-10-20
        • 1970-01-01
        • 2013-08-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-01
        • 2013-02-18
        相关资源
        最近更新 更多