Jenkins ant build.xml鏂囦欢璇﹁В(瀛︿範绗旇鍏�)

ANT build.xml鏂囦欢璇﹁В锛堜竴锛�

Ant鐨勬蹇�

鍙兘鏈変簺璇昏�呭苟涓嶈繛鎺ヤ粈涔堟槸Ant浠ュ強鍏ュ彲浣跨敤瀹冿紝浣嗗彧瑕佷娇鐢ㄩ�氳繃Linux绯荤粺寰楄鑰咃紝搴旇鐭ラ亾

make杩欎釜鍛戒护銆傚綋缂栬瘧Linux鍐呮牳鍙婁竴浜涜蒋浠剁殑婧愮▼搴忔椂锛岀粡甯歌鐢ㄨ繖涓懡浠ゃ�侻ake鍛戒护鍏跺疄灏�

鏄竴涓」鐩鐞嗗伐鍏凤紝鑰孉nt鎵�瀹炵幇鍔熻兘涓庢绫讳技銆傚儚make锛実numake鍜宯make杩欎簺缂栬瘧宸ュ叿閮芥湁

涓�瀹氱殑缂洪櫡锛屼絾鏄疉nt鍗村厠鏈嶄簡杩欎簺宸ュ叿鐨勭己闄枫�傛渶鍒滱nt寮�鍙戣�呭湪寮�鍙戣法骞冲彴鐨勫簲鐢ㄦ椂锛岀敤鏍蜂篃

鏄熀浜庤繖浜涚己闄峰Ant鍋氫簡鏇村ソ鐨勮璁°��

Ant 涓� makefile

Makefile鏈変竴浜涗笉瓒充箣澶勶紝姣斿寰堝浜洪兘浼氱鍒扮殑鐑︿汉鐨凾ab闂銆傛渶鍒濈殑Ant寮�鍙戣�呭娆″己璋冣��

鍙槸鎴戝湪Tab鍓嶉潰鍔犱簡涓�涓┖鏍硷紝鎵�浠ユ垜鐨勫懡浠ゅ氨涓嶈兘鎵ц鈥濄�傛湁涓�浜涘伐鍏峰湪涓�瀹氱▼搴︿笂瑙e喅浜�

杩欎釜闂锛屼絾杩樻槸鏈夊緢澶氬叾浠栫殑闂銆侫nt鍒欎笌涓�鑸熀浜庡懡浠ょ殑宸ュ叿鏈夋墍涓嶅悓锛屽畠鏄疛ava绫荤殑鎵�

灞曘�侫nt杩愯闇�瑕佺殑XML鏍煎紡鐨勬枃浠朵笉鏄疭hell鍛戒护鏂囦欢銆傚畠鏄敱涓�涓狿roject缁勬垚鐨勶紝鑰屼竴涓�

Project鍙堝彲鍒嗘垚鍙target锛宼arget鍐嶇粏鍒嗗張鍒嗘垚寰堝task锛屾瘡涓�涓猼ask閮芥槸閫氳繃涓�涓疄鐜扮壒

瀹氭帴鍙g殑java绫绘潵瀹屾垚鐨勩��

Ant鐨勪紭鐐�

Ant鏄疉pache杞欢鍩洪噾浼欽AKARTA鐩綍涓殑涓�涓瓙椤圭洰锛屽畠鏈変互涓嬬殑浼樼偣銆�

璺ㄥ钩鍙版�с�侫nt鏄瓨Java璇█缂栧啓鐨勶紝鎵�绀哄叿鏈夊緢濂界殑璺ㄥ钩鍙版�с��

鎿嶄綔绠�鍗曘�侫nt鏄敱涓�涓唴缃换鍔″拰鍙�変换鍔$粍鎴愮殑銆侫nt杩愯鏃堕渶瑕佷竴涓猉ML鏂囦欢(鏋勫缓鏂囦欢)銆�

Ant閫氳繃璋冪敤target鏍戯紝灏卞彲浠ユ墽琛屽悇绉峵ask銆傛瘡涓猼ask瀹炵幇浜嗙壒瀹氭帴鍙e璞°�傜敱浜嶢nt鏋勫缓鏂囦欢

鏃禭ML鏍煎紡鐨勬枃浠讹紝鎵�浠ュ拰瀹规槗缁存姢鍜屼功鍐欙紝鑰屼笖缁撴瀯寰堟竻鏅般��

Ant鍙互闆嗘垚鍒板紑鍙戠幆澧冧腑銆傜敱浜嶢nt鐨勮法骞冲彴鎬у拰鎿嶄綔绠�鍗曠殑鐗圭偣锛屽畠寰堝鏄撻泦鎴愬埌涓�浜涘紑鍙戠幆

澧冧腑鍘汇��

Ant 寮�鍙�

Ant鐨勬瀯寤烘枃浠�

褰撳紑濮嬩竴涓柊鐨勯」鐩椂锛岄鍏堝簲璇ョ紪鍐橝nt鏋勫缓鏂囦欢銆傛瀯寤烘枃浠跺畾涔変簡鏋勫缓杩囩▼锛屽苟琚洟闃熷紑鍙�

涓瘡涓汉浣跨敤銆侫nt鏋勫缓鏂囦欢榛樿鍛藉悕涓篵uild.xml锛屼篃鍙互鍙栧叾浠栫殑鍚嶅瓧銆傚彧涓嶈繃鍦ㄨ繍琛岀殑鏃跺��

鎶婅繖涓懡鍚嶅綋浣滃弬鏁颁紶缁橝nt銆傛瀯寤烘枃浠跺彲浠ユ斁鍦ㄤ换浣曠殑浣嶇疆銆備竴鑸仛娉曟槸鏀惧湪椤圭洰椤跺眰鐩綍涓�

锛岃繖鏍峰彲浠ヤ繚鎸侀」鐩殑绠�娲佸拰娓呮櫚銆備笅闈㈡槸涓�涓吀鍨嬬殑椤圭洰灞傛缁撴瀯銆�

(1) src瀛樻斁鏂囦欢銆�

(2) class瀛樻斁缂栬瘧鍚庣殑鏂囦欢銆�

(3) lib瀛樻斁绗笁鏂笿AR鍖呫��

(4) dist瀛樻斁鎵撳寘锛屽彂甯冧互鍚庣殑浠g爜銆�

Ant鏋勫缓鏂囦欢鏄疿ML鏂囦欢銆傛瘡涓瀯寤烘枃浠跺畾涔変竴涓敮涓�鐨勯」鐩�(Project鍏冪礌)銆傛瘡涓」鐩笅鍙互瀹�

涔夊緢澶氱洰鏍�(target鍏冪礌)锛岃繖浜涚洰鏍囦箣闂村彲浠ユ湁渚濊禆鍏崇郴銆傚綋鎵ц杩欑被鐩爣鏃讹紝闇�瑕佹墽琛屼粬浠墍

渚濊禆鐨勭洰鏍囥��

姣忎釜鐩爣涓彲浠ュ畾涔夊涓换鍔★紝鐩爣涓繕瀹氫箟浜嗘墍瑕佹墽琛岀殑浠诲姟搴忓垪銆侫nt鍦ㄦ瀯寤虹洰鏍囨椂蹇呴』璋�

鐢ㄦ墍瀹氫箟鐨勪换鍔°�備换鍔″畾涔変簡Ant瀹為檯鎵ц鐨勫懡浠ゃ�侫nt涓殑浠诲姟鍙互涓�3绫汇��

锛�1锛� 鏍稿績浠诲姟銆傛牳蹇冧换鍔℃槸Ant鑷甫鐨勪换鍔°��

锛�2锛� 鍙�変换鍔°�傚彲閫変换鍔″疄鏉ヨ嚜绗笁鏂圭殑浠诲姟锛屽洜姝ら渶瑕佷竴涓檮鍔犵殑JAR鏂囦欢銆�

锛�3锛� 鐢ㄦ埛鑷畾涔夌殑浠诲姟銆傜敤鎴疯嚜瀹氫箟鐨勪换鍔″疄鐢ㄦ埛鑷繁寮�鍙戠殑浠诲姟銆�

1.鏍囩

姣忎釜鏋勫缓鏂囦欢瀵瑰簲涓�涓」鐩�傛爣绛炬椂鏋勫缓鏂囦欢鐨勬牴鏍囩銆傚畠鍙互鏈夊涓唴鍦ㄥ睘鎬э紝

灏卞浠g爜涓墍绀猴紝鍏跺悇涓睘鎬х殑鍚箟鍒嗗埆濡備笅銆�

(1) default琛ㄧず榛樿鐨勮繍琛岀洰鏍囷紝杩欎釜灞炴�ф槸蹇呴』鐨勩��

(2) basedir琛ㄧず椤圭洰鐨勫熀鍑嗙洰褰曘��

(3) name琛ㄧず椤圭洰鍚嶃��

(4) description琛ㄧず椤圭洰鐨勬弿杩般��

姣忎釜鏋勫缓鏂囦欢閮藉搴斾簬涓�涓」鐩紝浣嗘槸澶у瀷椤圭洰缁忓父鍖呭惈澶ч噺鐨勫瓙椤圭洰锛屾瘡涓�涓瓙椤圭洰閮藉彲浠ユ湁

鑷繁鐨勬瀯寤烘枃浠躲��

2.鏍囩

涓�涓」鐩爣绛句笅鍙互鏈変竴涓垨澶氫釜target鏍囩銆備竴涓猼arget鏍囩鍙互渚濊禆鍏朵粬鐨則arget鏍囩銆備緥

濡傦紝鏈変竴涓猼arget鐢ㄤ簬缂栬瘧绋嬪簭锛屽彟涓�涓猼arget鐢ㄤ簬澹扮О鍙墽琛屾枃浠躲�傚湪鐢熸垚鍙墽琛屾枃浠朵箣鍓嶅繀

椤诲厛缂栬瘧璇ユ枃浠讹紝鍥犵瓥鍙墽琛屾枃浠剁殑target渚濊禆浜庣紪璇戠▼搴忕殑target銆俆arget鐨勬墍鏈夊睘鎬у涓嬨��

(1).name琛ㄧず鏍囨槑锛岃繖涓睘鎬ф槸蹇呴』鐨勩��

(2).depends琛ㄧず渚濊禆鐨勭洰鏍囥��

(3)if琛ㄧず浠呭綋灞炴�ц缃椂鎵嶆墽琛屻��

(4)unless琛ㄧず褰撳睘鎬ф病鏈夎缃椂鎵嶆墽琛屻��

(5)description琛ㄧず椤圭洰鐨勬弿杩般��

Ant鐨刣epends灞炴�ф寚瀹氫簡target鐨勬墽琛岄『搴忋�侫nt浼氫緷鐓epends灞炴�т腑target鍑虹幇椤哄簭渚濇鎵ц

姣忎釜target銆傚湪鎵ц涔嬪墠锛岄鍏堥渶瑕佹墽琛屽畠鎵�渚濊禆鐨則arget銆傜▼搴忎腑鐨勫悕涓簉un鐨則arget鐨�

depends灞炴�ompile锛岃�屽悕涓篶ompile鐨則arget鐨刣epends灞炴�ф槸prepare锛屾墍浠ヨ繖鍑犱釜target鎵�

琛岀殑椤哄簭鏄痯repare->compile->run銆�

涓�涓猼arget鍙兘琚墽琛屼竴娆★紝鍗充娇鏈夊涓猼arget渚濊禆浜庡畠銆傚鏋滄病鏈塱f鎴杣nless灞炴�э紝target鎬�

浼氳鎵ц銆�

3.鏍囩

