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.gitbook.net"/> <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:>