-. Ant簡(jiǎn)介
Ant是一個(gè)類(lèi)似make的工具,用來(lái)編譯/運行/測試java程序。
構建、包裝和發(fā)布過(guò)程中幾乎每一件事都可以由Ant的任務(wù)來(lái)處理.
二.Ant的安裝及配置
你可以從Jakata網(wǎng)站下載預編譯的ANT,解壓至任一目錄;
設置自己的環(huán)境變量,即ANT_HOME,指向解壓目錄;
設置JAVA_HOME環(huán)境變量,指向jdk的根目錄;
三:用ant管理項目
Ant一啟動(dòng)就會(huì )自動(dòng)地加載一個(gè)叫做Build.xml的項目配置文件。如果想給這個(gè)項目配置文件取別的名字,你可以使用buildfile標記來(lái)運行ant,就像下面這樣:
ant -buildfile Project_configuration.xml
主要特點(diǎn):
使用xml文件作為配置文件,即build.xml;
可與junit作無(wú)縫整合,達到系統測試、編譯到發(fā)布的功能;
強大、詳細的報表功能;
控制靈活,可自定義要執行的任務(wù)組合。
build.xml主要節點(diǎn):
proejct 項目
name 指定工程名稱(chēng)
default 指定默認的target(即任務(wù))
basedir 指定系統的基本路徑
property 屬性,類(lèi)似于全局變量
name 變量名稱(chēng)
value 變量值
屬性訪(fǎng)問(wèn)方法: ${property}
內置屬性:
basedir 工程的路徑.
ant.file build文件的路徑.
ant.version 版本
ant.project.name 工程名
ant.java.version jvm版本
target 目標,即任務(wù)
name 指定目標名稱(chēng)
depends 指定所依整的目標
if 條件,可達到控制流程目的
unless
description
task 一小段的任務(wù)
reference 引用
通過(guò)refid屬性來(lái)引用在其他節中定義的id
內置命令:
<tstamp/> 建立時(shí)間
<mkdir dir="${var}"/> 建立目錄
編譯文件:
<javac srcdir="${src}" destdir="${classes}" debug="off">
<classpath refid="appclasspath"/>
<include name="**/*.java" />
</javac>
執行文件:
<exec executable="${base.dir}/email.bat" >
</exec>
junit命令:
<junit>
<classpath refid="appclasspath"/>
<classpath>
<pathelement location="${base.dir}/defaultroot/WEB-INF/classes"/>
</classpath>
<formatter type="xml"/>
<test name="junit.tests.AllTests" haltonfailure="no" outfile="result"/>
</junit>
<junitreport todir="./report">
<fileset dir=".">
<include name="result.xml"/>
</fileset>
<report format="noframes" todir="./report"/>
</junitreport>
四:運行ant
ant [options] [target [target2 [target3] ...]]
Options:
-logfile <file> use given file for log
-l <file> ‘‘
-buildfile <file> use given buildfile
-file <file> ‘‘
-f <file> ‘‘
-D<property>=<value> use value for given property
-propertyfile <name> load all properties from file with -D
properties taking precedence
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。