璇ユ爣绛剧敤浜庡垱寤轰竴涓洰褰曪紝瀹冩湁涓�涓睘鎬ir鐢ㄦ潵鎸囧畾鎵�鍒涘缓鐨勭洰褰曞悕锛屽叾浠g爜濡備笅锛�

閫氳繃浠ヤ笂浠g爜灏卞垱寤轰簡涓�涓洰褰曪紝杩欎釜鐩綍宸茬粡琚墠闈㈢殑property鏍囩鎵�鎸囧畾銆�

4鏍囩

璇ユ爣绛剧敤鏉ョ敓鎴愪竴涓狫AR鏂囦欢锛屽叾灞炴�у涓嬨��

(1) destfile琛ㄧずJAR鏂囦欢鍚嶃��

(2) basedir琛ㄧず琚綊妗g殑鏂囦欢鍚嶃��

(3) includes琛ㄧず鍒綊妗g殑鏂囦欢妯″紡銆�

(4) exchudes琛ㄧず琚帓闄ょ殑鏂囦欢妯″紡銆�

5锛�

璇ユ爣绛剧敤浜庣紪璇戜竴涓垨涓�缁刯ava鏂囦欢锛屽叾灞炴�у涓嬨��

(1).srcdir琛ㄧず婧愮▼搴忕殑鐩綍銆�

(2).destdir琛ㄧずclass鏂囦欢鐨勮緭鍑虹洰褰曘��

(3).include琛ㄧず琚紪璇戠殑鏂囦欢鐨勬ā寮忋��

(4).excludes琛ㄧず琚帓闄ょ殑鏂囦欢鐨勬ā寮忋��

(5).classpath琛ㄧず鎵�浣跨敤鐨勭被璺緞銆�

(6).debug琛ㄧず鍖呭惈鐨勮皟璇曚俊鎭��

(7).optimize琛ㄧず鏄惁浣跨敤浼樺寲銆�

(8).verbose 琛ㄧず鎻愪緵璇︾粏鐨勮緭鍑轰俊鎭��

(9).fileonerror琛ㄧず褰撶鍒伴敊璇氨鑷姩鍋滄銆�

6锛庢爣绛�

璇ユ爣绛剧敤鏉ユ墽琛岀紪璇戠敓鎴愮殑.class鏂囦欢锛屽叾灞炴�у涓嬨��

(1).classname 琛ㄧず灏嗘墽琛岀殑绫诲悕銆�

(2).jar琛ㄧず鍖呭惈璇ョ被鐨凧AR鏂囦欢鍚嶃��

(3).classpath鎵�琛ㄧず鐢ㄥ埌鐨勭被璺緞銆�

(4).fork琛ㄧず鍦ㄤ竴涓柊鐨勮櫄鎷熸満涓繍琛岃绫汇��

(5).failonerror琛ㄧず褰撳嚭鐜伴敊璇椂鑷姩鍋滄銆�

(6).output 琛ㄧず杈撳嚭鏂囦欢銆�

(7).append琛ㄧず杩藉姞鎴栬�呰鐩栭粯璁ゆ枃浠躲��

7.鏍囩

璇ユ爣绛剧敤浜庡垹闄や竴涓枃浠舵垨涓�缁勬枃浠讹紝鍘诲睘鎬у涓嬨��

(1)/file琛ㄧず瑕佸垹闄ょ殑鏂囦欢銆�

(2).dir琛ㄧず瑕佸垹闄ょ殑鐩綍銆�

(3).includeEmptyDirs 琛ㄧず鎸囧畾鏄惁瑕佸垹闄ょ┖鐩綍锛岄粯璁ゅ�兼槸鍒犻櫎銆�

(4).failonerror 琛ㄧず鎸囧畾褰撶鍒伴敊璇槸鍚﹀仠姝紝榛樿鍊兼槸鑷姩鍋滄銆�

(5).verbose琛ㄧず鎸囧畾鏄惁鍒楀嚭鎵�鍒犻櫎鐨勬枃浠讹紝榛樿鍊间负涓嶅垪鍑恒��

8.鏍囩

璇ユ爣绛剧敤浜庢枃浠舵垨鏂囦欢闆嗙殑鎷疯礉锛屽叾灞炴�у涓嬨��

(1).file 琛ㄧず婧愭枃浠躲��

(2).tofile 琛ㄧず鐩爣鏂囦欢銆�

(3).todir 琛ㄧず鐩爣鐩綍銆�

(4).overwrite 琛ㄧず鎸囧畾鏄惁瑕嗙洊鐩爣鏂囦欢锛岄粯璁ゅ�兼槸涓嶈鐩栥��

(5).includeEmptyDirs 琛ㄧず鍒跺畾鏄惁鎷疯礉绌虹洰褰曪紝榛樿鍊间负鎷疯礉銆�

(6).failonerror 琛ㄧず鎸囧畾濡傜洰鏍囨病鏈夊彂鐜版槸鍚﹁嚜鍔ㄥ仠姝紝榛樿鍊兼槸鍋滄銆�

(7).verbose 琛ㄧず鍒跺畾鏄惁鏄剧ず璇︾粏淇℃伅锛岄粯璁ゅ�间笉鏄剧ず銆�

Ant鐨勬暟鎹被鍨�

鍦ㄦ瀯寤烘枃浠朵腑涓轰簡鏍囪瘑鏂囦欢鎴栨枃浠剁粍锛岀粡甯搁渶瑕佷娇鐢ㄦ暟鎹被鍨嬨�傛暟鎹被鍨嬪寘鍚湪

org.apache.tool.ant.types鍖呬腑銆備笅闈㈤暅绠�鍗曚粙缁嶆瀯寤烘枃浠朵腑涓�浜涘父鐢ㄧ殑鏁版嵁绫诲瀷銆�

1. argument 绫诲瀷

鐢盇nt鏋勫缓鏂囦欢璋冪敤鐨勭▼搴忥紝鍙互閫氳繃鍏冪礌鍚戝叾浼犻�掑懡浠よ鍙傛暟锛屽apply,exec鍜宩ava浠�

鍔″潎鍙帴鍙楀祵濂楀厓绱狅紝鍙互涓哄悇鑷殑杩囩▼璋冪敤鎸囧畾鍙傛暟銆備互涓嬫槸鐨勬墍鏈夊睘鎬с��

(1).values 鏄竴涓懡浠ゅ弬鏁般�傚鏋滃弬鏁扮鏈夌┖鏍硷紝浣嗗張鎯冲皢瀹冧綔涓哄崟鐙竴涓�硷紝鍒欎娇鐢ㄦ灞炴��

銆�

(2).file琛ㄧず涓�涓弬鏁扮殑鏂囦欢鍚嶃�傚湪鏋勫缓鏂囦欢涓紝姝ゆ枃浠跺悕鐩稿浜庡綋鍓嶇殑宸ヤ綔鐩綍銆�

(3).line琛ㄧず鐢ㄧ┖鏍煎垎闅旂殑澶氫釜鍙傛暟鍒楄〃銆�

(4).path琛ㄧず璺緞銆�

2.ervironment 绫诲瀷

鐢盇nt鏋勫缓鏂囦欢璋冪敤鐨勫閮ㄥ懡浠ゆ垨绋嬪簭锛屽厓绱犲埗瀹氫簡鍝簺鐜鍙橀噺瑕佷紶閫掔粰姝e湪鎵ц鐨勭郴

缁熷懡浠わ紝鍏冪礌鍙互鎺ュ彈浠ヤ笅灞炴�с��

(1).file琛ㄧず鐜鍙橀噺鍊煎緱鏂囦欢鍚嶃�傛鏂囦欢鍚嶈琚浆鎹綅涓�涓粷瀵硅矾寰勩��

(2).path琛ㄧず鐜鍙橀噺鐨勮矾寰勩�侫nt浼氬皢瀹冭浆鎹负涓�涓湰鍦扮害瀹氥��

(3).value 琛ㄧず鐜鍙橀噺鐨勪竴涓洿鎺ュ彉閲忋��

(4).key 琛ㄧず鐜鍙橀噺鍚嶃��

娉ㄦ剰聽聽 file path 鎴� value鍙兘鍙栦竴涓��

3.filelist绫诲瀷

Filelist 鏄竴涓敮鎸佸懡鍚嶇殑鏂囦欢鍒楄〃鐨勬暟鎹被鍨嬶紝鍖呭惈鍦ㄤ竴涓猣ilelist绫诲瀷涓殑鏂囦欢涓嶄竴瀹氭槸

瀛樺湪鐨勬枃浠躲�備互涓嬫槸鍏舵墍鏈夌殑灞炴�с��

(1).dir鏄敤浜庤绠楃粷瀵规枃浠跺悕鐨勭洰褰曘��

(2).files 鏄敤閫楀彿鍒嗛殧鐨勬枃浠跺悕鍒楄〃銆�

(3).refid 鏄鏌愬瀹氫箟鐨勪竴涓殑寮曠敤銆�

娉ㄦ剰聽聽 dir 鍜� files 閮芥槸蹇呰鐨勶紝闄ら潪鎸囧畾浜唕efid(杩欑鎯呭喌涓嬶紝dir鍜宖iles閮戒笉鍏佽浣跨敤)銆�

4.fileset绫诲瀷

Fileset 鏁版嵁绫诲瀷瀹氫箟浜嗕竴缁勬枃浠讹紝骞堕�氬父琛ㄧず涓哄厓绱犮�備笉杩囷紝璁稿ant浠诲姟鏋勫缓鎴愪簡

闅愬紡鐨刦ileset,杩欒鏄庝粬浠敮鎸佹墍鏈夌殑fileset灞炴�у拰宓屽鍏冪礌銆備互涓嬩负fileset 鐨勫睘鎬у垪琛ㄣ��

(1).dir琛ㄧずfileset 鐨勫熀鐩綍銆�

(2).casesensitive鐨勫�煎鏋滀负false锛岄偅涔堝尮閰嶆枃浠跺悕鏃讹紝fileset涓嶆槸鍖哄垎澶у皬鍐欑殑锛屽叾榛樿

鍊间负true.

(3).defaultexcludes 鐢ㄦ潵纭畾鏄惁浣跨敤榛樿鐨勬帓闄ゆā寮忥紝榛樿涓簍rue銆�

(4).excludes 鏄敤閫楀彿鍒嗛殧鐨勯渶瑕佹淳鍑虹殑鏂囦欢妯″紡鍒楄〃銆�

(5).excludesfile 琛ㄧず姣忚鍖呭惈涓�涓帓闄ゆā寮忕殑鏂囦欢鐨勬枃浠跺悕銆�

(6).includes 鏄敤閫楀彿鍒嗛殧鐨勶紝闇�瑕佸寘鍚殑鏂囦欢妯″紡鍒楄〃銆�

(7).includesfile 琛ㄧず姣忚鍖呮嫭涓�涓寘鍚ā寮忕殑鏂囦欢鍚嶃��

5.patternset 绫诲瀷

Fileset 鏄鏂囦欢鐨勫垎缁勶紝鑰宲atternset鏄妯″紡鐨勫垎缁勶紝浠栦滑鏄揣瀵嗙浉鍏崇殑姒傚康銆�

鏀寔4涓睘鎬э細includes excludex includexfile 鍜� excludesfile,涓巉ileset鐩�

鍚屻�侾atternset 杩樺厑璁镐互涓嬪祵濂楀厓绱狅細include,exclude,includefile 鍜� excludesfile.

6.filterset 绫诲瀷

Filterset瀹氫箟浜嗕竴缁勮繃婊ゅ櫒锛岃繖浜涜繃婊ゅ櫒灏嗗湪鏂囦欢绉诲姩鎴栧鍒舵椂瀹屾垚鏂囦欢鐨勬枃鏈浛鎹€��

涓昏灞炴�у涓嬶細

