ANT教程之三 Ant构建文件
2015-11-07 16:18
281 查看
通常情况下,Ant构建文件build.xml应该在项目的基础目录。可以自由使用其他文件名或将构建文件中其他位置。
在本练习中,创建一个名为build.xml 在电脑的任何地方的文件。
请注意,应该有XML声明之前没有空行或空格。该处理指令目标匹配"[xX][mM][lL]" 是不允许的 - 如果你这样做,这可能在运行Ant构建时造成的错误消息。
所有构建文件要求项目元素和至少一个目标元素。
XML元素的项目有三个属性:
一个目标是要作为一个单元运行的任务的集合。在我们的例子中,我们有一个简单的目标,以提供一个信息性消息给用户。
目标可以对其他目标的依赖关系。例如,部署目标可能对封装对象的依赖和包的目标可能具有依赖于compile目标等等。依赖关系是使用依赖属性表示。例如:
目标元素具有以下属性:
在上面的例子中的echo 任务是打印一条消息一个简单的任务。在我们的例子,它打印出Hello World消息。
要运行Ant构建文件,打开命令提示符并导航到build.xml文件所在的文件夹,然后输入ant info。也可以只输入ant来代替。既会工作,因为信息是默认的目标在构建文件。应该看到下面的输出:
在本练习中,创建一个名为build.xml 在电脑的任何地方的文件。
<?xml version="1.0"?> <project name="Hello World Project" default="info"> <target name="info"> <echo>Hello World - Welcome to Apache Ant!</echo> </target> </project>
请注意,应该有XML声明之前没有空行或空格。该处理指令目标匹配"[xX][mM][lL]" 是不允许的 - 如果你这样做,这可能在运行Ant构建时造成的错误消息。
所有构建文件要求项目元素和至少一个目标元素。
XML元素的项目有三个属性:
属性 | 描述 |
---|---|
name | The Name of the project. (Optional) |
default | The default target for the build script. A project may contain any number of targets. This attribute specifies which target should be considered as the default. (Mandatory) |
basedir | The base directory (or) the root folder for the project. (Optional) |
目标可以对其他目标的依赖关系。例如,部署目标可能对封装对象的依赖和包的目标可能具有依赖于compile目标等等。依赖关系是使用依赖属性表示。例如:
<target name="deploy" depends="pacakge"> .... </target> <target name="pacakge" depends="clean,compile"> .... </target> <target name="clean" > .... </target> <target name="compile" > .... </target>
目标元素具有以下属性:
属性 | 描述 |
---|---|
name | The name of the target (Required) |
depends | Comma separated list of all targets that this target depends on. (Optional) |
description | A short description of the target. (optional) |
if | Allows the execution of a target based on the trueness of a conditional attribute. (optional) |
unless | Adds the target to the dependency list of the specified Extension Point. An Extension Point is similar to a target, but it does not have any tasks. (Optional) |
要运行Ant构建文件,打开命令提示符并导航到build.xml文件所在的文件夹,然后输入ant info。也可以只输入ant来代替。既会工作,因为信息是默认的目标在构建文件。应该看到下面的输出:
C:>ant Buildfile: C:uild.xml info: [echo] Hello World - Welcome to Apache Ant! BUILD SUCCESSFUL Total time: 0 seconds C:>
相关文章推荐
- 6n8p+6P3p单端纯二线路胆机
- 一句话总结C++,Java,PHP
- quartz CronExpression表达式
- 第10周项目3-利用二叉树遍历思想解决问题
- Linux进程间通信
- Play 2, Scala, postgresql and Squeryl 整合
- 根据radio值设置是否选中状态
- 权限
- 【Java爬虫】爬取南通大学教务系统成绩计算绩点
- 信息安全系统设计基础第九周学习总结
- github开源项目smart-image-view
- vim的树形菜单NERDTREE的设置
- 深入理解Xfermode,使用时要注意以及顺便膜拜下saveLayer的强大
- 错误:Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." UserInfo={NSDebugDescription=Garbage
- Android 网络通信方式
- Vim插件管理利器——Vundle
- 举例讲解Linux系统下Python调用系统Shell的方法
- Vuforia Alaph Shader
- Direct3D 中绘制二维图像
- Xen I/O虚拟化原理——Xen下总线、设备和驱动