-. Ant簡介
Ant是一個類似make的工具,用來編譯/運行/測試java程序。 構(gòu)建、包裝和發(fā)布過程中幾乎每一件事都可以由Ant的任務(wù)來處理. 二.Ant的安裝及配置
你可以從Jakata網(wǎng)站下載預(yù)編譯的ANT,解壓至任一目錄; 設(shè)置自己的環(huán)境變量,即ANT_HOME,指向解壓目錄; 設(shè)置JAVA_HOME環(huán)境變量,指向jdk的根目錄; 三:用ant管理項目
Ant一啟動就會自動地加載一個叫做Build.xml的項目配置文件。如果想給這個項目配置文件取別的名字,你可以使用buildfile標記來運行ant,就像下面這樣:
ant -buildfile Project_configuration.xml 主要特點: 使用xml文件作為配置文件,即build.xml; 可與junit作無縫整合,達到系統(tǒng)測試、編譯到發(fā)布的功能; 強大、詳細的報表功能; 控制靈活,可自定義要執(zhí)行的任務(wù)組合。 build.xml主要節(jié)點:
proejct 項目
name 指定工程名稱 default 指定默認的target(即任務(wù)) basedir 指定系統(tǒng)的基本路徑 property 屬性,類似于全局變量
name 變量名稱 value 變量值 屬性訪問方法: ${property} 內(nèi)置屬性:
basedir 工程的路徑. ant.file build文件的路徑. ant.version 版本 ant.project.name 工程名 ant.java.version jvm版本 target 目標,即任務(wù)
name 指定目標名稱 depends 指定所依整的目標 if 條件,可達到控制流程目的 unless description task 一小段的任務(wù) reference 引用 通過refid屬性來引用在其他節(jié)中定義的id 內(nèi)置命令:
<tstamp/> 建立時間 <mkdir dir="${var}"/> 建立目錄 編譯文件: <javac srcdir="${src}" destdir="${classes}" debug="off"> <classpath refid="appclasspath"/> <include name="**/*.java" /> </javac> 執(zhí)行文件: <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 |
|