(1).begintoken 琛ㄧず宓屽杩囨护鍣ㄦ墍鎼滅储鐨勮鍙凤紝杩欐槸鏍囪瘑鍏跺紑濮嬬殑瀛楃涓层��

(2).endtoken琛ㄧず宓屽杩囨护鍣ㄦ墍鎼滅储鐨勮鍙疯繖鏄爣璇嗗叾缁撴潫鐨勫瓧绗︿覆銆�

(3).id鏄繃婊ゅ櫒鐨勫敮涓�鏍囧織绗︺��

(4).refid鏄鏋勫缓鏂囦欢涓煇澶勫畾涔変竴涓繃婊ゅ櫒鐨勫紩鐢ㄣ��

7.Path绫诲瀷

Path鍏冪礌鐢ㄦ潵琛ㄧず涓�涓被璺緞锛屼笉杩囧畠杩樺彲浠ョ敤浜庤〃绀哄叾浠栫殑璺緞銆傚湪鐢ㄤ綔鎻栦釜灞炴�ф椂锛岃矾缁忎腑

鐨勫悇椤圭敤鍒嗗彿鎴栧啋鍙烽殧寮�銆傚湪鏋勫缓鐨勬椂鍊欙紝姝ゅ垎闅旂灏嗕唬鏇垮綋鍓嶅钩鍙颁腑鎵�鏈夌殑璺緞鍒嗛殧绗︼紝鍏舵嫢

鏈夌殑灞炴�у涓嬨��

(1).location 琛ㄧず涓�涓枃浠舵垨鐩綍銆侫nt鍦ㄥ唴閮ㄥ皢姝ゆ墿灞曚负涓�涓粷瀵硅矾寰勩��

(2).refid 鏄褰撳墠鏋勫缓鏂囦欢涓煇澶勫畾涔夌殑涓�涓猵ath鐨勫紩鐢ㄣ��

(3).path琛ㄧず涓�涓枃浠舵垨璺緞鍚嶅垪琛ㄣ��

8.mapper绫诲瀷

Mapper绫诲瀷瀹氫箟浜嗕竴缁勮緭鍏ユ枃浠跺拰涓�缁勮緭鍑烘枃浠堕棿鐨勫叧绯伙紝鍏跺睘鎬у涓嬨��

(1).classname 琛ㄧず瀹炵幇mapper绫荤殑绫诲悕銆傚綋鍐呯疆mapper涓嶆弧瓒宠姹傛椂锛岀敤浜庡垱寤哄畾鍒秏apper.

(2).classpath琛ㄧず鏌ユ壘涓�涓畾鍒秏apper鏃舵墍鐢ㄧ殑绫诲瀷璺緞銆�

(3).classpathref鏄鏌愬瀹氫箟鐨勪竴涓被璺緞鐨勫紩鐢ㄣ��

(4).from灞炴�х殑鍚箟鍙栧喅浜庢墍鐢ㄧ殑mapper.

(5).to灞炴�х殑鍚箟鍙栧喅浜庢墍鐢ㄧ殑mapper.

(6).type灞炴�х殑鍙栧�间负identity锛宖latten glob merge聽聽 regexp聽聽 鍏朵腑涔嬩竴锛屽畠瀹氫箟浜嗚鏄敤鐨�

鍐呯疆mapper鐨勭被鍨嬨��

Ant 鐨勮繍琛�

瀹夎濂紸nt骞朵笖閰嶇疆濂借矾寰勪箣鍚庯紝鍦ㄥ懡浠よ涓垏鎹㈠埌鏋勫缓鏂囦欢鐨勭洰褰曪紝杈撳叆Ant鍛戒护灏卞彲浠ヨ繍琛�

Ant.鑻ユ病鏈夋寚瀹氫换浣曞弬鏁帮紝Ant浼氬湪褰撳墠鐩綍涓嬫煡璇uild.xml鏂囦欢銆傚鏋滄壘鍒颁簡灏辩敤璇ユ枃浠朵綔涓�

鏋勫缓鏂囦欢銆傚鏋滀娇鐢ㄤ簡 鈥揻ind 閫夐」锛孉nt 灏变細鍦ㄤ笂绾х洰褰曚腑鎵炬瀯寤烘枃浠讹紝鐩磋嚦鍒拌揪鏂囦欢绯荤粺寰�

璺熺洰褰曘�傚鏋滄瀯寤烘枃浠剁殑鍚嶅瓧涓嶆槸build.xml 锛屽垯Ant杩愯鐨勬椂鍊欏氨鍙互浣跨敤 鈥揵uildfile file

,杩欓噷file 鎸囧畾浜嗚浣跨敤鐨勬瀯寤烘枃浠剁殑鍚嶇О锛岀ず渚嬪涓嬶細

Ant

濡備笅璇存槑浜嗚〃绀哄綋鍓嶇洰褰曠殑鏋勫缓鏂囦欢涓篵uild.xml 杩愯 ant 鎵ц榛樿鐨勭洰鏍囥��

Ant 鈥揵uildfile聽聽 test.xml

浣跨敤褰撳墠鐩綍涓嬬殑test.xml 鏂囦欢杩愯Ant ,鎵ц榛樿鐨勭洰鏍�

ant鐨刡uild.xml鏂囦欢璇﹁В锛堜簩锛�

浠uild_for_ejb_templet.xml涓虹ず渚嬶紝璁茶ВAnt涓父鐢ㄧ殑鍏冪礌鍜屼换鍔°��

绾﹀畾锛� "鈥�"琛ㄧず杩欓噷鏈夊緢澶氫唬鐮侊紝鏈垪鍑�

build_for_ejb_templet.xml浠诲姟鐨勫垎涓轰互涓嬪嚑澶ч儴鍒�

i. 寮�濮�

ii. 鍒濆鍖�

iii. 瀹氫箟classpath

iv. 涓虹紪璇戜綔鍑嗗

v. 缂栬瘧EJB閮ㄥ垎

vi. 缂栬瘧WEB閮ㄥ垎

vii. 缂栬瘧J2EE Application

viii. 閮ㄧ讲Application

ix. 鍒涘缓缁勪欢鐨凙PI

x. 纭畾build鐨勭洰鏍�

build_for_ejb_templet.xml鐨勮瑙�

寮�濮嬄�


璁茶В锛歟ncoding="UTF-8"琛ㄧずXML鏂囦欢閲囩敤UTF-8缂栫爜鏍煎紡锛屽鏋滆浣跨敤GBK缂栫爜锛岄渶瀹氫箟涓篹ncodeing="GBK"銆�


Build file for 'componentName'

Creation date : $Date: yyyy-m-d $

Updated date : $Date: yyyy-m-d $

Author:聽聽 developerName

Copyright 2002 CompanyName, Inc. All rights reserved.

-->

璁茶В锛氭閮ㄥ垎涓烘枃浠跺唴瀹圭殑绠�浠嬶紝鍖呮嫭鏂囦欢鍚嶇О銆佸垱寤烘棩鏈熴�佹渶鍚庝慨鏀规棩鏈熴�佸垱寤烘枃浠剁殑浣滆�呫�佺増鏉冦��

componentName 琛ㄧず 鏂囦欢鍚嶇О

yyyy-m-dd 琛ㄧず 鍒涘缓鏃ユ湡銆佹渶鍚庝慨鏀规棩鏈熺殑鏍煎紡锛屽2002-5-1

developerName 琛ㄧず 鍒涘缓鏂囦欢鐨勪綔鑰�

CompanyName 琛ㄧず 鍏徃鍚嶇О鎴朥RL

鈥�

璁茶В锛氭閮ㄥ垎瀹氫箟浜嗕竴涓悕绉颁负componentName鐨勯」鐩厓绱狅紝缂虹渷鐨勪换鍔′负"core"浠诲姟锛屾牴鐩綍涓哄綋鍓嶇洰褰曘�俢omponentName琛ㄧず缁勪欢鐨勫悕绉帮紝杩欓噷鎸嘐JB鐨勫悕绉般��

鍒濆鍖柭�

鈥�

璁茶В锛氭閮ㄥ垎鐢ㄤ簬鍒濆鍖栨墍鏈夌殑鍙橀噺

璁茶В锛氬鍏ラ」鐩牴鐩綍涓媌uild.properties涓殑鍏ㄥ眬鍙橀噺锛屽紑鍙戜汉鍛樹篃鍙互鍦ㄦ鏂囦欢涓噸鏂板畾涔夊叏灞�鍙橀噺銆�

鈥�

鈥�

璁茶В锛氬畾涔夊拰Jboss Application Server鏈夊叧鐨勫彉閲忥紝鍖呮嫭lib鐩綍銆乧lient鐩綍銆�

deploy鐩綍鍜孞2EE Application閮ㄧ讲瑕佺敤鍒扮殑涓�浜涘彉閲忋��

璁茶В锛氬畾涔夌粍浠剁殑鍚嶇О

璁茶В锛氬畾涔夋簮浠g爜鐩綍璺緞

璁茶В锛氬畾涔夎祫婧愮洰褰曡矾寰�

璁茶В锛氬畾涔夊簱鐩綍璺緞

璁茶В锛氬畾涔塨uild鐩綍璺緞

璁茶В锛氬畾涔夋簮浠g爜鐨勪富鐩綍璺緞

璁茶В锛氬畾涔夊瓨鏀綞JB鐨勬簮浠g爜鐩綍璺緞

璁茶В锛氬畾涔夊瓨鏀綣avaBean鐨勬簮浠g爜鐩綍璺緞

璁茶В锛氬畾涔夊瓨鏀維ervlet鐨勬簮浠g爜鐩綍璺緞

璁茶В锛氬畾涔夊瓨鏀網EB閮ㄥ垎鏂囦欢锛堝寘鎷琂SP绋嬪簭銆丠TML鏂囦欢銆佸浘鐗囥�丆SS鏂囦欢銆丣S鑴氭湰绛夛級鐨勭洰褰曡矾寰�

璁茶В锛氬畾涔夊瓨鏀剧粍浠禔PI鐨勫紑鍙戞枃浠剁洰褰曡矾寰�

璁茶В锛氬畾涔夊瓨鏀綞JB鐨勭紪璇戜唬鐮佺洰褰曡矾寰�

璁茶В锛氬畾涔夊瓨鏀綣avaBean鐨勭紪璇戜唬鐮佺洰褰曡矾寰�

璁茶В锛氬畾涔塛EB鐩綍鐨勭被鐩綍璺緞

璁茶В锛氬畾涔塛EB鐩綍鐨勫簱鐩綍鍚嶇О

璁茶В锛氬畾涔夊帇缂╂枃妗g殑鍚嶇О

璁茶В锛氬畾涔夐」鐩殑缁勪欢鐩綍璺緞


璁茶В锛氳繖娈典负娉ㄩ噴锛岃鏄庝互涓嬫槸瀹氫箟褰撳墠缁勪欢鐨勫彉閲�

璁茶В锛氬畾涔夊綋鍓嶇粍浠剁殑鍚嶇О

璁茶В锛氬畾涔夊綋鍓嶇粍浠剁殑鐩綍璺緞

value="${ProjectName.componentName.home}/lib/ejb"/>

璁茶В锛氬畾涔夊綋鍓嶇粍浠剁殑EJB缂栬瘧鐩綍璺緞

value="${ProjectName.componentName.home}/build/componentName-ejb.jar"/>

璁茶В锛氬畾涔夊綋鍓嶇粍浠跺唴鐨凟JB鍖呯殑璺緞

value="${ProjectName.componentName.home}/build/componentName-ejb-client.jar"/>

璁茶В锛氬畾涔夊綋鍓嶇粍浠跺唴鐨凟JB瀹㈡埛绔寘鐨勮矾寰�


