project

项目定义,一个ant文件就是一个 project,定义了项目名称,起始位置以及默认执行的 target。

<project name="Easily" basedir="." default="build">

property

属性定义,可以定义的属性包括:文件属性、字符串定义。

<property file="build.properties"/>
<property name="WIDTH" value="1200"/>
<property name="HEIGHT" value="750"/>
<property name="PROJECT_DIR" value="${basedir}/../"/>
<property name="SOURCE_DIR" value="${PROJECT_DIR}/src"/>

taskdef

任务定义,可以理解为具体执行的任务所需要的第三方库,比如编译 as3 就需要引入 flexTasks.jar ,比如在代码中需要用到 Math 的时候,需要引入 include Math,同样的道理。

<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar"/>

target

可以理解为 method,是 ant 执行的最小单位,每个 target 会有一个名称,可以主动的调用执行 。

<target name="build">

antcall

target 调用,用于执行 target 。

<antcall target="buildswf"/>

mxmlc

编译 as3 项目,生成 swf 文件,需要指定入口文件 file,输出文件 output 。

  • incremental 是否增量编译
  • define 编译参数
  • load-config 项目配置文件,有需要的话可以自己编写,没有不声明也可以
  • static-link-runtime-shared-libraries 运行时库是否静态链接
  • compiler.debug 调试信息
  • default-size 缺省尺寸
  • compiler.include-libraries 将指定目录下的 swc 文件编译进目标文件,不管项目中是否引用
  • compiler.library-path 将指定目录下的 swc 文件引入项目中,并将引用到的部分代码编译进目标文件
  • compiler.external-library-path 将指定目录下的 swc 文件引入项目中,作为外部链接,注意,运行时如果没有找到相关定义会报错
  • source-path 外部文件引用
<mxmlc file="${SOURCE_DIR}/Easily.as"
output="${OUTPUT_DIR}/Easily.swf"
show-actionscript-warnings="false"
actionscript-file-encoding="UTF-8"
keep-generated-actionscript="true"
use-resource-bundle-metadata="true"
incremental="false"> <define name="CONFIG::debug" value="true"/> <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<compiler.debug>true</compiler.debug> <!-- Set size of output SWF file. -->
<default-size width="${WIDTH}" height="${HEIGHT}"/> <!-- Include all these swcs -->
<compiler.include-libraries dir="${LIBS_DIR}" append="true">
<include name="*.swc" />
<exclude name="data.swc"/>
</compiler.include-libraries> <!-- Include the useful swcs -->
<compiler.library-path dir="${LIBS_DIR}" append="true">
<include name="*.swc"/>
</compiler.library-path> <!-- Reference the external swcs -->
<compiler.external-library-path dir="${LIBS_DIR}" append="true">
<include name="*.swc" />
</compiler.external-library-path> <source-path path-element="F:/My Documents/SVN/Box2D/src"/>
</mxmlc>

compc

编译 as3 项目,输出 swc 库,大部分选项都同 mxmlc ,需要注意的是 include-classes ,这个参数需要指定哪些类需要编译进 swc 中,格式是以空格为分隔符的类的字符串列表,比如: org.easily.astar.AStar org.easily.astar.BinaryHeap org.easily.astar.Grid org.easily.astar.Node

<compc output="${OUTPUT_DIR}/easily.swc"
include-classes="${CLASSES}"
optimize="true"
benchmark="true"
strict="true"
actionscript-file-encoding="utf-8"
locale="en_US"
allow-source-path-overlap="true"
use-resource-bundle-metadata="true"
incremental="false"> <static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<compiler.debug>false</compiler.debug>
<show-actionscript-warnings>false</show-actionscript-warnings> <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${SOURCE_DIR}"/>
<library-path dir="${PROJECT_DIR}/libs" includes="*" append="true"/>
<source-path path-element="F:/My Documents/SVN/Box2D/src"/>
</compc>

可以将类的定义放到另外一个文件中,比如 class.properties ,定义一个属性为 CLASSES=xx xx xx,ant 是有相关的 api 可以将相关的类定义找到并处理好,只是语法过于拧巴,我写了个 python 脚本来干这个事情:

import os

def findmatch(file_name, ext, excludes):
for exclude in excludes:
if file_name.find(exclude) != -1:
return False
return file_name.endswith(ext) def list_file(dir_name, ext, excludes):
result = []
for root, dirs, files in os.walk(dir_name):
result.extend(os.path.join(root, file_name) for file_name in files if findmatch(file_name, ext, excludes))
return result def list_class(root, root_sep, ext, excludes):
return (format_name(root_sep, file_name, ext) for file_name in list_file(root, ext, excludes)) def format_name(root_sep, file_name, ext):
return file_name.replace(ext, "").replace(root_sep, "").replace("\\", ".") def export_file(root_list, ext, excludes, out_file):
with open(out_file, "w") as f:
f.write("CLASSES=")
for root in root_list:
f.writelines(class_name + " " for class_name in list_class(root, root + "\\", ext, excludes)) def main():
root_list = [os.getcwd()+"\\..\\src"]
ext = ".as"
excludes = ["Test.as"]
out_file = "class.properties"
export_file(root_list, ext, excludes, out_file) if __name__ == "__main__":
main()

