Ant属性任务 - ANT
Ant构建文件是用XML编写的,它不迎合声明变量,你在最喜欢的编程语言做的。然而,正如你可能已经想到,它会如果允许Ant声明变量,如项目名称,项目源代码目录等有用
Ant使用属性元素,它允许你指定的属性。这允许属性从一个版本改变为另一个。或者从一个环境到另一个。
默认情况下,Ant提供了可以在构建文件中使用下列预定义的属性
属性 | 描述 |
---|---|
ant.file | The full location of the build file. |
ant.version | The version of the Apache Ant installation. |
basedir | The basedir of the build, as specified in the basedir attribute of theproject element. |
ant.java.version | The version of the JDK that is used by Ant. |
ant.project.name | The name of the project, as specified in the name atrribute of theproject element |
ant.project.default-target | The default target of the current project |
ant.project.invoked-targets | Comma separated list of the targets that were invoked in the current project |
ant.core.lib | The full location of the ant jar file |
ant.home | The home directory of Ant installation |
ant.library.dir | The home directory for Ant library files - typically ANT_HOME/lib folder. |
Ant也使得系统性能(例如:文件分割符),可用于构建文件。
除了以上所述,用户可以使用属性元素定义附加属性。一个例子介绍如下展示了如何定义一个名为站点名称(sitename)属性:
<?xml version="1.0"?>
<project name="Hello World Project" default="info">
<property name="sitename" value="www.yiibai.com"/>
<target name="info">
<echo>Apache Ant version is ${ant.version} - You are
at ${sitename} </echo>
</target>
</project>
上述构建文件运行ant应该产生下面的输出:
C:>ant
Buildfile: C:uild.xml
info:
[echo] Apache Ant version is Apache Ant(TM) version 1.8.2
compiled on December 20 2010 - You are at www.yiibai.com
BUILD SUCCESSFUL
Total time: 0 seconds
C:>