璁茶В锛氳繖娈典负娉ㄩ噴锛岃鏄庝互涓嬫槸瀹氫箟寮曞叆鍏跺畠缁勪欢鐨勫彉閲�

value="referencesComponentName"/>

璁茶В锛氬畾涔夋寚瀹氱粍浠剁殑鍚嶇О

value="${ProjectName.components.home}/referencesComponentName"/>

璁茶В锛氬畾涔夋寚瀹氱粍浠剁殑鐩綍璺緞

value="${ProjectName.referencesComponentName.home}/lib/ejb"/>

璁茶В锛氬畾涔夋寚瀹氱粍浠剁殑EJB缂栬瘧鐩綍璺緞

value="${ProjectName.referencesComponentName.home}

/build/referencesComponentName-ejb.jar"/>

璁茶В锛氬畾涔夋寚瀹氱粍浠跺唴鐨凟JB鍖呯殑璺緞

value="${ProjectName.referencesComponentName.home}

/build/referencesComponentName-ejb-client.jar"/>

璁茶В锛氬畾涔夋寚瀹氱粍浠跺唴鐨凟JB瀹㈡埛绔寘鐨勮矾寰�

value="${jboss.client}/jboss-j2ee.jar:${jboss.client}

/jnp-client.jar:${jboss.client}/jnp-client.jar:${jboss.client}

/jbossmq-client.jar:${jboss.client}/jbosssx-client.jar:${jboss.client}

/concurrent.jar:${jboss.client}/jaas.jar:${jboss.lib}

/jboss-jmx.jar:${jboss.home}/server/${jboss.configuration}

/lib/jbosssx.jar:${jboss.home}/server/${jboss.configuration}

/lib/mail.jar:${servlet-lib.path}:${ejb-classes.dest}:

${web-classes.dest}:${ProjectName.componentName.classbindir}:

${ProjectName.componentName.ejbjar.client}:

${ProjectName.referencesComponentName.classbindir}:

${ProjectName.referencesComponentName.ejbjar.client}" />

璁茶В锛氬畾涔塩lasspath锛岀紪璇慴ean鏃惰鐢ㄥ埌銆傝繖鏄畾涔塩lasspath鐨勪竴绉嶆柟娉曪紝涓嬮潰杩樻湁鍙︿竴绉嶆柟娉曘��

瀹氫箟classpath聽




location="${jboss.home}/server/${jboss.configuration}/lib/jbosssx.jar" />

location="${jboss.home}/server/${jboss.configuration}/lib/mail.jar" />

璁茶В锛氭娈靛畾涔夊簲鐢ㄦ湇鍔″櫒涓寘鏂囦欢锛屽鏀寔ejb鐨刯boss-j2ee.jar銆佹敮鎸佸鎴风绋嬪簭鐨刯np-client.jar銆乯bossmq-client.jar銆乯bosssx-client.jar銆佹敮鎸丣avaMail鐨刴ail.jar绛夈��

location="${ProjectName.referencesComponentName.classbindir}"/>

璁茶В锛氭娈靛畾涔夐」鐩腑瑕佺敤鍒扮殑鍖呮枃浠躲��

璁茶В锛氭娈靛畾涔夊湪缂栬瘧servlet鏃剁殑classpath锛�${ servlet-lib.path }鏄郴缁熸寚瀹氱殑Servlet寮曟搸鍖呫��

涓虹紪璇戜綔鍑嗗宸ヤ綔




璁茶В锛氭竻闄uild銆乴ib鐩綍涓嬬殑鎵�鏈夋枃浠跺拰鐩綍銆�




璁茶В锛氬垱寤篵uild涓鐢ㄥ埌鐨勬墍鏈夌洰褰曪紝鏍规嵁闇�瑕佸彲浠ュ姞鍏ヨ嚜瀹氫箟鐨勭洰褰曞锛�

缂栬瘧EJB閮ㄥ垎




destdir="${ejb-classes.dest}"

includes="com/**"

classpathref="base.path" />

璁茶В锛氭灏忔鐢ㄦ潵瀹屾垚缂栬瘧ejb鍜屽叾瀹僪elp classes銆傛牴鎹渶瑕佸彲浠ュ姞鍏ヤ竴涓潪甯告湁鐢ㄧ殑鍏冪礌锛�

encoding="${javac.encoding}"

tofile="${lib.dir}/ejb/META-INF/ejb-jar.xml" />

tofile="${lib.dir}/ejb/META-INF/jaws.xml" />

tofile="${lib.dir}/ejb/META-INF/jboss.xml" />

tofile="${lib.dir}/ejb/META-INF/jbosscmp-jdbc.xml" />

璁茶В锛氭灏忔鐢ㄦ潵鎷疯礉EJB閮ㄧ讲鏂囦欢锛屽湪JAS涓璄JB閮ㄧ讲鏂囦欢鏈塲aws.xml銆乯boss.xml銆乯bosscmp-jdbc.xml銆�

basedir="${lib.dir}/ejb" />

璁茶В锛氭灏忔鐢ㄦ潵鎶奵lass鍜岄儴缃叉枃浠跺帇缂╂垚鍖呮枃浠讹紝杩欎釜鍖呮枃浠跺氨鏄竴涓狤JB缁勪欢銆�

file="${ProjectName.referencesComponentName.home}/build/

${ProjectName.referencesComponentName.name}-ejb-client.jar"

tofile="${build.dir}/${ProjectName.referencesComponentName.name}

-ejb-client.jar" />

basedir="${lib.dir}/ejb"

excludes="com/ProjectName/componentName/ejb/ComponentNameEJB.class" />

璁茶В锛氭灏忔鐢ㄦ潵鎶奵lass鍜岄儴缃叉枃浠跺帇缂╂垚鍖呮枃浠讹紝浠ユ敮鎸佸鎴风杩愯銆�

缂栬瘧WEB閮ㄥ垎




destdir="${lib.dir}/web/WEB-INF/classes"

includes="com/**"

classpath="${build.classpath}" />

璁茶В锛氭灏忔鐢ㄦ潵瀹屾垚缂栬瘧servlet銆�

tofile="${lib.dir}/web/WEB-INF/jboss-web.xml" />

tofile="${lib.dir}/web/WEB-INF/web.xml" />

璁茶В锛氭灏忔鐢ㄦ潵鎷疯礉WEB閮ㄧ讲鏂囦欢锛屽湪JAS涓璚EB閮ㄧ讲鏂囦欢鏈塲boss-web.xml銆�

file="${build.dir}/${ProjectName.referencesComponentName.name}-ejb-client.jar"

tofile="${lib.dir}/web/WEB-INF/lib/${ProjectName.referencesComponentName.name}

-ejb-client.jar" />

basedir="${lib.dir}/web" />

璁茶В锛氭灏忔鐢ㄦ潵鎶婃墍鏈夌殑JSP绋嬪簭銆丠tml銆丆ss銆佸浘鐗囧拰閮ㄧ讲鏂囦欢绛夊帇缂╂垚WAR鏂囦欢銆�

缂栬瘧J2EE Application




tofile="${lib.dir}/j2ee/META-INF/application.xml" />

璁茶В锛氭灏忔鐢ㄦ潵鎷疯礉Application鐨勯儴缃叉枃浠躲��

tofile="${lib.dir}/j2ee/${name}-ejb.jar" />

tofile="${lib.dir}/j2ee/${name}-web.war" />

basedir="${lib.dir}/j2ee" />

璁茶В锛氭灏忔鐢ㄦ潵鎶奅JB缁勪欢銆佹敮鎸佸鎴风杩愯鐨勫寘鍜岄儴缃叉枃浠跺帇缂╂垚EAR鏂囦欢锛屽畠灏辨槸涓�涓狫2EE Application銆傝繖閲岃璇存槑锛屽湪杩涜build鏃讹紝鏍规嵁闇�瑕佸彲浠ヤ笉鐢熸垚EAR鏂囦欢銆�

閮ㄧ讲Application




璁茶В锛氭灏忔鐢ㄦ潵閮ㄧ讲Application锛屽湪JAS3.0涓�${jboss.deploy}鏄疛AS鐨勭儹閮ㄧ讲鐩綍銆�

鍒涘缓缁勪欢鐨凙PI




destdir="${javadoc.dir}"

classpath="${build.classpath}"

encoding="${javadoc.encoding}"

author="${javadoc.author}"

version="${javadoc.version}"

use="${javadoc.usage}"

windowtitle="${project.name} ${name} Component API"

doctitle="${project.name} ${name} Component"

bottom="Copyright ${sign.copyright} ${project.date}

${company.signature}. All Rights Reserved.">

璁茶В锛氭灏忔鐢ㄦ潵鍒涘缓缁勪欢鐨凙PI銆傝繖閲屽己鐑堣姹傜被璁捐浜哄憳鍜岀紪鐮佷汉鍛樻寜鐓avadoc瀹氫箟鐨勬爣绛惧婧愪唬鐮佽繘琛屾敞閲娿��

纭畾build鐨勭洰鏍�

+---------------------------------------+

+聽聽聽聽 Building ${name} Component聽聽聽聽聽聽聽聽 +

+---------------------------------------+

+---------------------------------------+

+聽聽聽聽 Finished ${name} Component聽聽聽聽聽聽聽聽 +

+---------------------------------------+

ejbclientjar,war" />

ejbclientjar,war,ear,deploy-server" />

璁茶В锛氭灏忔鐢ㄦ潵纭畾build鐨勭洰鏍囥�傜己鐪佺洰褰曚负core锛屾墍浠ュ湪build涓嶅姞鍙傛暟鏃讹紝绯荤粺灏嗗彧鐢熸垚jar鏂囦欢鍜寃ar鏂囦欢銆傚鏋� build鏃跺姞涓婂弬鏁帮紝绯荤粺灏嗘牴鎹渶瑕佹潵鐢熸垚鏂囦欢锛屼緥濡傦細鍦ㄥ懡浠よ杈撳叆ant deploy锛岀郴缁熷皢鐢熸垚jar鏂囦欢銆亀ar鏂囦欢銆乪ar鏂囦欢锛屽悓鏃跺皢ear鏂囦欢杩涜閮ㄧ讲銆�

ant build.xml 璇﹁В(涓�)

鍦‥clipse涓娇鐢ˋnt Ant鏄疛ava骞冲彴涓嬮潪甯告鐨勬壒澶勭悊鍛戒护鎵ц绋嬪簭锛岃兘闈炲父鏂逛究鍦拌嚜鍔ㄥ畬鎴愮紪璇戯紝娴嬭瘯锛屾墦鍖咃紝閮ㄧ讲绛夌瓑涓�绯诲垪浠诲姟锛屽ぇ澶ф彁楂樺紑鍙戞晥鐜囥�傚鏋滀綘鐜板湪杩樻病鏈夊紑濮嬩娇鐢ˋnt锛岄偅灏辫璧跺揩寮�濮嬪涔犱娇鐢紝浣胯嚜宸辩殑寮�鍙戞按骞充笂涓�涓柊鍙伴樁銆偮�

Eclipse涓凡缁忛泦鎴愪簡Ant锛屾垜浠彲浠ョ洿鎺ュ湪Eclipse涓繍琛孉nt銆偮�

浠ュ墠闈㈠缓绔嬬殑Hello宸ョ▼涓轰緥锛屽垱寤轰互涓嬬洰褰曠粨鏋勶細聽

