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. z-index 详解

    Definition and Usage The z-index property specifies the stack order of an element. An element with g ...

  2. MVC5路由系统机制详细讲解

    请求一个ASP.NET mvc的网站和以前的web form是有区别的,ASP.NET MVC框架内部给我们提供了路由机制,当IIS接受到一个请求时,会先看是否请求了一个静态资源(.html,css, ...

  3. jQuery基本操作

    jQuery简介 jQuery是一个兼容多浏览器的javascript库,极大地简化了 JavaScript 编程,核心理念是write less,do more(写得更少,做得更多),对javasc ...

  4. 【转】关于字符编码,你所需要知道的(ASCII,Unicode,Utf-8,GB2312…)

    转载地址:http://www.imkevinyang.com/2010/06/%E5%85%B3%E4%BA%8E%E5%AD%97%E7%AC%A6%E7%BC%96%E7%A0%81%EF%BC ...

  5. Java基础应用

    Java集合类解析 List.Map.Set三个接口,存取元素时,各有什么特点? List 以特定次序来持有元素,可有重复元素.Set 无法拥有重复元素,内部排序.Map 保存key-value值,v ...

  6. iOS定时器的使用

    iOS开发中定时器经常会用到,iOS中常用的定时器有三种,分别是NSTime,CADisplayLink和GCD. NSTimer 方式1 // 创建定时器 NSTimer *timer = [NST ...

  7. c++打开浏览器

    调用外部命令 如果用默认浏览器,就调用ShellExecute(NULL, _T("open"), _T("explorer.exe"), _T("h ...

  8. 类加载机制(深入理解JAVA虚拟机学习笔记)

    1.类加载机制的定义 将class文件加载到内存,然后对class文件中的数据进行校验.解析和初始化,转换成可以被虚拟机直接使用的JAVA类型,这就是虚拟机的类加载机制.(在JAVA中,类的加载.连接 ...

  9. div css 自适应

    怎样实现响应式布局? 对于这个问题,我们可以通过CSS3中的Media Query来实现,即媒介查询.媒体查询让CSS可以更精确作用于不同的媒体类型和同一媒体的不同条件.媒体查询的大部分媒体特性都接受 ...

  10. GOLANG 基本数据类型 整型

    基本数据类型-整型 种类     有符号(负号)      int8 int16 int32 int64 无符号(无符号) uint8 uint16 uint32 uint64 架构特定(取决于系统位 ...