Ant 學(xué)習(xí)筆記
ant環(huán)境安裝配置
安裝
- apache官網(wǎng)下載問(wèn)價(jià)壓縮包
- 解壓到電腦的任意路徑
- 新建環(huán)境變量 ANT_HOME 值為 D:\apache-ant-1.9.6(解壓目錄)
- 編輯”系統(tǒng)變量“中的”P(pán)ath“增加%ANT_HOME%\bin(注意要用英文分號(hào)和其他值分開(kāi))
- 編輯”系統(tǒng)變量“中的”CLASSPATH“增加%ANT_HOME%\lib(注意要用英文分號(hào)和其他值分開(kāi))
驗(yàn)證是否安裝成功
打開(kāi)cmd命令框轨功,輸入ant -version ,如果輸出ant的版本號(hào),證明安裝成功
Ant構(gòu)建文件
文件名build.xml 褪子,通常在項(xiàng)目的基目錄
示例:
<?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>
project: 項(xiàng)目標(biāo)簽潘懊,具有以下屬性:
name:項(xiàng)目名稱(chēng) default:默認(rèn)執(zhí)行的目標(biāo)
target:目標(biāo) 具有以下屬性:
name:目標(biāo)的名稱(chēng)(必須) depends:依賴(lài) description:描述 if:允許目標(biāo)在某種條件下執(zhí)行 unless:將目標(biāo)添加到指定擴(kuò)展點(diǎn)的依賴(lài)項(xiàng)列表基协。擴(kuò)展點(diǎn)類(lèi)似于目標(biāo)洋措,但它沒(méi)有任何任務(wù)。(可選)
屬性 | 描述 |
---|---|
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) |
可以添加屬性文件 如build.properties
在build.xml中指定配置文件的名稱(chēng)
<property file="build.properties"/>
build.properties 文件內(nèi)容示例:
# The Site Name
sitename=www.yiibai.com
buildversion=3.3.2
src.dir=src
web.dir=war
build.dir=${web.dir}/WEB-INF/classes
name=fax