鏂板缓涓�涓猙uild.xml锛屾斁鍦ㄥ伐绋嬫牴鐩綍涓嬨�俠uild.xml瀹氫箟浜咥nt瑕佹墽琛岀殑鎵瑰鐞嗗懡浠ゃ�傝櫧鐒禔nt涔熷彲浠ヤ娇鐢ㄥ叾瀹冩枃浠跺悕锛屼絾鏄伒寰爣鍑嗚兘鏇翠娇寮�鍙戞洿瑙勮寖锛屽悓鏃舵槗浜庝笌鍒汉浜ゆ祦銆偮�

閫氬父锛宻rc瀛樻斁Java婧愭枃浠讹紝classes瀛樻斁缂栬瘧鍚庣殑class鏂囦欢锛宭ib瀛樻斁缂栬瘧鍜岃繍琛岀敤鍒扮殑鎵�鏈塲ar鏂囦欢锛寃eb瀛樻斁JSP绛墂eb鏂囦欢锛宒ist瀛樻斁鎵撳寘鍚庣殑jar鏂囦欢锛宒oc瀛樻斁API鏂囨。銆偮�

鐒跺悗鍦ㄦ牴鐩綍涓嬪垱寤篵uild.xml鏂囦欢锛岃緭鍏ヤ互涓嬪唴瀹癸細聽

Xml浠g爜 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽 聽haltonfailure="false" 聽

聽 聽 聽 聽 聽 聽 聽 聽 聽failureproperty="tests.failed" 聽

聽 聽 聽 聽 聽 聽 聽 聽 聽showoutput="true"> 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽*********************************************************** 聽聽

聽 聽 聽 聽 聽**** 聽 One or more tests failed! 聽 Check the output ... 聽 **** 聽聽

聽 聽 聽 聽 聽*********************************************************** 聽聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽 聽

聽 聽 聽

聽 聽 聽 聽 聽 聽 聽author="true" 聽

聽 聽 聽 聽 聽 聽 聽version="true" 聽

聽 聽 聽 聽 聽 聽 聽use="true" 聽

聽 聽 聽 聽 聽 聽 聽windowtitle="Test API"> 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽Hello, test]]> 聽

聽 聽 聽 聽 聽 聽 聽All Rights Reserved.]]> 聽

聽 聽 聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽

聽 聽 聽 聽

浠ヤ笂xml渚濇瀹氫箟浜唅nit锛堝垵濮嬪寲锛夛紝compile锛堢紪璇戯級锛宼est锛堟祴璇曪級锛宒oc锛堢敓鎴愭枃妗o級锛宲ack锛堟墦鍖咃級浠诲姟锛屽彲浠ヤ綔涓烘ā鏉裤�偮�

閫変腑Hello宸ョ▼锛岀劧鍚庨�夋嫨鈥淧roject鈥濓紝鈥淧roperties鈥濓紝鈥淏uilders鈥濓紝鈥淣ew鈥︹�濓紝閫夋嫨鈥淎nt Build鈥濓細聽

濉叆Name锛欰nt_Builder锛汢uildfile锛歜uild.xml锛汢aseDirectory锛�${workspace_loc: /Hello}锛堟寜鈥淏rowseWorkspace鈥濋�夋嫨宸ョ▼鏍圭洰褰曪級锛岀敱浜庣敤鍒颁簡junit.jar鍖咃紝鎼滅储Eclipse鐩綍锛屾壘鍒� junit.jar锛屾妸瀹冨鍒跺埌Hello/lib鐩綍涓嬶紝骞舵坊鍔犲埌Ant鐨凜lasspath涓細聽

鐒跺悗鍦˙uilder闈㈡澘涓挬涓夾nt_Build锛屽幓鎺塉ava Builder锛毬�

鍐嶆缂栬瘧锛屽嵆鍙湪鎺у埗鍙扮湅鍒癆nt鐨勮緭鍑猴細聽

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 standardtags: 聽 @todo. To avoid potential overrides, use at least one periodcharacter (.) in custom tag names.聽

聽 聽 聽 [javadoc] Note: Custom tags that were not seen: 聽 @todo聽

BUILD SUCCESSFUL聽

Total time: 11 seconds聽

Ant渚濇鎵ц鍒濆鍖栵紝缂栬瘧锛屾祴璇曪紝鎵撳寘锛岀敓鎴怉PI鏂囨。涓�绯诲垪浠诲姟锛屾瀬澶у湴鎻愰珮浜嗗紑鍙戞晥鐜囥�傚皢鏉ュ紑鍙慗2EE椤圭洰鏃讹紝杩樺彲鍔犲叆閮ㄧ讲绛変换鍔°�傚苟涓旓紝鍗充娇鑴辩浜咵clipse鐜锛屽彧瑕佹纭畨瑁呬簡Ant锛岄厤缃ソ鐜鍙橀噺ANT_HOME=

Ant 鐨勬渶瀹屾暣build.xml涔嬫爣绛撅細

Ant 寮�鍙懧�

Ant鐨勬瀯寤烘枃浠堵�

聽聽 褰撳紑濮嬩竴涓柊鐨勯」鐩椂锛岄鍏堝簲璇ョ紪鍐橝nt鏋勫缓鏂囦欢銆傛瀯寤烘枃浠跺畾涔変簡鏋勫缓杩囩▼锛屽苟琚洟闃熷紑鍙戜腑姣忎釜浜轰娇鐢ㄣ�侫nt鏋勫缓鏂囦欢榛樿鍛藉悕涓� build.xml锛屼篃鍙互鍙栧叾浠栫殑鍚嶅瓧銆傚彧涓嶈繃鍦ㄨ繍琛岀殑鏃跺�欐妸杩欎釜鍛藉悕褰撲綔鍙傛暟浼犵粰Ant銆傛瀯寤烘枃浠跺彲浠ユ斁鍦ㄤ换浣曠殑浣嶇疆銆備竴鑸仛娉曟槸鏀惧湪椤圭洰椤跺眰鐩綍涓紝杩欐牱鍙互淇濇寔椤圭洰鐨勭畝娲佸拰娓呮櫚銆備笅闈㈡槸涓�涓吀鍨嬬殑椤圭洰灞傛缁撴瀯銆偮�

(1) src瀛樻斁鏂囦欢銆偮�

(2) class瀛樻斁缂栬瘧鍚庣殑鏂囦欢銆偮�

(3) lib瀛樻斁绗笁鏂笿AR鍖呫�偮�

(4) dist瀛樻斁鎵撳寘锛屽彂甯冧互鍚庣殑浠g爜銆偮�

Ant鏋勫缓鏂囦欢鏄疿ML鏂囦欢銆傛瘡涓瀯寤烘枃浠跺畾涔変竴涓敮涓�鐨勯」鐩�(Project鍏冪礌)銆傛瘡涓」鐩笅鍙互瀹氫箟寰堝鐩爣(target鍏冪礌)锛岃繖浜涚洰鏍囦箣闂村彲浠ユ湁渚濊禆鍏崇郴銆傚綋鎵ц杩欑被鐩爣鏃讹紝闇�瑕佹墽琛屼粬浠墍渚濊禆鐨勭洰鏍囥�傛瘡涓洰鏍囦腑鍙互瀹氫箟澶氫釜浠诲姟锛岀洰鏍囦腑杩樺畾涔変簡鎵�瑕佹墽琛岀殑浠诲姟搴忓垪銆侫nt鍦ㄦ瀯寤虹洰鏍囨椂蹇呴』璋冪敤鎵�瀹氫箟鐨勪换鍔°�備换鍔″畾涔変簡Ant瀹為檯鎵ц鐨勫懡浠ゃ�侫nt涓殑浠诲姟鍙互涓�3绫汇�偮�

锛�1锛� 鏍稿績浠诲姟銆傛牳蹇冧换鍔℃槸Ant鑷甫鐨勪换鍔°�偮�

锛�2锛� 鍙�変换鍔°�傚彲閫変换鍔″疄鏉ヨ嚜绗笁鏂圭殑浠诲姟锛屽洜姝ら渶瑕佷竴涓檮鍔犵殑JAR鏂囦欢銆偮�

锛�3锛� 鐢ㄦ埛鑷畾涔夌殑浠诲姟銆傜敤鎴疯嚜瀹氫箟鐨勪换鍔″疄鐢ㄦ埛鑷繁寮�鍙戠殑浠诲姟銆偮�

1.鏍囩聽

聽 姣忎釜鏋勫缓鏂囦欢瀵瑰簲涓�涓」鐩�傛爣绛炬椂鏋勫缓鏂囦欢鐨勬牴鏍囩銆傚畠鍙互鏈夊涓唴鍦ㄥ睘鎬э紝灏卞浠g爜涓墍绀猴紝鍏跺悇涓睘鎬х殑鍚箟鍒嗗埆濡備笅銆偮�

(1) default琛ㄧず榛樿鐨勮繍琛岀洰鏍囷紝杩欎釜灞炴�ф槸蹇呴』鐨勩�偮�

(2) basedir琛ㄧず椤圭洰鐨勫熀鍑嗙洰褰曘�偮�

(3) name琛ㄧず椤圭洰鍚嶃�偮�

(4) description琛ㄧず椤圭洰鐨勬弿杩般�偮�

姣忎釜鏋勫缓鏂囦欢閮藉搴斾簬涓�涓」鐩紝浣嗘槸澶у瀷椤圭洰缁忓父鍖呭惈澶ч噺鐨勫瓙椤圭洰锛屾瘡涓�涓瓙椤圭洰閮藉彲浠ユ湁鑷繁鐨勬瀯寤烘枃浠躲�偮�

2.鏍囩聽

涓�涓」鐩爣绛鹃┐姊㈡潅骞告榫岃毃鍠�?/span>target鏍囩銆備竴涓猼arget鏍囩鍙互渚濊禆鍏朵粬鐨則arget鏍囩銆備緥濡傦紝鏈変竴涓猼arget鐢ㄤ簬缂栬瘧绋嬪簭锛屽彟涓�涓猼arget鐢ㄤ簬澹扮О鍙墽琛屾枃浠躲�傚湪鐢熸垚鍙墽琛屾枃浠朵箣鍓嶅繀椤诲厛缂栬瘧璇ユ枃浠讹紝鍥犵瓥鍙墽琛屾枃浠剁殑target渚濊禆浜庣紪璇戠▼搴忕殑 target銆俆arget鐨勬墍鏈夊睘鎬у涓嬨�偮�

(1).name琛ㄧず鏍囨槑锛岃繖涓睘鎬ф槸蹇呴』鐨勩�偮�

(2).depends琛ㄧず渚濊禆鐨勭洰鏍囥�偮�

(3)if琛ㄧず浠呭綋灞炴�ц缃椂鎵嶆墽琛屻�偮�

(4)unless琛ㄧず褰撳睘鎬ф病鏈夎缃椂鎵嶆墽琛屻�偮�

(5)description琛ㄧず椤圭洰鐨勬弿杩般�偮�

Ant鐨刣epends灞炴�ф寚瀹氫簡target鐨勬墽琛岄『搴忋�侫nt浼氫緷鐓epends灞炴�т腑target鍑虹幇椤哄簭渚濇鎵ц姣忎釜target銆傚湪鎵ц涔嬪墠锛岄鍏堥渶瑕佹墽琛屽畠鎵�渚濊禆鐨則arget銆傜▼搴忎腑鐨勫悕涓簉un鐨則arget鐨刣epends灞炴�ompile锛岃�屽悕涓篶ompile鐨則arget鐨� depends灞炴�ф槸prepare锛屾墍浠ヨ繖鍑犱釜target鎵ц鐨勯『搴忔槸prepare->compile->run銆備竴涓猼arget鍙兘琚墽琛屼竴娆★紝鍗充娇鏈夊涓猼arget渚濊禆浜庡畠銆傚鏋滄病鏈塱f鎴杣nless灞炴�э紝target鎬讳細琚墽琛屻�偮�

3.鏍囩聽