exec

执行脚本或者应用程序,可以指定应用程序和命令行参数。

<exec executable="/bin/sh">
<arg line = "-c 'php ${basedir}/../xml.php'" />
</exec>

Ant 常用语法及选项的更多相关文章

  1. python MVC、MTV 框架介绍 Django 模板系统常用语法

    Django 框架简介一.MVC框架和MTV框架1.MVC 全名Model View Controller,是软件工程中的一种软件架构模式,把软件系统分为三个基本部分.优势: 耦合性低 重用性高 生命 ...

  2. MySQL的DML常用语法格式

    MySQL的DML常用语法格式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我们知道MySQL的查询大致分为单表查询,多表查询以及联合查询.多表查询,顾名思义,就是查询的结果可能 ...

  3. python3+selenium常用语法汇总

    Selenium常用语法总结 一.Selenium常用定位语法 1.元素定位 (1)ID定位元素: find_element_by_id(‘’) (2)通过元素的类名称定位元素: find_eleme ...

  4. iptables常用语法与案例

    常用命令语法: [root@www ~]# iptables [-t tables] [-L] [-nv] 选项与参数: -t :后面接 table ,例如 nat 或 filter ,若省略此项目, ...

  5. Markdown通用的常用语法说明

    前言 Markdown 是一种轻量级的 标记语言,语法简洁明了.学习容易,还具有其他很多优点,目前被越来越多的人用来写作使用. Markdown具有一系列衍生版本,用于扩展Markdown的功能(如表 ...

  6. Markdown简介以及常用语法

    Markdown简介以及常用语法 最近发现用markdown记录东西很方便,感觉和emacs的org mode很类似,但是windows下使用emacs不是很方便.特此记录一下markdown常用的语 ...

  7. Sql常用语法以及名词解释

    Sql常用语法以及名词解释 SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) D ...

  8. Markdown常用语法

    什么是Markdown Markdown 是一种方便记忆.书写的纯文本标记语言,用户可以使用这些标记符号以最小的输入代价生成极富表现力的文档. 通过Markdown简单的语法,就可以使普通文本内容具有 ...

  9. 2 hive的使用 + hive的常用语法

    本博文的主要内容有: .hive的常用语法 .内部表 .外部表 .内部表,被drop掉,会发生什么? .外部表,被drop掉,会发生什么? .内部表和外部表的,保存的路径在哪? .用于创建一些临时表存 ...

随机推荐

  1. ios 使用AFN上传图片到服务器

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSe ...

  2. Tomcat发布项目方法

    第一种方法:    将已完成的项目(无论用jbuilder\eclipse\netbeans)下的webroot目录整个拷贝到Tomcat的webapps目录中,假若webroot目录改名为xxx,则 ...

  3. js兼容性问题总结

    JS中出现的兼容性问题的总结1.关于获取行外样式 currentStyle 和 getComputedStyle 出现的兼容性问题  我们都知道js通过style不可以获取行外样式,当我们需要获取行外 ...

  4. INNO SETUP 读取可变注册表路径的问题

    ;INNO 读取可变注册表路径的问题 ;问题:;我想自动为 FireFox 安装上 Real 的 Mozilla 插件~但是它的路径存放在"HKEY_CURRENT_USER\Softwar ...

  5. 完整安装cocoaPods

    cocoaPods是一款xcode项目管理第三方库的工具 *ruby源码镜像下载:https://ruby.taobao.org/mirrors/ruby/*升级gem的版本: $sudo gem u ...

  6. [转载]Back up all of your mysql databases nightly

    原文地址:http://www.linuxbrigade.com/back-up-all-of-your-mysql-databases-nightly/ Put the following into ...

  7. Python3基础 创建一个空列表,一个空元组

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  8. linux开发摘要

    1.linux内核文档链接点击打开链接 2.配置文件 在out\target\product\project\obj\KERNEL_OBJ\.config中可以看到 # CONFIG_MTD_LPDD ...

  9. 使用Json出现java.lang.NoClassDefFoundError解决方法

    前几天在项目使用到Json格式数据,于是把使用Json需要用到的包都引到了工程里面,程序写好后运行时,发现后台报 java.lang.NoClassDefFoundError: net/sf/json ...

  10. 【leetcode❤python】 165. Compare Version Numbers

    #-*- coding: UTF-8 -*-class Solution(object):    def compareVersion(self, version1, version2):       ...