Ant錛屼互鎴戣嚜韜殑鐞嗚В錛屽畠鐨勪綔鐢ㄧ被浼間笌Linux涓嬬殑makefile錛屽彲浠ュ杞歡欏圭洰榪涜緙栬瘧銆佺敓鎴愭枃妗c佸崟鍏冩祴璇曘佹墦鍖呫侀儴緗茬瓑錛涗絾鍙堜笉鍚屼笌makefile錛屽洜涓簃akefile鏄熀浜巗hell鐨勬瀯寤哄伐鍏鳳紝浣咥nt鏄熀浜嶫ava鐨勬瀯寤哄伐鍏鳳紝涓斾嬌鐢↗ava璇█鍙互寰堝鏄撶殑瀵瑰畠榪涜鎵╁睍錛孉nt鏄熀浜嶺ML鐨勪功鍐欐牸寮忋?/p>
涓銆佸畨瑁匒nt
1銆?nbsp; 鍏堝皢Ant瑙e帇鍒頒竴涓洰褰曪紝鍋囧瑙e帇鍒癉:\ant
2銆?nbsp; 璁劇疆鐜鍙橀噺
set ANT_HOME=d:\ant
set PATH=%PATH%;%ANT_HOME%\bin
浜屻佷嬌鐢ˋnt
Ant鐨勬瀯寤烘枃浠舵槸鐢╔ML鏍煎紡涔﹀啓鐨勶紝姣忎釜build鏂囦歡鍖呭惈涓涓猵roject鍜岃嚦灝戜竴涓粯璁ょ殑target銆?/p>
<?xml version="1.0" encoding="UTF-8"?>
<project name="jartest" default="jar" basedir=".">
<target name="jar" depends="war">
<jar jarfile="${basedir}/Operation.jar">
<fileset dir="bin">
<include name="**/*.class" />
</fileset>
<!--
<fileset dir="src">
<include name="jndi.properties"/>
</fileset>
-->
</jar>
</target>
<target name="war">
<war warfile="OperationTest.war" webxml="web/WEB-INF/web.xml">
<fileset dir="web">
<include name="**/*.jsp"/>
</fileset>
</war>
</target>
</project>
1銆?nbsp; Project
Project鏈変笁涓睘鎬ame錛宒efault錛宐asedir
Name錛歅roject鐨勫悕瀛?/p>
Default錛歜uild鏂囦歡榪愯鏃墮粯璁ょ殑target
Basedir錛氳繘琛岄」鐩瀯寤虹殑鏍圭洰褰曪紝濡傛灉娌℃湁璁劇疆姝ら」錛屽垯榛樿涓巄uild鏂囦歡鍚岀洰褰?/p>
2銆?nbsp; Target
涓涓猅arget鍙互渚濊禆浜庡叾瀹冨涓猅arget錛?/p>
<target name="A"/>
<target name="B" depends="A"/>
鎯寵鎵цB蹇呴渶鍏堟墽琛孉
Target鐨勫睘鎬э細(xì)name錛宒epends錛宨f錛寀nless錛宒escription
Name錛歍arget鐨勫悕瀛?/p>
Depends錛氭墽琛屽綋鍓峊arget鏃墮渶瑕佷緷璧栫殑Target
If錛氳繖涓睘鎬х殑鍚嶅瓧蹇呴渶璁劇疆錛屽綋鍓嶇殑Target鎵嶈兘鎵ц
<target name="A" if="file"/>
Unless錛氳繖涓睘鎬х殑鍚嶅瓧蹇呴渶涓嶈兘璁劇疆錛屽綋鍓嶇殑Target鎵嶈兘鎵ц
<target name="A" unless="file"/>
Description錛氬褰撳墠Target鐨勪竴孌墊弿榪?/p>
3銆?nbsp; Tasks
鍏蜂綋闇姹傛墽琛岀殑浠誨姟錛岃繖涓氨鏈夊緢澶氫簡(jiǎn)錛屽錛歐AR, EAR, JAVAC, JAVA, JAR, COPY, COPYDIR, COPYFILE, MKDIR, MOVE, DELETE, ECHO, EXEC, UNZIP, ZIP, TAR, UNJAR, UNTAR, UNWAR, SCP, FTP, TELNET, 絳夌瓑錛屼互涓嬫槸鍚凾ask鐨勫睘鎬т粙緇嶏細(xì)
錛?錛?nbsp; Javac錛氱紪璇慗ava婧愭枃浠?/p>
Srcdir錛欽ava鏂囦歡鐨勭洰褰?/p>
Destdir錛欳lass鏂囦歡鐨勪繚瀛樼洰褰?/p>
Includes錛氶渶瑕佸寘鍚摢浜涙枃浠?/p>
Excludes錛氫笉鍖呭惈鍝簺鏂囦歡
Classpath錛氱紪璇戞椂闇瑕佸紩鐢ㄧ殑classpath
Debug錛氱紪璇戞椂鏄惁鍖呭惈debug淇℃伅
<javac destdir="${build}" classpath="xyz.jar" debug="on">
<src path="${src}"/>
<src path="${src2}"/>
<include name="mypackage/p1/**"/>
<include name="mypackage/p2/**"/>
<exclude name="mypackage/p1/testpackage/**"/>
</javac>
錛?錛?nbsp; Java錛氳繍琛宑lass鏂囦歡
Classname錛氶渶瑕佹墽琛岀殑class鏂囦歡鍚?/p>
Jar錛氶渶瑕佹墽琛岀殑jar鏂囦歡錛屽繀欏誨寘鍚▼搴忓叆鍙g被錛屾湁Main鏂規(guī)硶鐨勭被
Args錛氭墽琛宑lass闇瑕佺殑鍙傛暟
Classpath錛氶渶瑕佷嬌鐢ㄧ殑classpath
<java jar="dist/test.jar" fork="true" failonerror="true" maxmemory="128m">
<arg value="-h"/>
<classpath>
<pathelement location="dist/test.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
錛?錛?nbsp; Jar錛氬皢澶氫釜class鏂囦歡鎵撴垚涓涓猨ar鍖?/p>
Destfile錛氶渶瑕佸垱寤虹殑jar鏂囦歡鍚?/p>
Basedir錛氭枃浠剁殑鏉ユ簮
Includes錛氶渶瑕佸寘鍚摢浜涙枃浠?/p>
Excludes錛氫笉鍖呭惈鍝簺鏂囦歡
<jar destfile="${dist}/lib/app.jar"
basedir="${build}/classes"
includes="mypackage/test/**"
excludes="**/Test.class"
/>
錛?錛?nbsp; War錛氬皢鏂囦歡鎵撳寘鎴怶ar鏂囦歡
Destfile錛氶渶瑕佸垱寤虹殑war鏂囦歡鍚?/p>
Webxml錛歸eb.xml鏂囦歡鐨勮礬寰勫強(qiáng)鏂囦歡鍚?/p>
Basedir錛氭枃浠剁殑鏉ユ簮
Includes錛氶渶瑕佸寘鍚摢浜涙枃浠?/p>
Excludes錛氫笉鍖呭惈鍝簺鏂囦歡
<war destfile="myapp.war" webxml="src/metadata/myapp.xml">
<fileset dir="src/html/myapp"/>
<fileset dir="src/jsp/myapp"/>
<lib dir="thirdparty/libs">
<exclude name="jdbc1.jar"/>
</lib>
<classes dir="build/main"/>
<zipfileset dir="src/graphics/images/gifs"
prefix="images"/>
</war>
錛?錛?nbsp; Ear錛氬皢鏂囦歡鎵撳寘鎴怑ar鏂囦歡
Destfile錛氶渶瑕佸垱寤虹殑ear鏂囦歡鍚?/p>
appxml錛歁ETA-INF/application.xml鏂囦歡鐨勮礬寰勫強(qiáng)鏂囦歡鍚?/p>
Basedir錛氭枃浠剁殑鏉ユ簮
Includes錛氶渶瑕佸寘鍚摢浜涙枃浠?/p>
Excludes錛氫笉鍖呭惈鍝簺鏂囦歡
<ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
<fileset dir="${build.dir}" includes="*.jar,*.war"/>
</ear>
錛?錛?nbsp; Mkdir錛氬垱寤轟竴涓洰褰?/p>
<mkdir dir="${dist}"/>
錛?錛?nbsp; Delete錛氬垹闄や竴涓枃浠訛紝鎴栨枃浠跺す鍙?qiáng)鍏跺寘鍚殑鏂囦?/p>
File錛氶渶瑕佸垹闄ょ殑鏂囦歡鍚?/p>
Dir錛氶渶瑕佸垹闄ょ殑鐩綍
<delete file="/lib/ant.jar"/>
<delete dir="lib"/>
<delete>
<fileset dir="." includes="**/*.bak"/>
</delete>
4銆?nbsp; Properties
涓涓狿roject鍙互璁劇疆澶氫釜Property錛屽彲浠ュ湪build鏂囦歡鍐呬嬌鐢紝涔熷彲浠ラ氳繃Ant鍛戒護(hù)浣跨敤
錛?錛?鍦╞uild鏂囦歡鍐?/p>
<property name="build" location="build"/>
<delete dir="${build}"/>
錛?錛?閫氳繃Ant鍛戒護(hù)錛屼嬌鐢ㄩ夐」涓猴細(xì)-Dproperty=value
<property name="build" location="build"/>
鎵цAnt鍛戒護(hù)錛歛nt –Dbuild=aa 鍒檒ocation鐨勫煎氨鍙樹(shù)負(fù)aa浜?/p>
璁劇疆Property鐨勫叚縐嶆柟寮?/p>
錛?錛?閫氳繃name錛寁alue鐨勫睘鎬ц緗?/p>
<property name="foo.dist" value="dist"/>
錛?錛?閫氳繃name錛宺efid鐨勫睘鎬ц緗?/p>
錛?錛?閫氳繃file錛寀rl錛宺esource灞炴ц緗紝foo.properties鏄敭鍊煎鐨勫睘鎬ф枃浠?/p>
<property file="foo.properties"/>
<property resource="foo.properties"/>
<property url=">
錛?錛?閫氳繃environment灞炴ц緗紝鑾峰緱鐜鍙橀噺
<property environment="env"/>
<echo message="ANT_HOME is set to = ${env.ANT_HOME}"/>
涓夈佽繍琛孉nt
ant [options] [target [target2 [target3] ...]]
Options:
-help, -h print this message
-projecthelp, -p print project help information
-version print the version information and exit
-diagnostics print information that might be helpful to
diagnose or report problems.
-quiet, -q be extra quiet
-verbose, -v be extra verbose
-debug, -d print debugging information
-emacs, -e produce logging information without adornments
-lib <path> specifies a path to search for jars and classes
-logfile <file> use given file for log
-l <file> ''
-logger <classname> the class which is to perform logging
-listener <classname> add an instance of class as a project listener
-noinput do not allow interactive input
-buildfile <file> use given buildfile
-file <file> ''
-f <file> ''
-D<property>=<value> use value for given property
-keep-going, -k execute all targets that do not depend
on failed target(s)
-propertyfile <name> load all properties from file with -D
properties taking precedence
-inputhandler <class> the class which will handle input requests
-find <file> (s)earch for buildfile towards the root of
-s <file> the filesystem and use it
-nice number A niceness value for the main thread:
1 (lowest) to 10 (highest); 5 is the default
-nouserlib Run ant without using the jar files from ${user.home}/.ant/lib
-noclasspath Run ant without using CLASSPATH
濡傦細(xì)ant -buildfile test.xml -Dbuild=build/classes dist