璇ユ爣绛剧敤浜庡垱寤轰竴涓洰褰曪紝瀹冩湁涓�涓睘鎬ir鐢ㄦ潵鎸囧畾鎵�鍒涘缓鐨勭洰褰曞悕锛屽叾浠g爜濡備笅锛毬�

閫氳繃浠ヤ笂浠g爜灏卞垱寤轰簡涓�涓洰褰曪紝杩欎釜鐩綍宸茬粡琚墠闈㈢殑property鏍囩鎵�鎸囧畾銆偮�

4鏍囩聽

璇ユ爣绛剧敤鏉ョ敓鎴愪竴涓狫AR鏂囦欢锛屽叾灞炴�у涓嬨�偮�

(1) destfile琛ㄧずJAR鏂囦欢鍚嶃�偮�

(2) basedir琛ㄧず琚綊妗g殑鏂囦欢鍚嶃�偮�

(3) includes琛ㄧず鍒綊妗g殑鏂囦欢妯″紡銆偮�

(4) exchudes琛ㄧず琚帓闄ょ殑鏂囦欢妯″紡銆偮�

5锛幝�

璇ユ爣绛剧敤浜庣紪璇戜竴涓垨涓�缁刯ava鏂囦欢锛屽叾灞炴�у涓嬨�偮�

(1).srcdir琛ㄧず婧愮▼搴忕殑鐩綍銆偮�

(2).destdir琛ㄧずclass鏂囦欢鐨勮緭鍑虹洰褰曘�偮�

(3).include琛ㄧず琚紪璇戠殑鏂囦欢鐨勬ā寮忋�偮�

(4).excludes琛ㄧず琚帓闄ょ殑鏂囦欢鐨勬ā寮忋�偮�

(5).classpath琛ㄧず鎵�浣跨敤鐨勭被璺緞銆偮�

(6).debug琛ㄧず鍖呭惈鐨勮皟璇曚俊鎭�偮�

(7).optimize琛ㄧず鏄惁浣跨敤浼樺寲銆偮�

(8).verbose 琛ㄧず鎻愪緵璇︾粏鐨勮緭鍑轰俊鎭�偮�

(9).fileonerror琛ㄧず褰撶鍒伴敊璇氨鑷姩鍋滄銆偮�

6锛庢爣绛韭�

璇ユ爣绛剧敤鏉ユ墽琛岀紪璇戠敓鎴愮殑.class鏂囦欢锛屽叾灞炴�у涓嬨�偮�

(1).classname 琛ㄧず灏嗘墽琛岀殑绫诲悕銆偮�

(2).jar琛ㄧず鍖呭惈璇ョ被鐨凧AR鏂囦欢鍚嶃�偮�

(3).classpath鎵�琛ㄧず鐢ㄥ埌鐨勭被璺緞銆偮�

(4).fork琛ㄧず鍦ㄤ竴涓柊鐨勮櫄鎷熸満涓繍琛岃绫汇�偮�

(5).failonerror琛ㄧず褰撳嚭鐜伴敊璇椂鑷姩鍋滄銆偮�

(6).output 琛ㄧず杈撳嚭鏂囦欢銆偮�

(7).append琛ㄧず杩藉姞鎴栬�呰鐩栭粯璁ゆ枃浠躲�偮�

7.鏍囩聽

璇ユ爣绛剧敤浜庡垹闄や竴涓枃浠舵垨涓�缁勬枃浠讹紝鍘诲睘鎬у涓嬨�偮�

(1)/file琛ㄧず瑕佸垹闄ょ殑鏂囦欢銆偮�

(2).dir琛ㄧず瑕佸垹闄ょ殑鐩綍銆偮�

(3).includeEmptyDirs 琛ㄧず鎸囧畾鏄惁瑕佸垹闄ょ┖鐩綍锛岄粯璁ゅ�兼槸鍒犻櫎銆偮�

(4).failonerror 琛ㄧず鎸囧畾褰撶鍒伴敊璇槸鍚﹀仠姝紝榛樿鍊兼槸鑷姩鍋滄銆偮�

(5).verbose琛ㄧず鎸囧畾鏄惁鍒楀嚭鎵�鍒犻櫎鐨勬枃浠讹紝榛樿鍊间负涓嶅垪鍑恒�偮�

8.鏍囩聽

璇ユ爣绛剧敤浜庢枃浠舵垨鏂囦欢闆嗙殑鎷疯礉锛屽叾灞炴�у涓嬨�偮�

(1).file 琛ㄧず婧愭枃浠躲�偮�

(2).tofile 琛ㄧず鐩爣鏂囦欢銆偮�

(3).todir 琛ㄧず鐩爣鐩綍銆偮�

(4).overwrite 琛ㄧず鎸囧畾鏄惁瑕嗙洊鐩爣鏂囦欢锛岄粯璁ゅ�兼槸涓嶈鐩栥�偮�

(5).includeEmptyDirs 琛ㄧず鍒跺畾鏄惁鎷疯礉绌虹洰褰曪紝榛樿鍊间负鎷疯礉銆偮�

(6).failonerror 琛ㄧず鎸囧畾濡傜洰鏍囨病鏈夊彂鐜版槸鍚﹁嚜鍔ㄥ仠姝紝榛樿鍊兼槸鍋滄銆偮�

(7).verbose 琛ㄧず鍒跺畾鏄惁鏄剧ず璇︾粏淇℃伅锛岄粯璁ゅ�间笉鏄剧ず銆偮�

ant鏁欑▼璇﹁В--javac锛宩ava锛宩ar锛寃ar锛宒elete锛宑opy锛宮kdir锛�

Ant 鏄竴涓� Apache 鍩洪噾浼氫笅鐨勮法骞冲彴鐨勬瀯浠跺伐鍏凤紝瀹冨彲浠ュ疄鐜伴」鐩殑鑷姩鏋勫缓鍜岄儴缃茬瓑鍔熻兘銆傚湪鏈枃涓紝涓昏璁╄鑰呯啛鎮夋�庢牱灏� Ant 搴旂敤鍒� Java 椤圭洰涓紝璁╁畠绠�鍖栨瀯寤哄拰閮ㄧ讲鎿嶄綔銆�

涓�锛幝犅犅犅犅犅犅犅犅犅犅犅犅� 瀹夎涓庨厤缃�

涓嬭浇鍦板潃锛� http://ant.apache.org/ 锛屽湪鏈枃涓笅杞界殑鏄� 1.7.0 鐗堟湰銆傝В鍘嬪埌鏌愪釜鐩綍锛堜緥濡� E:"apache-ant-1.7.0 锛夛紝鍗冲彲浣跨敤銆�

娣诲姞绯荤粺鐜鍙橀噺锛� ANT_HOME 锛岃鍙橀噺鎸囧悜 Ant 瑙e帇鍚庣殑鏍圭洰褰曪紝鍦ㄦ涓� E:"apache-ant-1.7.0 銆�

瀹夎涓庨厤缃畬姣曞悗锛岃鑰呭彲浠ユ祴璇曚竴涓� Ant 鏄惁鍙敤锛岄鍏堣繘鍏� Ant 鐨� bin 鐩綍锛岃繍琛屽懡浠� ant 鈥搗ersion 锛岃嫢瀹夎鍜岄厤缃垚鍔燂紝鍒欎細鏄剧ず Ant 鐗堟湰淇℃伅锛屽涓嬪浘鎵�绀猴細

鐢变笂鍙互鐪嬪嚭锛岃鑰呰繍琛� Ant 鐨勫懡浠ゆ椂锛岄渶瑕佽繘鍏ュ埌 Ant 鐨� bin 鐩綍锛屽浣曟墠鑳借绯荤粺鑷姩鎵惧埌 Ant 鍛紵杩欐椂闇�瑕佽鑰呭湪绯荤粺鐜鍙橀噺 path 涓坊鍔� Ant 鐨� bin 鐩綍銆傝缃畬鎴愬悗锛屾垜浠氨鍙互鍦ㄤ换浣曠洰褰曪紙渚嬪 C:"Documents and Settings"AmigoXie 鐩綍锛夎緭鍏� Ant 鐨勫懡浠わ紝鏉ヨ幏寰楀懡浠ょ殑杩愯缁撴灉銆�

浜岋紟聽聽聽聽聽聽聽聽聽聽聽聽聽 Ant 鐨勫叧閿厓绱�

Ant 鐨勬瀯浠舵枃浠舵槸鍩轰簬 XML 缂栧啓鐨勶紝榛樿鍚嶇О涓� build.xml 銆備负浜嗘洿娓呮鐨勪簡瑙� Ant 锛屽湪杩欓噷缂栧啓涓�涓畝鍗曠殑 Ant 绋嬪簭锛岀敤鏉ュ睍鐜� Ant 鐨勫姛鑳斤紝璁╄鑰呭 Ant 鏈変竴涓垵姝ョ殑浜嗚В銆傞鍏堝湪 E 鐩樹笅寤虹珛涓�涓� build.xml 鏂囦欢锛屽唴瀹瑰涓嬶細


< project聽 name ="helloWorld">

< target聽 name ="sayHelloWorld">

< echo聽 message ="Hello,Amigo"/>



璇昏�呭彲浠ヨ繘鍏� E 鐩橈紝鐒跺悗杩愯 ant sayHelloWorld 锛屽彲浠ョ湅鍒板涓嬬殑杩愯缁撴灉锛�

鍏朵腑 sayHelloWorld 涓洪渶瑕佹墽琛岀殑浠诲姟鐨勫悕绉般�傚鏋滄枃浠跺悕涓嶄负 build.xml 锛岃�屼负 hello.xml 鏃讹紝璇昏�呰繍琛屽悓鏍风殑鍛戒护鏃讹紝鍛戒护绐楀彛浼氬嚭鐜板涓嬮敊璇細

Buildfile: build.xml does not exist!

Build failed

鐢变笂闈㈢殑鍛戒护鐨勯敊璇彁绀哄彲浠ョ湅鍑猴紝 ant 鍛戒护榛樿瀵绘壘 build.xml 鏂囦欢銆傝嫢鏂囦欢鍚嶄负 hello.xml 鏃讹紝璇昏�呰繕闇�瑕佸鍛戒护鍋氬皯璁告敼鍙橈紝鏀逛负锛� ant 鈥揻 hello.xml sayHelloWorld 銆� ant 鈥揵uildfile hello.xml sayHelloWorld 鎴� ant 鈥揻ile hello.xml sayHelloWorld 銆�

鎺ヤ笅鏉ュ紑濮嬪悜璇昏�呰瑙f湰鑺傜殑閲嶇偣锛� Ant 鐨勫叧閿厓绱� project 銆� target 銆� property 鍜� task 銆�

1.聽聽聽聽聽聽聽 project 鍏冪礌

project 鍏冪礌鏄� Ant 鏋勪欢鏂囦欢鐨勬牴鍏冪礌锛� Ant 鏋勪欢鏂囦欢鑷冲皯搴旇鍖呭惈涓�涓� project 鍏冪礌锛屽惁鍒欎細鍙戠敓閿欒銆傚湪姣忎釜 project 鍏冪礌涓嬶紝鍙寘鍚涓� target 鍏冪礌銆傛帴涓嬫潵鍚戣鑰呭睍绀轰竴涓� project 鍏冪礌鐨勫悇灞炴�с��

1 锛� name 灞炴��

鐢ㄤ簬鎸囧畾 project 鍏冪礌鐨勫悕绉般��

2 锛� default 灞炴��

鐢ㄤ簬鎸囧畾 project 榛樿鎵ц鏃舵墍鎵ц鐨� target 鐨勫悕绉般��

3 锛� basedir 灞炴��

