首先下載ant在http://jakarta.apache.org/builds,然后解壓縮到本地,我把它壓縮到C:\ant目錄下 在環(huán)境變量修改屬性 在path屬性前增加------C:\ant\bin;這樣就可以使用ant了 build.xml文件都包含一個project和至少一個target元素,target元素中包含一個或多個任務(wù)元素,任務(wù)是一段可執(zhí)行的代碼。 根元素是project,三個屬性name,default,basedir name指定工程的名字 default指定工程默認(rèn)的target元素 basedir指定工程的基路徑,如果是“.”,表示為build.xml所在路徑 <project name="bookstore" default="about" basedir="."> <target name="init"> <!--初始化各個變量的名字--> <!--用到的環(huán)境變量的包--> <property environment="myenv" /> <mkdir dir="${build}" /><!--調(diào)用前面的目錄參數(shù)是${xxx}--> <copy todir="${build}" ><!--拷貝目錄文件到新的目錄下--> <target name="compile" depends="init"> <!--它依賴init的執(zhí)行,所以調(diào)用它先執(zhí)行init--> <javac srcdir="${src}"
<target name="bookstorewar" depends="compile"> <!--生成war的任務(wù)--> <war warfile="${build}/bookstore.war" webxml="${build}/WEB-INF/web.xml"> <target name="about" > <!--默認(rèn)的target--> </project>
我們這個build.xml在我們的應(yīng)用的根目錄下 所以運行ant的方法是:在DOS下 1.進(jìn)入C:\myApp,我們的應(yīng)用目錄下 輸入: ant (會搜索當(dāng)前路徑下的build.xml文件) 2.直接輸入ant -buildfile c:\myApp\build.xml 3.直接輸入ant -buildfile c:\myApp\build.xml about 以上三種方式都執(zhí)行about的target,如果指想編譯java文件,我們只要 ant -buildfile c:\myApp\build.xml compile |