Ant 攻略

          1? Ant 是什么?
          Ant 是一種基于 Java XML build 工具。

          2 下載、安裝 Ant
          安裝 Ant
          下載 .zip 文件,解壓縮到 c:\ant1.3( 后面引用為 %ANT_HOME%)

          2.1
          在你運行 Ant 之前需要做一些配置工作。
          ·
          bin 目錄加入 PATH 環境變量。
          ·
          設定 ANT_HOME 環境變量,指向你安裝 Ant 的目錄。在一些 OS 上, Ant 的腳本可以猜測 ANT_HOME Unix Windos NT/2000 )-但最好不要依賴這一特性。
          ·
          可選地,設定 J***A_HOME 環境變量(參考下面的高級小節),該變量應該指向你安裝 JDK 的目錄。
          注意:不要將 Ant ant.jar 文件放到 JDK/JRE lib/ext 目錄下。 Ant 是個應用程序,而 lib/ext 目錄是為 JDK 擴展使用的(如 JCE JSSE 擴展)。而且通過擴展裝入的類會有安全方面的限制。
          2.2
          運行 Ant

          運行 Ant 非常簡單,當你正確地安裝 Ant 后,只要輸入 ant 就可以了。

          n
          沒有指定任何參數時, Ant 會在當前目錄下查詢 build.xml 文件。如果找到了就用該文件作為 buildfile 。如果你用 -find 選項。 Ant 就會在上級目錄中尋找 buildfile ,直至到達文件系統的根。要想讓 Ant 使用其他的 buildfile ,可以用參數 -buildfile file ,這里 file 指定了你想使用的 buildfile

          n
          可以指定執行一個或多個 target 。當省略 target 時, Ant 使用標簽 <project> default 屬性所指定的 target


          命令行選項總結:
          ant [options] [target [target2 [target3] ...]]
          Options:
          -help print this message
          -projecthelp print project help information
          -version print the version information and exit
          -quiet be extra quiet
          -verbose be extra verbose
          -debug print debugging information
          -emacs produce logging information without adornments
          -logfile file use given file for log output
          -logger classname the class that is to perform logging
          -listener classname add an instance of class as a project listener
          -buildfile file use specified buildfile
          -find file search for buildfile towards the root of the filesystem and use the first one found
          -Dproperty=value set property to value
          例子
          ant
          使用當前目錄下的 build.xml 運行 Ant ,執行缺省的 target
          ant -buildfile test.xml
          使用當前目錄下的 test.xml 運行 Ant ,執行缺省的 target
          ant -buildfile test.xml dist
          使用當前目錄下的 test.xml 運行 Ant ,執行一個叫做 dist target
          ant -buildfile test.xml -Dbuild=build/classes dist
          使用當前目錄下的 test.xml 運行 Ant ,執行一個叫做 dist target ,并設定 build 屬性的值為 build/classes

          3 編寫 build.xml

          Ant
          buildfile 是用 XML 寫的。每個 buildfile 含有一個 project

          buildfile
          中每個 task 元素可以有一個 id 屬性,可以用這個 id 值引用指定的任務。這個值必須是唯一的。(詳情請參考下面的 Task 小節)

          3.1 Projects

          project
          有下面的屬性:
          Attribute Description Required
          name
          項目名稱 . No
          default
          當沒有指定 target 時使用的缺省 target Yes
          basedir
          用于計算所有其他路徑的基路徑。該屬性可以被 basedir property 覆蓋。當覆蓋時,該屬性被忽略。如果屬性和 basedir property 都沒有設定,就使用 buildfile 文件的父目錄。 No
          項目的描述以一個頂級的 <description> 元素的形式出現(參看 description 小節)。

          一個項目可以定義一個或多個 target 。一個 target 是一系列你想要執行的。執行 Ant 時,你可以選擇執行那個 target 。當沒有給定 target 時,使用 project default 屬性所確定的 target

          3.2 Targets

          一個 target 可以依賴于其他的 target 。例如,你可能會有一個 target 用于編譯程序,一個 target 用于生成可執行文件。你在生成可執行文件之前必須先編譯通過,所以生成可執行文件的 target 依賴于編譯 target Ant 會處理這種依賴關系。

          然而,應當注意到, Ant depends 屬性只指定了 target 應該被執行的順序-如果被依賴的 target 無法運行,這種 depends 對于指定了依賴關系的 target 就沒有影響。

          Ant
          會依照 depends 屬性中 target 出現的順序(從左到右)依次執行每個 target 。然而,要記住的是只要某個 target 依賴于一個 target ,后者就會被先執行。
          <target name="A"/>
          <target name="B" depends="A"/>
          <target name="C" depends="B"/>
          <target name="D" depends="C,B,A"/>
          假定我們要執行 target D 。從它的依賴屬性來看,你可能認為先執行 C ,然后 B ,最后 A 被執行。錯了, C 依賴于 B B 依賴于 A ,所以先執行 A ,然后 B ,然后 C ,最后 D 被執行。

          一個 target 只能被執行一次,即時有多個 target 依賴于它(看上面的例子)。

          如果(或如果不)某些屬性被設定,才執行某個 target 。這樣,允許根據系統的狀態( java version, OS, 命令行屬性定義等等)來更好地控制 build 的過程。要想讓一個 target 這樣做,你就應該在 target 元素中,加入 if (或 unless )屬性,帶上 target 因該有所判斷的屬性。例如:
          <target name="build-module-A" if="module-A-present"/>
          <target name="build-own-fake-module-A" unless="module-A-present"/>
          如果沒有 if unless 屬性, target 總會被執行。

          可選的 description 屬性可用來提供關于 target 的一行描述,這些描述可由 -projecthelp 命令行選項輸出。

          將你的 tstamp task 在一個所謂的初始化 target 是很好的做法,其他的 target 依賴這個初始化 target 。要確保初始化 target 是出現在其他 target 依賴表中的第一個 target 。在本手冊中大多數的初始化 target 的名字是

          posted on 2006-11-21 17:58 Timothy 閱讀(267) 評論(0)  編輯  收藏 所屬分類: J2EE開發環境

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          公告

          語義Web : 網絡就是計算機,軟件就是服務!

          常用鏈接

          留言簿(4)

          隨筆檔案(20)

          文章分類(25)

          文章檔案(25)

          新聞分類(4)

          新聞檔案(4)

          相冊

          收藏夾(27)

          個人主頁

          網絡博客

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 三门峡市| 衢州市| 襄汾县| 靖西县| 本溪市| 武威市| 岢岚县| 梨树县| 揭阳市| 灵川县| 湘阴县| 福州市| 伊春市| 柏乡县| 彰化市| 丹棱县| 怀化市| 务川| 凌云县| 冀州市| 武陟县| 武强县| 虹口区| 永福县| 屯留县| 金山区| 万盛区| 长武县| 阿鲁科尔沁旗| 昂仁县| 左云县| 北京市| 苏尼特右旗| 绵阳市| 工布江达县| 汉阴县| 彝良县| 临澧县| 东平县| 闵行区| 嵩明县|