鐢ㄤ簬鎸囧畾鍩鸿矾寰勭殑浣嶇疆銆傝灞炴�ф病鏈夋寚瀹氭椂锛屼娇鐢� Ant 鐨勬瀯浠舵枃浠剁殑闄勭洰褰曚綔涓哄熀鍑嗙洰褰曘��

涓嬮潰缁欒鑰呬竴涓畝鍗曠殑渚嬪瓙鏉ュ睍绀� project 鐨勫悇鍏冪礌鐨勪娇鐢ㄣ�備慨鏀� E:"build.xml 鏂囦欢锛屼慨鏀瑰悗鐨勫唴瀹瑰涓嬶細


< project聽 name ="projectStudy"聽 default ="sayBaseDir"聽 basedir ="E:" apache-ant-1.7.0" >

< target聽 name ="sayBaseDir">

< echo聽 message ="The base dir is: ${basedir}"/>



浠庝笂闈㈢殑鍐呭鎴戜滑鍙互鐪嬪嚭锛屽湪杩欓噷瀹氫箟浜� default 灞炴�х殑鍊间负 sayBaseDir 锛屽嵆褰撹繍琛� ant 鍛戒护鏃讹紝鑻ユ湭鎸囨槑鎵ц鐨� target 鏃讹紝榛樿鎵ц鐨� target 鐨� sayBaseDir 锛屽悓鏃惰繕瀹氫箟浜� basedir 灞炴�х殑鍊间负 E:"apache-ant-1.7.0 锛岃繘鍏� E 鐩樺悗杩愯 ant 鍛戒护锛屽彲鐪嬪埌杩愯鐨勭粨鏋滐紝濡備笅鍥炬墍绀猴細

鍥犱负璁惧畾浜� basedir 鐨勫�硷紝鎵�浠� basedir 灞炴�х殑鍊煎彉鎴愪簡璇昏�呰缃殑鍊笺�傝鑰呭彲浠ヨ嚜琛屽皢 project 鍏冪礌鐨� basedir 灞炴�у幓鎺夊悗杩愯 ant 鐪嬬湅杩愯缁撴灉锛屾鏃� basedir 鐨勫�煎彉鎴愪簡 E:" 锛屽嵆涓� Ant 鏋勪欢鏂囦欢鐨勭埗鐩綍銆�

鏈夌殑鏃跺�欙紝璇昏�呭彲鑳芥湁杩欑闇�姹傦紝鍗虫兂寰楀埌鏌愪釜 project 涓嬫墍鏈夌殑 target 鐨勫悕绉帮紝璇昏�呭彲浠ラ�氳繃鍦� ant 鍛戒护閲屽姞涓� -proecthelp 鏉ヨ揪鍒拌鐩殑銆備緥濡傞拡瀵逛笂杩扮殑渚嬪瓙鎴戜滑杩愯 ant 鈥損rojecthelp 锛岃緭鍑虹粨鏋滃涓嬶細

Buildfile: build.xml

Main targets:

Other targets:

sayBaseDir

Default target: sayBaseDir

2.聽聽聽聽聽聽聽 target 鍏冪礌

瀹冧负 Ant 鐨勫熀鏈墽琛屽崟鍏冿紝瀹冨彲浠ュ寘鍚竴涓垨澶氫釜鍏蜂綋鐨勪换鍔°�傚涓� target 鍙互瀛樺湪鐩镐簰渚濊禆鍏崇郴銆傚畠鏈夊涓嬪睘鎬э細

1 锛� name 灞炴��

鎸囧畾 target 鍏冪礌鐨勫悕绉帮紝杩欎釜灞炴�у湪涓�涓� project 鍏冪礌涓槸鍞竴鐨勩�傛垜浠彲浠ラ�氳繃鎸囧畾 target 鍏冪礌鐨勫悕绉版潵鎸囧畾鏌愪釜 target 銆�

2 锛� depends 灞炴��

鐢ㄤ簬鎻忚堪 target 涔嬮棿鐨勪緷璧栧叧绯伙紝鑻ヤ笌澶氫釜 target 瀛樺湪渚濊禆鍏崇郴鏃讹紝闇�瑕佷互鈥� , 鈥濋棿闅斻�� Ant 浼氫緷鐓� depends 灞炴�т腑 target 鍑虹幇鐨勯『搴忎緷娆℃墽琛屾瘡涓� target 銆傝渚濊禆鐨� target 浼氬厛鎵ц銆�

3 锛� if 灞炴��

鐢ㄤ簬楠岃瘉鎸囧畾鐨勫睘鎬ф槸鍚﹀瓨鍦紝鑻ヤ笉瀛樺湪锛屾墍鍦� target 灏嗕笉浼氳鎵ц銆�

4 锛� unless 灞炴��

璇ュ睘鎬х殑鍔熻兘涓� if 灞炴�х殑鍔熻兘姝eソ鐩稿弽锛屽畠涔熺敤浜庨獙璇佹寚瀹氱殑灞炴�ф槸鍚﹀瓨鍦紝鑻ヤ笉瀛樺湪锛屾墍鍦� target 灏嗕細琚墽琛屻��

5 锛� description 灞炴��

璇ュ睘鎬ф槸鍏充簬 target 鍔熻兘鐨勭畝鐭弿杩板拰璇存槑銆�

涓嬮潰甯﹂璇昏�呮潵鐪嬩竴涓悇灞炴�х患鍚堜娇鐢ㄧ殑渚嬪瓙銆備慨鏀� E:"build.xml 鏂囦欢锛屼慨鏀瑰悗鐨勫唴瀹瑰涓嬶細


< project聽 name ="targetStudy">

< target聽 name ="targetA"聽 if ="ant.java.version">

< echo聽 message ="Java Version: ${ant.java.version}"/>


< target聽 name ="targetB"聽 depends ="targetA"聽 unless ="amigo">

< description >

a depend example!


< echo聽 message ="The base dir is: ${basedir}"/>



杩涘叆 E 鐩樺悗杩愯 ant targetB 锛屽彲鐪嬪埌濡備笅鍥炬墍绀虹殑杩愯缁撴灉锛�

璇昏�呭垎鏋愮粨鏋滃悗鍙互鐪嬪埌锛屾垜浠繍琛岀殑鏄悕涓� targetB 鐨� target 锛屽洜璇� target 渚濊禆浜� targetA 锛屾墍浠� targetA 灏嗛鍏堣鎵ц锛屽悓鏃跺洜涓虹郴缁熷畨瑁呬簡 java 鐜锛屾墍浠� ant.java.version 灞炴�у瓨鍦紝鎵ц浜� targetA 杩欎釜 target 锛岃緭鍑轰俊鎭細 [echo] Java Version: 1.5 锛� targetA 鎵ц瀹屾瘯鍚庯紝鎺ョ潃鎵ц targetB 锛屽洜涓� amigo 涓嶅瓨鍦紝鑰� unless 灞炴�ф槸鍦ㄤ笉瀛樺湪鏃惰繘鍏ユ墍鍦ㄧ殑 target 鐨勶紝鐢辨鍙煡 targetB 寰椾互鎵ц锛岃緭鍑轰俊鎭細 The base dir is: E:" 銆�

3.聽聽聽聽聽聽聽 property 鍏冪礌

璇ュ厓绱犲彲鐪嬩綔鍙傞噺鎴栬�呭弬鏁扮殑瀹氫箟锛� project 鐨勫睘鎬у彲浠ラ�氳繃 property 鍏冪礌鏉ヨ瀹氾紝涔熷彲鍦� Ant 涔嬪璁惧畾銆傝嫢瑕佸湪澶栭儴寮曞叆鏌愭枃浠讹紝渚嬪 build.properties 鏂囦欢锛屽彲浠ラ�氳繃濡備笅鍐呭灏嗗叾寮曞叆锛�

property 鍏冪礌鍙敤浣� task 鐨勫睘鎬у�笺�傚湪 task 涓槸閫氳繃灏嗗睘鎬у悕鏀惧湪鈥� ${ 鈥濆拰鈥� } 鈥濅箣闂达紝骞舵斁鍦� task 灞炴�у�肩殑浣嶇疆鏉ュ疄鐜扮殑銆�

Ant 鎻愪緵浜嗕竴浜涘唴缃殑灞炴�э紝瀹冭兘寰楀埌鐨勭郴缁熷睘鎬х殑鍒楄〃涓� Java 鏂囨。涓� System.getPropertis() 鏂规硶寰楀埌鐨勫睘鎬т竴鑷达紝杩欎簺绯荤粺灞炴�у彲鍙傝�� sun 缃戠珯鐨勮鏄庛��

鍚屾椂锛� Ant 杩樻彁渚涗簡涓�浜涘畠鑷繁鐨勫唴缃睘鎬э紝濡備笅锛�

basedir 锛� project 鍩虹洰褰曠殑缁濆璺緞锛岃灞炴�у湪璁茶В project 鍏冪礌鏃舵湁璇︾粏璇存槑锛屼笉鍐嶈禈杩帮紱

ant.file 锛� buildfile 鐨勭粷瀵硅矾寰勶紝濡備笂闈㈢殑鍚勪緥瀛愪腑锛� ant.file 鐨勫�间负 E:"build.xml 锛�

ant.version 锛� Ant 鐨勭増鏈紝鍦ㄦ湰鏂囦腑锛屽�间负 1.7.0 锛�

ant.project.name 锛氬綋鍓嶆寚瀹氱殑 project 鐨勫悕瀛楋紝鍗冲墠鏂囪鍒扮殑 project 鐨� name 灞炴�х殑鍊硷紱

ant.java.version 锛� Ant 妫�娴嬪埌鐨� JDK 鐨勭増鏈紝鍦ㄤ笂渚嬭繍琛岀粨鏋滀腑鍙湅鍒颁负 1.5 銆�

涓嬮潰璁╄鑰呮潵鐪嬩竴涓� property 鍏冪礌浣跨敤鐨勭畝鍗曚緥瀛愩�備慨鏀� E:"build.xml 鏂囦欢锛屽唴瀹瑰涓嬶細


< project聽 name ="propertyStudy"聽 default ="example">

< property聽 name ="name"聽 value ="amigo"/>

< property聽 name ="age"聽 value ="25"/>

< target聽 name ="example">

< echo聽 message ="name: ${name}, age: ${age}"/>



璇ヤ緥鐨勮繍琛岀粨鏋滃涓嬪浘鎵�绀猴細

鐢辨璇昏�呭彲浠ョ湅鍑猴紝閫氳繃濡備笅涓や釜璇彞锛�

鎴戜滑璁剧疆浜嗗悕涓� name 鍜� age 鐨勪袱涓睘鎬э紝杩欎袱涓睘鎬ц缃悗锛岃鑰呭湪涓嬫枃涓彲浠ラ�氳繃 ${name} 鍜� ${age} 鍒嗗埆鍙栧緱杩欎袱涓睘鎬х殑鍊笺��

涓夛紟聽聽聽聽聽聽聽聽聽聽聽聽聽 Ant 鐨勫父鐢ㄤ换鍔�

鍦� Ant 宸ュ叿涓瘡涓�涓换鍔″皝瑁呬簡鍏蜂綋瑕佹墽琛岀殑鍔熻兘锛屾槸 Ant 宸ュ叿鐨勫熀鏈墽琛屽崟浣嶃�傚湪鏈皬鑺備腑锛屼富瑕佸紩瀵艰鑰呮潵鐪嬩笅 Ant 鐨勫父鐢ㄤ换鍔″強鍏朵娇鐢ㄤ妇渚嬨��

1.聽聽聽聽聽聽聽 copy 浠诲姟

璇ヤ换鍔′富瑕佺敤鏉ュ鏂囦欢鍜岀洰褰曠殑澶嶅埗鍔熻兘銆備妇渚嬪涓嬶細

