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)屬性:

<project name="Hello World Project" default="info"> <property name="sitename" value="www.yiibai.com"/> <target name="info"> Apache Ant version is ${ant.version} - You are
at ${sitename}

上述構建文件運行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:>

0 條評論,你可以發表評論,我們會進行改進
Comment author placeholder