銆銆Eclipse 涓凡緇忛泦鎴愪簡(jiǎn)Ant錛屾垜浠彲浠ョ洿鎺ュ湪Eclipse涓繍琛孉nt銆?/P>
銆銆浠ュ墠闈㈠緩绔嬬殑Hello宸ョ▼涓轟緥錛屽垱寤轟互涓嬬洰褰曠粨鏋勶細(xì)
銆銆鏂板緩涓涓猙uild.xml錛屾斁鍦ㄥ伐紼嬫牴鐩綍涓嬨俠uild.xml瀹氫箟浜?jiǎn)Ant瑕佹墽琛岀殑鎵瑰鐞嗗懡浠ゃ傝櫧鐒禔nt涔熷彲浠ヤ嬌鐢ㄥ叾瀹冩枃浠跺悕錛屼絾鏄伒寰爣鍑嗚兘鏇翠嬌寮鍙戞洿瑙勮寖錛屽悓鏃舵槗浜庝笌鍒漢浜ゆ祦銆?/P>
銆銆閫氬父錛宻rc瀛樻斁Java婧愭枃浠訛紝classes瀛樻斁緙栬瘧鍚庣殑class鏂囦歡錛宭ib瀛樻斁緙栬瘧鍜岃繍琛岀敤鍒扮殑鎵鏈塲ar鏂囦歡錛寃eb瀛樻斁JSP絳墂eb鏂囦歡錛宒ist瀛樻斁鎵撳寘鍚庣殑jar鏂囦歡錛宒oc瀛樻斁API鏂囨。銆?/P>
銆銆鐒跺悗鍦ㄦ牴鐩綍涓嬪垱寤篵uild.xml鏂囦歡錛岃緭鍏ヤ互涓嬪唴瀹癸細(xì)
<xml version="1.0"?>
<roject name="Hello world" default="doc">
<-- properies -->
<roperty name="src.dir" value="src" />
<roperty name="report.dir" value="report" />
<roperty name="classes.dir" value="classes" />
<roperty name="lib.dir" value="lib" />
<roperty name="dist.dir" value="dist" />
<roperty name="doc.dir" value="doc"/>
<-- 瀹氫箟classpath -->
<ath id="master-classpath">
<ileset file="${lib.dir}/*.jar" />
<athelement path="${classes.dir}"/>
<path>
<-- 鍒濆鍖栦換鍔?-->
<arget name="init">
<target>
<-- 緙栬瘧 -->
<arget name="compile" depends="init" description="compile the source files">
<kdir dir="${classes.dir}"/>
<avac srcdir="${src.dir}" destdir="${classes.dir}" target="1.4">
<lasspath refid="master-classpath"/>
<javac>
<target>
<-- 嫻嬭瘯 -->
<arget name="test" depends="compile" description="run junit test">
<kdir dir="${report.dir}"/>
<unit printsummary="on"
haltonfailure="false"
failureproperty="tests.failed"
showoutput="true">
<lasspath refid="master-classpath" />
<ormatter type="plain"/>
<atchtest todir="${report.dir}">
<ileset dir="${classes.dir}">
<nclude name="**/*Test.*"/>
<fileset>
<batchtest>
<junit>
<ail if="tests.failed">
***********************************************************
**** One or more tests failed! Check the output ... ****
***********************************************************
<fail>
<target>
<-- 鎵撳寘鎴恓ar -->
<arget name="pack" depends="test" description="make .jar file">
<kdir dir="${dist.dir}" />
<ar destfile="${dist.dir}/hello.jar" basedir="${classes.dir}">
<xclude name="**/*Test.*" />
<xclude name="**/Test*.*" />
<jar>
<target>
<-- 杈撳嚭api鏂囨。 -->
<arget name="doc" depends="pack" description="create api doc">
<kdir dir="${doc.dir}" />
<avadoc destdir="${doc.dir}"
author="true"
version="true"
use="true"
windowtitle="Test API">
<ackageset dir="${src.dir}" defaultexcludes="yes">
<nclude name="example/**" />
<packageset>
<octitle>[CDATA[<1>ello, test<h1>]>doctitle>
<ottom>[CDATA[<>ll Rights Reserved.<i>]>bottom>
<ag name="todo" scope="all" description="To do:" />
<javadoc>
<target>
<project>
銆銆浠ヤ笂xml渚濇瀹氫箟浜?jiǎn)init錛堝垵濮嬪寲錛夛紝compile錛堢紪璇戯級(jí)錛宼est錛堟祴璇曪級(jí)錛宒oc錛堢敓鎴愭枃妗o級(jí)錛宲ack錛堟墦鍖咃級(jí)浠誨姟錛屽彲浠ヤ綔涓烘ā鏉褲?/P>
銆銆閫変腑Hello宸ョ▼錛岀劧鍚庨夋嫨鈥淧roject鈥濓紝鈥淧roperties鈥濓紝鈥淏uilders鈥濓紝鈥淣ew鈥︹濓紝閫夋嫨鈥淎nt Build鈥濓細(xì)
銆銆濉叆Name錛欰nt_Builder錛汢uildfile錛歜uild.xml錛汢ase Directory錛?{workspace_loc:/Hello}錛堟寜鈥淏rowse Workspace鈥濋夋嫨宸ョ▼鏍圭洰褰曪級(jí)錛岀敱浜庣敤鍒頒簡(jiǎn)junit.jar鍖咃紝鎼滅儲(chǔ)Eclipse鐩綍錛屾壘鍒癹unit.jar錛屾妸瀹冨鍒跺埌Hello/lib鐩綍涓嬶紝騫舵坊鍔犲埌Ant鐨凜lasspath涓細(xì)
銆銆鐒跺悗鍦˙uilder闈㈡澘涓挬涓夾nt_Build錛屽幓鎺塉ava Builder錛?/P>
銆銆鍐嶆緙栬瘧錛屽嵆鍙湪鎺у埗鍙扮湅鍒癆nt鐨勮緭鍑猴細(xì)
Buildfile: F:\eclipse-projects\Hello\build.xml
init:
compile:
[mkdir] Created dir: F:\eclipse-projects\Hello\classes
[javac] Compiling 2 source files to F:\eclipse-projects\Hello\classes
test:
[mkdir] Created dir: F:\eclipse-projects\Hello\report
[junit] Running example.HelloTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.02 sec
pack:
[mkdir] Created dir: F:\eclipse-projects\Hello\dist
[jar] Building jar: F:\eclipse-projects\Hello\dist\hello.jar
doc:
[mkdir] Created dir: F:\eclipse-projects\Hello\doc
[javadoc] Generating Javadoc
[javadoc] Javadoc execution
[javadoc] Loading source files for package example...
[javadoc] Constructing Javadoc information...
[javadoc] Standard Doclet version 1.4.2_04
[javadoc] Building tree for all the packages and classes...
[javadoc] Building index for all the packages and classes...
[javadoc] Building index for all classes...
[javadoc] Generating F:\eclipse-projects\Hello\doc\stylesheet.css...
[javadoc] Note: Custom tags that could override future standard tags: @todo. To avoid potential overrides, use at least one period character (.) in custom tag names.
[javadoc] Note: Custom tags that were not seen: @todo
BUILD SUCCESSFUL
Total time: 11 seconds
銆銆Ant渚濇鎵ц鍒濆鍖栵紝緙栬瘧錛屾祴璇曪紝鎵撳寘錛岀敓鎴怉PI鏂囨。涓緋誨垪浠誨姟錛屾瀬澶у湴鎻愰珮浜?jiǎn)寮鍙戞晥鐜囥傚皢鏉ュ紑鍙慗2EE欏圭洰鏃訛紝榪樺彲鍔犲叆閮ㄧ講絳変換鍔°傚茍涓旓紝鍗充嬌鑴辯浜?jiǎn)Eclipse鐜錛屽彧瑕佹紜畨瑁呬簡(jiǎn)Ant錛岄厤緗ソ鐜鍙橀噺ANT_HOME=<nt瑙e帇鐩綍>Path=鈥?%ANT_HOME%\bin錛屽湪鍛戒護(hù)琛屾彁紺虹涓嬪垏鎹㈠埌Hello鐩綍錛岀畝鍗曞湴閿叆ant鍗沖彲銆?/P>