Eg1. 澶嶅埗鍗曚釜鏂囦欢锛�

Eg2. 瀵规枃浠剁洰褰曡繘琛屽鍒讹細

Eg3. 灏嗘枃浠跺鍒跺埌鍙﹀鐨勭洰褰曪細

2.聽聽聽聽聽聽聽 delete 浠诲姟

瀵规枃浠舵垨鐩綍杩涜鍒犻櫎锛屼妇渚嬪涓嬶細

Eg1. 鍒犻櫎鏌愪釜鏂囦欢锛�

Eg2. 鍒犻櫎鏌愪釜鐩綍锛�

Eg3. 鍒犻櫎鎵�鏈夌殑澶囦唤鐩綍鎴栫┖鐩綍锛�

3.聽聽聽聽聽聽聽 mkdir 浠诲姟

鍒涘缓鐩綍銆� eg 锛�

4.聽聽聽聽聽聽聽 move 浠诲姟

绉诲姩鏂囦欢鎴栫洰褰曪紝涓句緥濡備笅锛�

Eg1. 绉诲姩鍗曚釜鏂囦欢锛�

Eg2. 绉诲姩鍗曚釜鏂囦欢鍒板彟涓�涓洰褰曪細

Eg3. 绉诲姩鏌愪釜鐩綍鍒板彟涓�涓洰褰曪細

5.聽聽聽聽聽聽聽 echo 浠诲姟

璇ヤ换鍔$殑浣滅敤鏄牴鎹棩蹇楁垨鐩戞帶鍣ㄧ殑绾у埆杈撳嚭淇℃伅銆傚畠鍖呮嫭 message 銆� file 銆� append 鍜� level 鍥涗釜灞炴�э紝涓句緥濡備笅锛�

鍥涳紟聽聽聽聽聽聽聽聽聽聽聽聽聽 鍒╃敤 Ant 鏋勫缓鍜岄儴缃� Java 宸ョ▼

Ant 鍙互浠f浛浣跨敤 javac 銆� java 鍜� jar 绛夊懡浠ゆ潵鎵ц java 鎿嶄綔锛屼粠鑰岃揪鍒拌交鏉剧殑鏋勫缓鍜岄儴缃� Java 宸ョ▼鐨勭洰鐨勩�備笅闈㈡潵鐪嬪嚑涓煡璇嗙偣銆�

1.聽聽聽聽聽聽聽 鍒╃敤 Ant 鐨� javac 浠诲姟鏉ョ紪璇� java 绋嬪簭

Ant 鐨� javac 浠诲姟鐢ㄤ簬瀹炵幇缂栬瘧 Java 绋嬪簭鐨勫姛鑳姐�備笅闈㈡潵鐪嬩竴涓畝鍗曠殑渚嬪瓙锛�

棣栧厛鎴戜滑寤虹珛鍚嶄负 antstudy 鐨� Java 宸ョ▼锛屽缓绔� src 鐩綍涓烘簮浠g爜鐩綍锛屽湪 src 鐩綍涓嬪缓绔� HelloWorld.java 杩欎釜绫绘枃浠躲�傝绫绘枃浠剁殑鍐呭濡備笅锛�

public聽聽 class聽 HelloWorld聽 {

public聽聽 static聽聽 void聽 main(String[] args)聽 {

System.out.println("Hello,Amigo");

}

}

鍚屾椂鍦� antstudy 宸ョ▼鐨勬牴鐩綍涓嬪缓绔� build.xml 鏂囦欢锛屽湪璇ユ枃浠朵腑缂栬瘧 src 鐩綍涓嬬殑 java 鏂囦欢锛屽苟灏嗙紪璇戝悗鐨� class 鏂囦欢鏀惧叆 build/classes 鐩綍涓紝鍦ㄧ紪璇戝墠锛岄渶娓呴櫎 classes 鐩綍锛岃鏂囦欢鐨勫唴瀹瑰涓嬶細


< project聽 name ="javacTest" default ="compile"聽 basedir =".">

< target聽 name ="clean">

< delete聽 dir ="build"/>


< target聽 name ="compile"聽 depends ="clean">

< mkdir聽 dir ="build/classes"/>

< javac聽 srcdir ="src"聽 destdir ="build/classes"/>



杩愯璇� build.xml 鏂囦欢锛屽彲鍦ㄥ伐绋嬩腑鐪嬪埌鏂板浜� build/classes 鐩綍锛屽苟鍦ㄨ鐩綍涓敓鎴愪簡缂栬瘧鍚庣殑 HelloWorld.class 鏂囦欢銆�

2.聽聽聽聽聽聽聽 浣跨敤 Ant 鐨� java 浠诲姟杩愯 Java 绋嬪簭

Ant 涓彲浠ヤ娇鐢� java 浠诲姟瀹炵幇杩愯 Java 绋嬪簭鐨勫姛鑳姐�備笅闈㈠湪 1 鐨勪緥瀛愪腑杩涜濡備笅鐨勪慨鏀癸紝淇敼鍚庣殑 build.xml 鏂囦欢鐨勫唴瀹瑰涓嬶細


< project聽 name ="javaTest"聽 default ="jar"聽 basedir =".">

< target聽 name ="clean">

< delete聽 dir ="build"/>


< target聽 name ="compile"聽 depends ="clean">

< mkdir聽 dir ="build/classes"/>

< javac聽 srcdir ="src"聽 destdir ="build/classes"/>


< target聽 name ="run"聽 depends ="compile">

< java聽 classname ="HelloWorld">

< classpath >

< pathelement聽 path ="build/classes"/>





杩愯璇� build.xml 鏂囦欢锛屽彲鍦ㄦ帶鍒跺彴鐪嬪埌 HelloWorld 鐨� main 鏂规硶鐨勮緭鍑恒��

3.聽聽聽聽聽聽聽 浣跨敤 Ant 鐨� jar 浠诲姟鐢熸垚 jar 鏂囦欢

璇昏�呭彲浠ュ湪涓婁緥鐨勫熀纭�涓婃洿杩涗竴姝ワ紝鏉ョ敓鎴� jar 鍖咃紝鍙湪 run 杩欎釜 target 涓嬪啀鍔犱笂濡備笅 target 锛�

< target聽 name ="jar"聽 depends ="run">

< jar聽 destfile ="helloworld.jar"聽 basedir ="build/classes">

< manifest >

< attribute聽 name ="Main-class"聽 value ="HelloWorld"/>




姝ゆ椂灏� ant 鐨� project 鐨� default 灞炴�ц缃负 jar 锛屽悓鏃惰繍琛岃 build.xml 鏂囦欢锛岃繍琛屽畬姣曞悗锛屽彲鐪嬪埌鍦ㄥ伐绋嬬洰褰曚笅鐢熸垚浜嗕竴涓� jar 鍖� HelloWorld.jar 銆�

4.聽聽聽聽聽聽聽 浣跨敤 Ant 鐨� war 浠诲姟鎵撳寘 J2EE Web 椤圭洰

寤虹珛涓�涓� J2EE Web 宸ョ▼锛屽叾鐩綍缁撴瀯濡備笅鍥炬墍绀猴細

鍏朵腑 src 涓烘簮浠g爜鐩綍锛� WebRoot 涓哄悇 jsp 瀛樻斁鐩綍锛� lib 涓哄伐绋嬬殑鍖呯洰褰曘�傚湪 antwebproject 宸ョ▼鐩綍涓嬪缓绔嬩簡 build.xml 鏂囦欢锛岃鏂囦欢涓鸿宸ョ▼鐨� Ant 鏋勪欢鏂囦欢銆傝鑰呭彲浠� src 鐩綍涓嬫斁鍏ュ湪鍓嶇画渚嬪瓙涓紑鍙戠殑 HelloWorld.java 鏂囦欢锛屽苟鍦� WebRoot 涓嬪缓绔� index.jsp 鏂囦欢锛屽叾鍐呭寰堢畝鍗曪紝灏辨槸杈撳嚭 Hello 淇℃伅锛屼唬鐮佸涓嬫墍绀猴細

<% @ page language="java" contentType="text/html; charset="UTF-8" pageEncoding="UTF-8" %>


< html >

< head >

< meta聽 http-equiv ="Content-Type"聽 content ="text/html; charset=ISO-8859-1">

< title > ant 鎵撳寘娴嬭瘯


< body >

Hello,Ant



鎺ヤ笅鏉ョ紪鍐� build.xml 鏂囦欢锛屽叾鍐呭濡備笅锛�


< project聽 name ="antwebproject"聽聽 default ="war" basedir =".">

< property聽 name ="classes"聽 value ="build/classes"/>

< property聽 name ="build" value ="build"/>

< property聽 name ="lib" value ="WebRoot/WEB-INF/lib"/>


< target聽 name ="clean">

< delete聽 dir ="build"/>



< target聽 name ="compile"聽 depends ="clean">

< mkdir聽 dir ="${classes}"/>

< javac聽 srcdir ="src"聽 destdir ="${classes}"/>



< target聽 name ="war"聽 depends ="compile">

< war聽 destfile ="${build}/antwebproject.war"聽 webxml ="WebRoot/WEB-INF/web.xml">


< fileset聽 dir ="WebRoot"聽 includes ="**/*.jsp"/>


< lib聽 dir ="${lib}"/>


< classesdir ="${classes}"/>




鍚� target 鐨勪綔鐢ㄥ湪鍐呭涓凡缁忚繘琛岃鏄庯紝鍦ㄦ涓嶅啀璧樿堪銆傝繍琛岃 build 鏂囦欢锛屾洿鏂扮洰褰曞悗锛屽彲鐪嬪埌鍦� build 鐩綍涓嬬敓鎴愪簡 antwebproject.war 鏂囦欢锛岃В寮�鍚庡彲鐪嬪埌鍏剁洰褰曠粨鏋勫涓嬶細

--META-INF

--MANIFEST.MF

--index.jsp

--WEB-INF

--lib

--log4j-1.2.9.jar

--classes

--HelloWorld.class

--web.xml

璇昏�呭彲浠ュ皢璇� war 鍖呮嫹璐濆埌 Tomcat 鐨勭洰褰曚笅鐪嬩竴涓嬭繍琛岀粨鏋溿��

浜旓紟聽聽聽聽聽聽聽聽聽聽聽聽聽 鎬荤粨

鍦ㄦ湰鏂囦腑锛岀瑪鑰呯敱娴呰嚦娣辫缁嗘弿杩颁簡 Ant 鐨勫畨瑁呬笌閰嶇疆銆佸叧閿厓绱犲拰甯哥敤浠诲姟銆傚苟閫氳繃瀹炰緥璁茶堪浜� Ant 鍦ㄦ垜浠� Java 椤圭洰涓殑搴旂敤锛岃杩颁簡缂栬瘧銆佽繍琛� java 绋嬪簭锛屼互鍙婃墦 jar 鍖呫�� war 鍖呯瓑鐭ヨ瘑锛屽紩棰嗚鑰呰繘鍏� Ant 鐨勫濡欎笘鐣屻�傚湪鏈枃涓彲浠ョ湅鍒帮紝 Ant 鍦ㄨ嚜鍔ㄦ瀯寤哄拰閮ㄧ讲 Java 绋嬪簭鏂归潰鏂逛究鏄撶敤锛岃�屼笖闈炲父鐏垫椿锛屼笉澶变负鎴戜滑 Java 寮�鍙戣�呯殑缁濅匠甯墜

http://blog.csdn.net/user4570/archive/2009/05/27/4221101.aspx

你可能感兴趣的:(Jenkins ant build.xml鏂囦欢璇﹁В(瀛︿範绗旇鍏�))