運(yùn)行Ant非常簡(jiǎn)單,當(dāng)你正確地
安裝Ant后,只要輸入ant就可以了。
沒有指定任何參數(shù)時(shí),Ant會(huì)在當(dāng)前目錄下查詢build.xml文件。如果找到了就用該文件作為buildfile。如果你用
-find 選項(xiàng)。Ant就會(huì)在上級(jí)目錄中尋找buildfile,直至到達(dá)文件系統(tǒng)的根。要想讓Ant使用其他的buildfile,可以用參數(shù)
-buildfile file,這里
file指定了你想使用的buildfile。
你也可以設(shè)定一些屬性,以覆蓋buildfile中指定的屬性值(參看property task)??梢杂?
-Dproperty=value 選項(xiàng),這里
property是指屬性的名稱,而
value則是指屬性的值。也可以用這種辦法來(lái)指定一些環(huán)境變量的值。你也可以用property task來(lái)存取環(huán)境變量。只要將
-DMYVAR=%MYVAR% (Windows) 或
-DMYVAR=$MYVAR (Unix) 傳遞給Ant -你就可以在你的buildfile中用${MYVAR}來(lái)存取這些環(huán)境變量。
還有兩個(gè)選項(xiàng)
-quite,告訴Ant運(yùn)行時(shí)只輸出少量的必要信息。而
-verbose,告訴Ant運(yùn)行時(shí)要輸出更多的信息。
可以指定執(zhí)行一個(gè)或多個(gè)target。當(dāng)省略target時(shí),Ant使用標(biāo)簽<project>的default屬性所指定的target。
如果有的話,-projecthelp 選項(xiàng)輸出項(xiàng)目的描述信息和項(xiàng)目target的列表。先列出那些有描述的,然后是沒有描述的target。
命令行選項(xiàng)總結(jié):
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
使用當(dāng)前目錄下的build.xml運(yùn)行Ant,執(zhí)行缺省的target。
ant -buildfile test.xml
使用當(dāng)前目錄下的test.xml運(yùn)行Ant,執(zhí)行缺省的target。
ant -buildfile test.xml dist
使用當(dāng)前目錄下的test.xml運(yùn)行Ant,執(zhí)行一個(gè)叫做dist的target。
ant -buildfile test.xml -Dbuild=build/classes dist
使用當(dāng)前目錄下的test.xml運(yùn)行Ant,執(zhí)行一個(gè)叫做dist的target,并設(shè)定build屬性的值為build/classes。
文件
在Unix上,Ant的執(zhí)行腳本在做任何事之前都會(huì)source(讀并計(jì)算值)~/.antrc 文件;在Windows上,Ant的批處理文件會(huì)在開始時(shí)調(diào)用%HOME%\antrc_pre.bat,在結(jié)束時(shí)調(diào)用%HOME%\antrc_post.bat。你可以用這些文件配置或取消一些只有在運(yùn)行Ant時(shí)才需要的環(huán)境變量??聪旅娴睦?。
環(huán)境變量
包裹腳本(wrapper scripts)使用下面的環(huán)境變量(如果有的話):
- JAVACMD Java可執(zhí)行文件的絕對(duì)路徑。用這個(gè)值可以指定一個(gè)不同于JAVA_HOME/bin/java(.exe)的JVM。
- ANT_OPTS 傳遞給JVM的命令行變量-例如,你可以定義屬性或設(shè)定Java堆的最大值
手工運(yùn)行Ant
如果你自己動(dòng)手安裝(DIY)Ant,你可以用下面的命令啟動(dòng)Ant:
java -Dant.home=c:\ant org.apache.tools.ant.Main [options] [target]
這個(gè)命令與前面的ant命令一樣。選項(xiàng)和target也和用ant命令時(shí)一樣。這個(gè)例子假定你的CLASSPATH包含:
- ant.jar
- jars/classes for your XML parser
- the JDK‘s required jar/zip files