ant 命令
ant的構建文件
一. ant 的構建文件:
1. 目錄結構:
??? antBook
??? antBook/src
??? antBook/build
??? antBook/build/classese
??? antBook/build/lib
?
1.? antBook/build.xml
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
?
<project name="simple Buildfile" default="compile" basedir=".">
<!-- The directory containing source code-->
<property name="src.dir" value="src"/>
<!-- Temporary build directories -->
<property name="build.dir" value="build"/>
<property name="build.classes" value="${build.dir}/classes"/>
<property name="build.lib" value="${build.dir}/lib"/>
<!--compile target-->
<target name="prepare">
? <mkdir dir="${build.dir}"/>
? <mkdir dir="${build.classes}"/>
? <mkdir dir="${build.lib}"/>
</target>
<target name="clean" description="removes all generated files.">
? <delete dir="${build.dir}"/>
</target>
<target name="compile" depends="prepare" description="編譯文件">
? <javac srcdir="${src.dir}" destdir="${build.classes}"/>
</target>
<target name="jar" depends="compile" description="壓縮成jar">
? <jar jarfile="${build.lib}/oreilly.jar" basedir="${build.classes}"
? ?excludes="**/*Test.class"/>
</target>
<target name="all" depends="clean,jar" description="cleans,compiles.."/>
</project>
?
2. ant運行時會顯示每個所執行到的目標的名字,ant 先執行了prepare,其后才執行compile,這是因為compile是默認目標,而它對prepare目標存在一個依賴關系。
?
3. ant運行指定的構建文件時,命令如下:
??? ant? -buildfile? *.xml????
??? ant? -buildfile? *.xml clean
?
4. 可以運行一條命令執行多個目標:
??? ant clean jar
?
5.可以輸入ant all 來完成清理和重新構建, 因為all依賴于clean和 jar. 而jar進一步依賴compile,compile則依賴于prepare, 這樣一條簡單的命令ant all 既可以按適當的順序完成所以目標。
?
6. 獲得描述信息:
?? 包含description屬性的為主目標,沒有描述的則為子目標。
從工程的基目錄鍵入: ant -projecthelp 可獲得如下輸出信息:
?
Main targets:
?all????? cleans,compiles..
?clean??? removes all generated files.
?compile? 編譯文件
?jar????? 壓縮成jar"
Default target: compile
?
7. 獲得ant 命令行參數:? 鍵入ant -help
?
-help:?
??? 顯示描述ant 命令及其選項的幫助信息。
?
-projecthelp:
???? 顯示description屬性中的文本信息
?
-version : 顯示ant版本信息
?
-quiet :
?? 抑制并非由構建文件中的echo任務所產生的大多數消息。
?
-verbose:
?? 顯示構建過程中每個操作的詳細信息,此選項與-debug只能選擇其一。
?
-debug
?? 顯示ANT和任務開發人員已經標志為調式消息的消息,此選項與-verbose只能選其一。
?
-emacs
?? 對日志消息進行格式化,使他們能夠很容易的由emacs的shell模式所解析; 也就是說,打印任務事件,但并不縮排,在期之前也沒有[taskname].
?
-logger classname
?? 指定一個類來處理ANT 的日志記錄,所指定的類必須實現了org.apache.tools.ant.BuildLogger接口。
?
-listener classname
??? 為ANT 聲明一個監聽類,并增加到其監聽者列表中,在ANT與IDE或者其他JAVA程序集成時,此選項非常有用。
必須將所指定的監聽類編寫為可以處理ANT的構建消息接發。
?
-buildfile filename
?? 指定ant需要處理的文件, 默認的構建文件為build.xml
?
-Dproperty=value
??? 在命令行上定義一個特殊名-值對。
?
-find filename
?? 指定ant應當處理的構建文件。 與-buildfile選項不同,如果所指定文件在當前目錄中未找到,-file就要求ant在其父目錄中再進行搜索,這種搜索會繼續在其祖目錄中進行,直到到達文件系統根目錄為止, 在此如果文件還未找到則構建失敗。
?
?
8. 構建文件的幾點事項:
?
(1. 所有構建文件都要有<project >元素, 而且至少有一個<target>元素。
?
(2. 對于<project >元素的default屬性并沒有默認值。
?
(3. 構建文件并不一定要命名為build.xml,ant默認搜索該文件。
?
(4. 每個構建文件只有一個<project >元素。
?
總結
- 上一篇: linux 查看文件和文件夹大小
- 下一篇: ant system property