You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

faq.html 91 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!-- Content Stylesheet for Site -->
  3. <!-- start the processing -->
  4. <html>
  5. <!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  8. <meta name="author" value="Stefan Bodewig">
  9. <meta name="email" value="bodewig@apache.org">
  10. <title>Apache Ant - Frequently Asked Questions</title>
  11. </head>
  12. <body bgcolor="#ffffff" text="#000000" link="#525D76">
  13. <table border="0" width="100%" cellspacing="0">
  14. <!-- TOP IMAGE -->
  15. <tr>
  16. <td align="left">
  17. <a href="http://jakarta.apache.org"><img src="images/jakarta-logo.gif" border="0"/></a>
  18. </td>
  19. <td align="center">
  20. <a href="http://www.sdmagazine.com"><img src="images/sdm_productivity_award.gif" border="0" height="75" width="135"/></a>
  21. </td>
  22. <td align="center">
  23. <a href="http://www.javaworld.com"><img src="images/jw_ec_logo_winner2002.gif" border="0" height="85" width="230"/></a>
  24. </td>
  25. <td align="right">
  26. <a href="http://jakarta.apache.org/ant/"><img src="./images/ant_logo_large.gif" alt="Apache Ant" border="0"/></a>
  27. </td>
  28. </tr>
  29. </table>
  30. <table border="0" width="100%" cellspacing="4">
  31. <tr><td colspan="2">
  32. <hr noshade="" size="1"/>
  33. </td></tr>
  34. <tr>
  35. <!-- LEFT SIDE NAVIGATION -->
  36. <td valign="top" nowrap="true">
  37. <p><strong>Apache Ant</strong></p>
  38. <ul>
  39. <li> <a href="./index.html">Front Page</a>
  40. </li>
  41. <li> <a href="./antnews.html">News</a>
  42. </li>
  43. <li> <a href="./manual/index.html">Documentation</a>
  44. </li>
  45. <li> <a href="./projects.html">Related Projects</a>
  46. </li>
  47. <li> <a href="./external.html">External Tools and Tasks</a>
  48. </li>
  49. <li> <a href="./resources.html">Resources</a>
  50. </li>
  51. <li> <a href="./faq.html">Ant FAQ</a>
  52. </li>
  53. <li> <a href="./problems.html">Having Problems?</a>
  54. </li>
  55. </ul>
  56. <p><strong>Download</strong></p>
  57. <ul>
  58. <li> <a href="http://jakarta.apache.org/site/binindex.html">Binaries</a>
  59. </li>
  60. <li> <a href="http://jakarta.apache.org/site/sourceindex.html">Source Code</a>
  61. </li>
  62. </ul>
  63. <p><strong>Jakarta</strong></p>
  64. <ul>
  65. <li> <a href="http://jakarta.apache.org/site/news.html">News & Status</a>
  66. </li>
  67. <li> <a href="http://jakarta.apache.org/site/mission.html">Mission</a>
  68. </li>
  69. <li> <a href="http://jakarta.apache.org/site/guidelines.html">Guidelines Notes</a>
  70. </li>
  71. <li> <a href="http://jakarta.apache.org/site/faqs.html">FAQs</a>
  72. </li>
  73. </ul>
  74. <p><strong>Get Involved</strong></p>
  75. <ul>
  76. <li> <a href="http://jakarta.apache.org/site/getinvolved.html">Overview</a>
  77. </li>
  78. <li> <a href="http://jakarta.apache.org/site/cvsindex.html">CVS Repositories</a>
  79. </li>
  80. <li> <a href="http://jakarta.apache.org/site/mail.html">Mailing Lists</a>
  81. </li>
  82. <li> <a href="http://jakarta.apache.org/site/library.html">Reference Library</a>
  83. </li>
  84. <li> <a href="http://nagoya.apache.org/bugzilla/enter_bug.cgi?product=Ant">Bug Database</a>
  85. </li>
  86. <li> <a href="http://nagoya.apache.org/bugzilla/enter_bug.cgi?product=Ant&bug_severity=Enhancement">Enhancement Requests</a>
  87. </li>
  88. </ul>
  89. </td>
  90. <td align="left" valign="top">
  91. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  92. <tr><td bgcolor="#525D76">
  93. <font color="#ffffff" face="arial,helvetica,sanserif">
  94. <strong>Questions</strong>
  95. </font>
  96. </td></tr>
  97. <tr><td>
  98. <blockquote>
  99. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  100. <tr><td bgcolor="#828DA6">
  101. <font color="#ffffff" face="arial,helvetica,sanserif">
  102. <strong>About this FAQ</strong>
  103. </font>
  104. </td></tr>
  105. <tr><td>
  106. <blockquote>
  107. <ul>
  108. <li><a href="#latest-version">
  109. Where do I find the latest version of this
  110. document?
  111. </a></li>
  112. <li><a href="#adding-faqs">
  113. How can I contribute to this FAQ?
  114. </a></li>
  115. <li><a href="#creating-faq">
  116. How do you create the HTML version of this
  117. FAQ?
  118. </a></li>
  119. </ul>
  120. </blockquote>
  121. </td></tr>
  122. </table>
  123. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  124. <tr><td bgcolor="#828DA6">
  125. <font color="#ffffff" face="arial,helvetica,sanserif">
  126. <strong>General</strong>
  127. </font>
  128. </td></tr>
  129. <tr><td>
  130. <blockquote>
  131. <ul>
  132. <li><a href="#what-is-ant">
  133. What is Apache Ant?
  134. </a></li>
  135. <li><a href="#ant-name">
  136. Why do you call it Ant?
  137. </a></li>
  138. <li><a href="#history">
  139. Tell us a little bit about Ant's history.
  140. </a></li>
  141. </ul>
  142. </blockquote>
  143. </td></tr>
  144. </table>
  145. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  146. <tr><td bgcolor="#828DA6">
  147. <font color="#ffffff" face="arial,helvetica,sanserif">
  148. <strong>Installation</strong>
  149. </font>
  150. </td></tr>
  151. <tr><td>
  152. <blockquote>
  153. <ul>
  154. <li><a href="#no-gnu-tar">
  155. I get checksum errors when I try to extract the
  156. <code>tar.gz</code> distribution file. Why?
  157. </a></li>
  158. </ul>
  159. </blockquote>
  160. </td></tr>
  161. </table>
  162. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  163. <tr><td bgcolor="#828DA6">
  164. <font color="#ffffff" face="arial,helvetica,sanserif">
  165. <strong>Using Ant</strong>
  166. </font>
  167. </td></tr>
  168. <tr><td>
  169. <blockquote>
  170. <ul>
  171. <li><a href="#always-recompiles">
  172. Why does Ant always recompile all my Java files?
  173. </a></li>
  174. <li><a href="#passing-cli-args">
  175. How do I pass parameters from the command line to my
  176. build file?
  177. </a></li>
  178. <li><a href="#jikes-switches">
  179. How can I use Jikes-specific command-line
  180. switches?
  181. </a></li>
  182. <li><a href="#shell-redirect-1">
  183. How do I include a &lt; character in my command-line arguments?
  184. </a></li>
  185. <li><a href="#shell-redirect-2">
  186. How do I redirect standard input or standard output
  187. in the <code>&lt;exec&gt;</code> task?
  188. </a></li>
  189. <li><a href="#batch-shell-execute">
  190. How do I execute a batch file or shell script from Ant?
  191. </a></li>
  192. <li><a href="#defaultexcludes">
  193. I've used a <code>&lt;delete&gt;</code> task to delete
  194. unwanted
  195. SourceSafe control files (CVS files, editor backup files, etc.), but
  196. it doesn't seem to work; the files never get deleted. What's
  197. wrong?
  198. </a></li>
  199. <li><a href="#multi-conditions">
  200. I want to execute a particular target only if
  201. multiple conditions are true.
  202. </a></li>
  203. <li><a href="#stop-dependency">
  204. I have a target I want to skip if a property is set,
  205. so I have <code>unless="property"</code> as an attribute
  206. of the target, but all the targets this target
  207. depends on are still executed. Why?
  208. </a></li>
  209. <li><a href="#include-order">
  210. In my <code>&lt;fileset&gt;</code>, I've put in an
  211. <code>&lt;exclude&gt;</code> of all files followed by an
  212. <code>&lt;include&gt;</code> of just the files I want, but it
  213. isn't giving me any files at all. What's wrong?
  214. </a></li>
  215. <li><a href="#encoding">
  216. How can I include national characters like German
  217. umlauts in my build file?
  218. </a></li>
  219. </ul>
  220. </blockquote>
  221. </td></tr>
  222. </table>
  223. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  224. <tr><td bgcolor="#828DA6">
  225. <font color="#ffffff" face="arial,helvetica,sanserif">
  226. <strong>Ant and IDEs/Editors</strong>
  227. </font>
  228. </td></tr>
  229. <tr><td>
  230. <blockquote>
  231. <ul>
  232. <li><a href="#integration">
  233. Is Ant supported by my IDE/Editor?
  234. </a></li>
  235. <li><a href="#emacs-mode">
  236. Why doesn't (X)Emacs/vi/MacOS X's project builder
  237. correctly parse the error messages generated by Ant?
  238. </a></li>
  239. </ul>
  240. </blockquote>
  241. </td></tr>
  242. </table>
  243. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  244. <tr><td bgcolor="#828DA6">
  245. <font color="#ffffff" face="arial,helvetica,sanserif">
  246. <strong>Advanced Issues</strong>
  247. </font>
  248. </td></tr>
  249. <tr><td>
  250. <blockquote>
  251. <ul>
  252. <li><a href="#dtd">
  253. Is there a DTD that I can use to validate my build
  254. files?
  255. </a></li>
  256. <li><a href="#xml-entity-include">
  257. How do I include an XML snippet in my build file?
  258. </a></li>
  259. <li><a href="#mail-logger">
  260. How do I send an email with the result of my build
  261. process?
  262. </a></li>
  263. <li><a href="#listener-properties">
  264. How do I get at the properties that Ant was running
  265. with from inside BuildListener?
  266. </a></li>
  267. </ul>
  268. </blockquote>
  269. </td></tr>
  270. </table>
  271. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  272. <tr><td bgcolor="#828DA6">
  273. <font color="#ffffff" face="arial,helvetica,sanserif">
  274. <strong>Known Problems</strong>
  275. </font>
  276. </td></tr>
  277. <tr><td>
  278. <blockquote>
  279. <ul>
  280. <li><a href="#remove-cr">
  281. &lt;chmod&gt; or &lt;exec&gt; doesn't work in Ant
  282. 1.3 on Unix
  283. </a></li>
  284. <li><a href="#javadoc-cannot-execute">
  285. JavaDoc failed: java.io.IOException: javadoc: cannot execute
  286. </a></li>
  287. <li><a href="#delegating-classloader">
  288. &lt;style&gt; or &lt;junit&gt; ignores my
  289. &lt;classpath&gt;
  290. </a></li>
  291. </ul>
  292. </blockquote>
  293. </td></tr>
  294. </table>
  295. </blockquote>
  296. </td></tr>
  297. </table>
  298. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  299. <tr><td bgcolor="#525D76">
  300. <font color="#ffffff" face="arial,helvetica,sanserif">
  301. <strong>Answers</strong>
  302. </font>
  303. </td></tr>
  304. <tr><td>
  305. <blockquote>
  306. <a name="latest-version">
  307. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  308. <tr><td bgcolor="#828DA6">
  309. <font color="#ffffff" face="arial,helvetica,sanserif">
  310. <strong>
  311. Where do I find the latest version of this
  312. document?
  313. </strong>
  314. </font>
  315. </td></tr>
  316. <tr><td>
  317. <blockquote>
  318. <p>The latest version can always be found at Ant's homepage
  319. <a href="http://jakarta.apache.org/ant/faq.html">http://jakarta.apache.org/ant/faq.html</a>.</p>
  320. </blockquote>
  321. </td></tr>
  322. </table>
  323. </a>
  324. <a name="adding-faqs">
  325. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  326. <tr><td bgcolor="#828DA6">
  327. <font color="#ffffff" face="arial,helvetica,sanserif">
  328. <strong>
  329. How can I contribute to this FAQ?
  330. </strong>
  331. </font>
  332. </td></tr>
  333. <tr><td>
  334. <blockquote>
  335. <p>The page you are looking it is generated from
  336. <a href="http://cvs.apache.org/viewcvs.cgi/~checkout~/jakarta-ant/xdocs/faq.xml">this</a>
  337. document. If you want to add a new question, please submit
  338. a patch against this document to one of Ant's mailing lists;
  339. hopefully, the structure is self-explanatory.</p>
  340. <p>If you don't know how to create a patch, see the patches
  341. section of <a href="http://jakarta.apache.org/site/source.html">this
  342. page</a>.</p>
  343. </blockquote>
  344. </td></tr>
  345. </table>
  346. </a>
  347. <a name="creating-faq">
  348. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  349. <tr><td bgcolor="#828DA6">
  350. <font color="#ffffff" face="arial,helvetica,sanserif">
  351. <strong>
  352. How do you create the HTML version of this
  353. FAQ?
  354. </strong>
  355. </font>
  356. </td></tr>
  357. <tr><td>
  358. <blockquote>
  359. <p>We use
  360. <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a>
  361. to render the HTML version from the original XML file.</p>
  362. <p>The Velocity stylesheets used to process the XML files can
  363. be found in the <code>xdocs/stylesheets</code> subdirectory of
  364. Ant's CVS repository - the build file <code>docs.xml</code> is
  365. used to drive Anakia. This file assumes that you have the
  366. <code>jakarta-site2</code> module checked out from CVS as
  367. well, but if you follow the instruction from Anakia's
  368. homepage, you should get it to work without that. Just make
  369. sure all required jars are in the task's classpath.</p>
  370. </blockquote>
  371. </td></tr>
  372. </table>
  373. </a>
  374. <a name="what-is-ant">
  375. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  376. <tr><td bgcolor="#828DA6">
  377. <font color="#ffffff" face="arial,helvetica,sanserif">
  378. <strong>
  379. What is Apache Ant?
  380. </strong>
  381. </font>
  382. </td></tr>
  383. <tr><td>
  384. <blockquote>
  385. <p> Ant is a Java-based build tool. In theory, it is kind of
  386. like Make, without Make's wrinkles and with the full
  387. portability of pure Java code.</p>
  388. </blockquote>
  389. </td></tr>
  390. </table>
  391. </a>
  392. <a name="ant-name">
  393. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  394. <tr><td bgcolor="#828DA6">
  395. <font color="#ffffff" face="arial,helvetica,sanserif">
  396. <strong>
  397. Why do you call it Ant?
  398. </strong>
  399. </font>
  400. </td></tr>
  401. <tr><td>
  402. <blockquote>
  403. <p>According to Ant's original author, James Duncan
  404. Davidson, the name is an acronym for "Another Neat
  405. Tool".</p>
  406. <p>Later explanations go along the lines of "ants
  407. do an extremely good job at building things", or
  408. "ants are very small and can carry a weight dozens of times
  409. their own" - describing what Ant is intended to
  410. be.</p>
  411. </blockquote>
  412. </td></tr>
  413. </table>
  414. </a>
  415. <a name="history">
  416. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  417. <tr><td bgcolor="#828DA6">
  418. <font color="#ffffff" face="arial,helvetica,sanserif">
  419. <strong>
  420. Tell us a little bit about Ant's history.
  421. </strong>
  422. </font>
  423. </td></tr>
  424. <tr><td>
  425. <blockquote>
  426. <p>Initially, Ant was part of the Tomcat code base, when it was
  427. donated to the Apache Software Foundation. It was
  428. created by James Duncan Davidson, who is also the original
  429. author of Tomcat. Ant was there to build Tomcat, nothing
  430. else.</p>
  431. <p>Soon thereafter, several open source Java projects realized
  432. that Ant could solve the problems they had with Makefiles.
  433. Starting with the projects hosted at Jakarta and the old Java
  434. Apache project, Ant spread like a virus and is now the build
  435. tool of choice for a lot of projects.</p>
  436. <p>In January 2000, Ant was moved to a separate CVS module and
  437. was promoted to a project of its own, independent of
  438. Tomcat, and became Apache Ant.</p>
  439. <p>The first version of Ant that was exposed to a larger audience
  440. was the one that shipped with Tomcat's 3.1 release on 19 April
  441. 2000. This version has later been referred to as Ant
  442. 0.3.1.</p>
  443. <p>The first official release of Ant as a stand-alone product was
  444. Ant 1.1, released on 19 July 2000. The complete release
  445. history:</p>
  446. <table>
  447. <tr>
  448. <td bgcolor="#039acc" colspan="" rowspan=""
  449. valign="top" align="left">
  450. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  451. Ant Version
  452. </font>
  453. </td>
  454. <td bgcolor="#039acc" colspan="" rowspan=""
  455. valign="top" align="left">
  456. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  457. Release Date
  458. </font>
  459. </td>
  460. </tr>
  461. <tr>
  462. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  463. valign="top" align="left">
  464. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  465. 1.1
  466. </font>
  467. </td>
  468. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  469. valign="top" align="left">
  470. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  471. 19 July 2000
  472. </font>
  473. </td>
  474. </tr>
  475. <tr>
  476. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  477. valign="top" align="left">
  478. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  479. 1.2
  480. </font>
  481. </td>
  482. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  483. valign="top" align="left">
  484. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  485. 24 October 2000
  486. </font>
  487. </td>
  488. </tr>
  489. <tr>
  490. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  491. valign="top" align="left">
  492. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  493. 1.3
  494. </font>
  495. </td>
  496. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  497. valign="top" align="left">
  498. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  499. 3 March 2001
  500. </font>
  501. </td>
  502. </tr>
  503. <tr>
  504. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  505. valign="top" align="left">
  506. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  507. 1.4
  508. </font>
  509. </td>
  510. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  511. valign="top" align="left">
  512. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  513. 3 September 2001
  514. </font>
  515. </td>
  516. </tr>
  517. <tr>
  518. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  519. valign="top" align="left">
  520. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  521. 1.4.1
  522. </font>
  523. </td>
  524. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  525. valign="top" align="left">
  526. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  527. 11 October 2001
  528. </font>
  529. </td>
  530. </tr>
  531. </table>
  532. </blockquote>
  533. </td></tr>
  534. </table>
  535. </a>
  536. <a name="no-gnu-tar">
  537. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  538. <tr><td bgcolor="#828DA6">
  539. <font color="#ffffff" face="arial,helvetica,sanserif">
  540. <strong>
  541. I get checksum errors when I try to extract the
  542. <code>tar.gz</code> distribution file. Why?
  543. </strong>
  544. </font>
  545. </td></tr>
  546. <tr><td>
  547. <blockquote>
  548. <p>Ant's distribution contains file names that are longer
  549. than 100 characters, which is not supported by the standard
  550. tar file format. Several different implementations of tar use
  551. different and incompatible ways to work around this
  552. restriction.</p>
  553. <p>Ant's &lt;tar&gt; task can create tar archives that use
  554. the GNU tar extension, and this has been used when putting
  555. together the distribution. If you are using a different
  556. version of tar (for example, the one shipping with Solaris),
  557. you cannot use it to extract the archive.</p>
  558. <p>The solution is to either install GNU tar, which can be
  559. found <a href="http://www.gnu.org/software/tar/tar.html">here</a>,
  560. or use the zip archive instead (you can extract it using
  561. <code>jar xf</code>).</p>
  562. </blockquote>
  563. </td></tr>
  564. </table>
  565. </a>
  566. <a name="always-recompiles">
  567. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  568. <tr><td bgcolor="#828DA6">
  569. <font color="#ffffff" face="arial,helvetica,sanserif">
  570. <strong>
  571. Why does Ant always recompile all my Java files?
  572. </strong>
  573. </font>
  574. </td></tr>
  575. <tr><td>
  576. <blockquote>
  577. <p>In order to find out which files should be compiled, Ant
  578. compares the timestamps of the source files to those of the
  579. resulting <code>.class</code> files. Opening all source files
  580. to find out which package they belong to would be very
  581. inefficient. Instead, Ant expects you to place your
  582. source files in a directory hierarchy that mirrors your
  583. package hierarchy and to point Ant to the root of this
  584. directory tree with the <code>srcdir</code> attribute.</p>
  585. <p>Say you have <code>&lt;javac srcdir="src"
  586. destdir="dest"/&gt;</code>. If Ant finds a file
  587. <code>src/a/b/C.java</code>, it expects it to be in package
  588. <code>a.b</code> so that the resulting <code>.class</code>
  589. file is going to be <code>dest/a/b/C.class</code>.</p>
  590. <p>If your source-tree directory structure does not match your
  591. package structure, Ant's heuristic won't work, and
  592. it will recompile classes that are up-to-date. Ant is not the
  593. only tool that expects a source-tree layout like this.</p>
  594. <p>If you have Java source files that aren't declared to
  595. be part of any package, you can still use the <code>&lt;javac&gt;</code>
  596. task to compile these files correctly - just set the
  597. <code>srcdir</code> and <code>destdir</code> attributes to
  598. the actual directory the source
  599. files live in and the directory the class files should go into,
  600. respectively.</p>
  601. </blockquote>
  602. </td></tr>
  603. </table>
  604. </a>
  605. <a name="passing-cli-args">
  606. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  607. <tr><td bgcolor="#828DA6">
  608. <font color="#ffffff" face="arial,helvetica,sanserif">
  609. <strong>
  610. How do I pass parameters from the command line to my
  611. build file?
  612. </strong>
  613. </font>
  614. </td></tr>
  615. <tr><td>
  616. <blockquote>
  617. <p>Use properties. Using <code>ant
  618. -D<em>name</em>=<em>value</em></code> lets you define values for
  619. properties on the Ant command line. These properties can then be
  620. used within your build file as
  621. any normal property: <code>${<em>name</em>}</code> will put in
  622. <code><em>value</em></code>.</p>
  623. </blockquote>
  624. </td></tr>
  625. </table>
  626. </a>
  627. <a name="jikes-switches">
  628. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  629. <tr><td bgcolor="#828DA6">
  630. <font color="#ffffff" face="arial,helvetica,sanserif">
  631. <strong>
  632. How can I use Jikes-specific command-line
  633. switches?
  634. </strong>
  635. </font>
  636. </td></tr>
  637. <tr><td>
  638. <blockquote>
  639. <p>A couple of switches are supported via "magic"
  640. properties:</p>
  641. <table>
  642. <tr>
  643. <td bgcolor="#039acc" colspan="" rowspan=""
  644. valign="top" align="left">
  645. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  646. switch
  647. </font>
  648. </td>
  649. <td bgcolor="#039acc" colspan="" rowspan=""
  650. valign="top" align="left">
  651. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  652. property
  653. </font>
  654. </td>
  655. <td bgcolor="#039acc" colspan="" rowspan=""
  656. valign="top" align="left">
  657. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  658. default
  659. </font>
  660. </td>
  661. </tr>
  662. <tr>
  663. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  664. valign="top" align="left">
  665. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  666. +E
  667. </font>
  668. </td>
  669. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  670. valign="top" align="left">
  671. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  672. build.compiler.emacs
  673. </font>
  674. </td>
  675. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  676. valign="top" align="left">
  677. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  678. false == not set
  679. </font>
  680. </td>
  681. </tr>
  682. <tr>
  683. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  684. valign="top" align="left">
  685. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  686. +P
  687. </font>
  688. </td>
  689. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  690. valign="top" align="left">
  691. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  692. build.compiler.pedantic
  693. </font>
  694. </td>
  695. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  696. valign="top" align="left">
  697. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  698. false == not set
  699. </font>
  700. </td>
  701. </tr>
  702. <tr>
  703. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  704. valign="top" align="left">
  705. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  706. +F
  707. </font>
  708. </td>
  709. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  710. valign="top" align="left">
  711. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  712. build.compiler.fulldepend
  713. </font>
  714. </td>
  715. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  716. valign="top" align="left">
  717. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  718. false == not set
  719. </font>
  720. </td>
  721. </tr>
  722. <tr>
  723. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  724. valign="top" align="left">
  725. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  726. <strong>(Only for Ant &lt; 1.4; replaced by the
  727. <code><strong>nowarn</strong></code>
  728. attribute of the <code><strong>&lt;javac&gt;</strong></code>
  729. task after that.)</strong><br />-nowarn
  730. </font>
  731. </td>
  732. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  733. valign="top" align="left">
  734. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  735. build.compiler.warnings
  736. </font>
  737. </td>
  738. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  739. valign="top" align="left">
  740. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  741. true == not set
  742. </font>
  743. </td>
  744. </tr>
  745. </table>
  746. </blockquote>
  747. </td></tr>
  748. </table>
  749. </a>
  750. <a name="shell-redirect-1">
  751. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  752. <tr><td bgcolor="#828DA6">
  753. <font color="#ffffff" face="arial,helvetica,sanserif">
  754. <strong>
  755. How do I include a &lt; character in my command-line arguments?
  756. </strong>
  757. </font>
  758. </td></tr>
  759. <tr><td>
  760. <blockquote>
  761. <p>The short answer is "Use: <code>&amp;lt;</code>".</p>
  762. <p>The long answer is that this probably won't do what you
  763. want anyway (see <a href="#shell-redirect-2">the next
  764. section</a>).</p>
  765. </blockquote>
  766. </td></tr>
  767. </table>
  768. </a>
  769. <a name="shell-redirect-2">
  770. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  771. <tr><td bgcolor="#828DA6">
  772. <font color="#ffffff" face="arial,helvetica,sanserif">
  773. <strong>
  774. How do I redirect standard input or standard output
  775. in the <code>&lt;exec&gt;</code> task?
  776. </strong>
  777. </font>
  778. </td></tr>
  779. <tr><td>
  780. <blockquote>
  781. <p>Say you want to redirect the standard input stream of the
  782. <code>cat</code> command to read from a file, something
  783. like:</p>
  784. <div align="left">
  785. <table cellspacing="4" cellpadding="0" border="0">
  786. <tr>
  787. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  788. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  789. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  790. </tr>
  791. <tr>
  792. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  793. <td bgcolor="#ffffff"><pre>
  794. shell-prompt&gt; cat &lt; foo
  795. </pre></td>
  796. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  797. </tr>
  798. <tr>
  799. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  800. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  801. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  802. </tr>
  803. </table>
  804. </div>
  805. <p>and try to translate it into</p>
  806. <div align="left">
  807. <table cellspacing="4" cellpadding="0" border="0">
  808. <tr>
  809. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  810. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  811. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  812. </tr>
  813. <tr>
  814. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  815. <td bgcolor="#ffffff"><pre>
  816. &lt;exec executable=&quot;cat&quot;&gt;
  817. &lt;arg value=&quot;&amp;lt;&quot; /&gt;
  818. &lt;arg value=&quot;foo&quot; /&gt;
  819. &lt;/exec&gt;
  820. </pre></td>
  821. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  822. </tr>
  823. <tr>
  824. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  825. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  826. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  827. </tr>
  828. </table>
  829. </div>
  830. <p>This will not do what you expect. The input redirection is
  831. performed by your shell, not the command itself, so this
  832. should read:</p>
  833. <div align="left">
  834. <table cellspacing="4" cellpadding="0" border="0">
  835. <tr>
  836. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  837. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  838. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  839. </tr>
  840. <tr>
  841. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  842. <td bgcolor="#ffffff"><pre>
  843. &lt;exec executable=&quot;/bin/sh&quot;&gt;
  844. &lt;arg value=&quot;-c&quot; /&gt;
  845. &lt;arg value=&quot;cat &amp;lt; foo&quot; /&gt;
  846. &lt;/exec&gt;
  847. </pre></td>
  848. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  849. </tr>
  850. <tr>
  851. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  852. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  853. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  854. </tr>
  855. </table>
  856. </div>
  857. <p>Note that you must use the <code>value</code> attribute of
  858. <code>&lt;arg&gt;</code> in the last element, in order to have
  859. the command passed as a single, quoted argument. Alternatively,
  860. you can use:</p>
  861. <div align="left">
  862. <table cellspacing="4" cellpadding="0" border="0">
  863. <tr>
  864. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  865. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  866. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  867. </tr>
  868. <tr>
  869. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  870. <td bgcolor="#ffffff"><pre>
  871. &lt;exec executable=&quot;/bin/sh&quot;&gt;
  872. &lt;arg line='-c &quot;cat &amp;lt; foo&quot;'/&gt;
  873. &lt;/exec&gt;
  874. </pre></td>
  875. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  876. </tr>
  877. <tr>
  878. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  879. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  880. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  881. </tr>
  882. </table>
  883. </div>
  884. <p>Note the double-quotes nested inside the single-quotes.</p>
  885. </blockquote>
  886. </td></tr>
  887. </table>
  888. </a>
  889. <a name="batch-shell-execute">
  890. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  891. <tr><td bgcolor="#828DA6">
  892. <font color="#ffffff" face="arial,helvetica,sanserif">
  893. <strong>
  894. How do I execute a batch file or shell script from Ant?
  895. </strong>
  896. </font>
  897. </td></tr>
  898. <tr><td>
  899. <blockquote>
  900. <p>On native Unix systems, you should be able to run shell scripts
  901. directly. On systems running a Unix-type shell (for example, Cygwin
  902. on Windows) execute the (command) shell instead - <code>cmd</code>
  903. for batch files, <code>sh</code> for shell scripts - then pass the
  904. batch file or shell script (plus any arguments to the script)
  905. as a single command, using the <code>/c</code> or
  906. <code>-c</code> switch, respectively. See
  907. <a href="#shell-redirect-2">the above section</a>
  908. for example <code>&lt;exec&gt;</code> tasks
  909. executing <code>sh</code>. For batch files, use something like:</p>
  910. <div align="left">
  911. <table cellspacing="4" cellpadding="0" border="0">
  912. <tr>
  913. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  914. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  915. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  916. </tr>
  917. <tr>
  918. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  919. <td bgcolor="#ffffff"><pre>
  920. &lt;exec dir=&quot;.&quot; executable=&quot;cmd&quot; os=&quot;Windows NT&quot;&gt;
  921. &lt;arg line=&quot;/c test.bat&quot;/&gt;
  922. &lt;/exec&gt;
  923. </pre></td>
  924. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  925. </tr>
  926. <tr>
  927. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  928. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  929. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  930. </tr>
  931. </table>
  932. </div>
  933. </blockquote>
  934. </td></tr>
  935. </table>
  936. </a>
  937. <a name="defaultexcludes">
  938. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  939. <tr><td bgcolor="#828DA6">
  940. <font color="#ffffff" face="arial,helvetica,sanserif">
  941. <strong>
  942. I've used a <code>&lt;delete&gt;</code> task to delete
  943. unwanted
  944. SourceSafe control files (CVS files, editor backup files, etc.), but
  945. it doesn't seem to work; the files never get deleted. What's
  946. wrong?
  947. </strong>
  948. </font>
  949. </td></tr>
  950. <tr><td>
  951. <blockquote>
  952. <p>This is probably happening because, by default, Ant excludes
  953. SourceSafe control files (<code>vssver.scc</code>) and certain other
  954. files from FileSets.</p>
  955. <p>Here's what you probably did:</p>
  956. <div align="left">
  957. <table cellspacing="4" cellpadding="0" border="0">
  958. <tr>
  959. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  960. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  961. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  962. </tr>
  963. <tr>
  964. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  965. <td bgcolor="#ffffff"><pre>
  966. &lt;delete&gt;
  967. &lt;fileset dir=&quot;${build.src}&quot; includes=&quot;**/vssver.scc&quot;/&gt;
  968. &lt;/delete&gt;
  969. </pre></td>
  970. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  971. </tr>
  972. <tr>
  973. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  974. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  975. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  976. </tr>
  977. </table>
  978. </div>
  979. <p>You need to switch off the default exclusions,
  980. and it will work:</p>
  981. <div align="left">
  982. <table cellspacing="4" cellpadding="0" border="0">
  983. <tr>
  984. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  985. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  986. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  987. </tr>
  988. <tr>
  989. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  990. <td bgcolor="#ffffff"><pre>
  991. &lt;delete&gt;
  992. &lt;fileset dir=&quot;${build.src}&quot; includes=&quot;**/vssver.scc&quot;
  993. defaultexcludes=&quot;no&quot;/&gt;
  994. &lt;/delete&gt;
  995. </pre></td>
  996. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  997. </tr>
  998. <tr>
  999. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1000. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1001. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1002. </tr>
  1003. </table>
  1004. </div>
  1005. <p>For a complete listing of the patterns that are excluded
  1006. by default, see <a href="manual/dirtasks.html#defaultexcludes">the user
  1007. manual</a>.</p>
  1008. </blockquote>
  1009. </td></tr>
  1010. </table>
  1011. </a>
  1012. <a name="multi-conditions">
  1013. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1014. <tr><td bgcolor="#828DA6">
  1015. <font color="#ffffff" face="arial,helvetica,sanserif">
  1016. <strong>
  1017. I want to execute a particular target only if
  1018. multiple conditions are true.
  1019. </strong>
  1020. </font>
  1021. </td></tr>
  1022. <tr><td>
  1023. <blockquote>
  1024. <p>There are actually several answers to this question.</p>
  1025. <p>If you have only one set and one unset property to test,
  1026. you can specify both an <code>if</code> and an <code>unless</code>
  1027. attribute for the target, and they will act as if they
  1028. are "anded" together.</p>
  1029. <p>If you are using a version of Ant 1.3 or earlier, the
  1030. way to work with all other cases is to chain targets together
  1031. to determine the specific state you want to test for.</p>
  1032. <p>To see how this works, assume you have three properties:
  1033. <code>prop1</code>, <code>prop2</code>, and <code>prop3</code>.
  1034. You want to test that <code>prop1</code> and <code>prop2</code>
  1035. are set, and that <code>prop3</code> is not. If the condition
  1036. holds true you want to echo "yes".</p>
  1037. <p>Here is the implementation in Ant 1.3 and earlier:</p>
  1038. <div align="left">
  1039. <table cellspacing="4" cellpadding="0" border="0">
  1040. <tr>
  1041. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1042. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1043. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1044. </tr>
  1045. <tr>
  1046. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1047. <td bgcolor="#ffffff"><pre>
  1048. &lt;target name=&quot;cond&quot; depends=&quot;cond-if&quot;/&gt;
  1049. &lt;target name=&quot;cond-if&quot; if=&quot;prop1&quot;&gt;
  1050. &lt;antcall target=&quot;cond-if-2&quot;/&gt;
  1051. &lt;/target&gt;
  1052. &lt;target name=&quot;cond-if-2&quot; if=&quot;prop2&quot;&gt;
  1053. &lt;antcall target=&quot;cond-if-3&quot;/&gt;
  1054. &lt;/target&gt;
  1055. &lt;target name=&quot;cond-if-3&quot; unless=&quot;prop3&quot;&gt;
  1056. &lt;echo message=&quot;yes&quot;/&gt;
  1057. &lt;/target&gt;
  1058. </pre></td>
  1059. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1060. </tr>
  1061. <tr>
  1062. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1063. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1064. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1065. </tr>
  1066. </table>
  1067. </div>
  1068. <p>Note: <code>&lt;antcall&gt;</code> tasks do <em>not</em> pass
  1069. property changes back up to the environment they were called
  1070. from, so you would'nt be able to, for example, set a
  1071. <code>result</code> property in the <code>cond-if-3</code> target,
  1072. then do
  1073. <code>&lt;echo message="result is ${result}"/&gt;</code>
  1074. in the <code>cond</code> target.</p>
  1075. <p>Starting with Ant 1.4, you can use the
  1076. <code>&lt;condition&gt;</code> task.</p>
  1077. <div align="left">
  1078. <table cellspacing="4" cellpadding="0" border="0">
  1079. <tr>
  1080. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1081. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1082. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1083. </tr>
  1084. <tr>
  1085. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1086. <td bgcolor="#ffffff"><pre>
  1087. &lt;target name=&quot;cond&quot; depends=&quot;cond-if,cond-else&quot;/&gt;
  1088. &lt;target name=&quot;check-cond&quot;&gt;
  1089. &lt;condition property=&quot;cond-is-true&quot;&gt;
  1090. &lt;and&gt;
  1091. &lt;not&gt;
  1092. &lt;equals arg1=&quot;${prop1}&quot; arg2=&quot;$${prop1}&quot; /&gt;
  1093. &lt;/not&gt;
  1094. &lt;not&gt;
  1095. &lt;equals arg1=&quot;${prop2}&quot; arg2=&quot;$${prop2}&quot; /&gt;
  1096. &lt;/not&gt;
  1097. &lt;equals arg1=&quot;${prop3}&quot; arg2=&quot;$${prop3}&quot; /&gt;
  1098. &lt;/and&gt;
  1099. &lt;/condition&gt;
  1100. &lt;/target&gt;
  1101. &lt;target name=&quot;cond-if&quot; depends=&quot;check-cond&quot; if=&quot;cond-is-true&quot;&gt;
  1102. &lt;echo message=&quot;yes&quot;/&gt;
  1103. &lt;/target&gt;
  1104. &lt;target name=&quot;cond-else&quot; depends=&quot;check-cond&quot; unless=&quot;cond-is-true&quot;&gt;
  1105. &lt;echo message=&quot;no&quot;/&gt;
  1106. &lt;/target&gt;
  1107. </pre></td>
  1108. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1109. </tr>
  1110. <tr>
  1111. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1112. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1113. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1114. </tr>
  1115. </table>
  1116. </div>
  1117. <p>This version takes advantage of two things:</p>
  1118. <ul>
  1119. <li>If a property <code>a</code> has not been set,
  1120. <code>${a}</code> will evaluate to <code>${a}</code>.</li>
  1121. <li>To get a literal <code>$</code> in Ant, you have to
  1122. escape it with another <code>$</code> - this will also break
  1123. the special treatment of the <code>${</code> sequence.</li>
  1124. </ul>
  1125. <p>Because testing for a literal <code>${property}</code> string
  1126. isn't all that readable or easy to understand,
  1127. post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element
  1128. to the <code>&lt;condition&gt;</code> task.</p>
  1129. <p>Here is the previous example done using
  1130. <code>&lt;isset&gt;</code>:</p>
  1131. <div align="left">
  1132. <table cellspacing="4" cellpadding="0" border="0">
  1133. <tr>
  1134. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1135. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1136. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1137. </tr>
  1138. <tr>
  1139. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1140. <td bgcolor="#ffffff"><pre>
  1141. &lt;target name=&quot;check-cond&quot;&gt;
  1142. &lt;condition property=&quot;cond-is-true&quot;&gt;
  1143. &lt;and&gt;
  1144. &lt;isset property=&quot;prop1&quot;/&gt;
  1145. &lt;isset property=&quot;prop2&quot;/&gt;
  1146. &lt;not&gt;
  1147. &lt;isset property=&quot;prop3&quot;/&gt;
  1148. &lt;/not&gt;
  1149. &lt;/and&gt;
  1150. &lt;/condition&gt;
  1151. &lt;/target&gt;
  1152. </pre></td>
  1153. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1154. </tr>
  1155. <tr>
  1156. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1157. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1158. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1159. </tr>
  1160. </table>
  1161. </div>
  1162. <p>The last option is to use a scripting language to set the
  1163. properties. This can be particularly handy when you need much
  1164. finer control than the simple conditions shown here but, of
  1165. course, comes with the overhead of adding JAR files to support
  1166. the language, to say nothing of the added maintenance in requiring
  1167. two languages to implement a single system. See the
  1168. <a href="manual/OptionalTasks/script.html">
  1169. <code>&lt;script&gt;</code> task documentation</a> for more
  1170. details.</p>
  1171. </blockquote>
  1172. </td></tr>
  1173. </table>
  1174. </a>
  1175. <a name="stop-dependency">
  1176. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1177. <tr><td bgcolor="#828DA6">
  1178. <font color="#ffffff" face="arial,helvetica,sanserif">
  1179. <strong>
  1180. I have a target I want to skip if a property is set,
  1181. so I have <code>unless="property"</code> as an attribute
  1182. of the target, but all the targets this target
  1183. depends on are still executed. Why?
  1184. </strong>
  1185. </font>
  1186. </td></tr>
  1187. <tr><td>
  1188. <blockquote>
  1189. <p>The list of dependencies is generated by Ant before any of the
  1190. targets are run. This allows dependent targets, such as an
  1191. <code>init</code> target, to set properties that can control the
  1192. execution of the targets higher in the dependency graph. This
  1193. is a good thing.</p>
  1194. <p>However, when your dependencies break down the
  1195. higher-level task
  1196. into several smaller steps, this behaviour becomes
  1197. counter-intuitive. There are a couple of solutions available:
  1198. </p>
  1199. <ol>
  1200. <li>Put the same condition on each of the dependent targets.</li>
  1201. <li>Execute the steps using <code>&lt;antcall&gt;</code>,
  1202. instead of specifying them inside the <code>depends</code>
  1203. attribute.</li>
  1204. </ol>
  1205. </blockquote>
  1206. </td></tr>
  1207. </table>
  1208. </a>
  1209. <a name="include-order">
  1210. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1211. <tr><td bgcolor="#828DA6">
  1212. <font color="#ffffff" face="arial,helvetica,sanserif">
  1213. <strong>
  1214. In my <code>&lt;fileset&gt;</code>, I've put in an
  1215. <code>&lt;exclude&gt;</code> of all files followed by an
  1216. <code>&lt;include&gt;</code> of just the files I want, but it
  1217. isn't giving me any files at all. What's wrong?
  1218. </strong>
  1219. </font>
  1220. </td></tr>
  1221. <tr><td>
  1222. <blockquote>
  1223. <p>The order of the <code>&lt;include&gt;</code> and
  1224. <code>&lt;exclude&gt;</code> tags within a <code>&lt;fileset&gt;</code>
  1225. is ignored when the FileSet is created. Instead, all of the
  1226. <code>&lt;include&gt;</code> elements are processed together,
  1227. followed by all of the <code>&lt;exclude&gt;</code>
  1228. elements. This means that the <code>&lt;exclude&gt;</code>
  1229. elements only apply to the file list produced by the
  1230. <code>&lt;include&gt;</code> elements.</p>
  1231. <p>To get the files you want, focus on just the
  1232. <code>&lt;include&gt;</code> patterns that would be necessary
  1233. to get them. If you find you need to trim the list that the
  1234. <code>&lt;include&gt;</code> elements
  1235. produce, then use <code>&lt;exclude&gt;</code> elements.</p>
  1236. </blockquote>
  1237. </td></tr>
  1238. </table>
  1239. </a>
  1240. <a name="encoding">
  1241. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1242. <tr><td bgcolor="#828DA6">
  1243. <font color="#ffffff" face="arial,helvetica,sanserif">
  1244. <strong>
  1245. How can I include national characters like German
  1246. umlauts in my build file?
  1247. </strong>
  1248. </font>
  1249. </td></tr>
  1250. <tr><td>
  1251. <blockquote>
  1252. <p>You need to tell the XML parser which character encoding
  1253. your build file uses, this is done inside the <a href="http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd">XML
  1254. declaration</a>.</p>
  1255. <p>By default the parser assumes you are using the UTF-8
  1256. encoding instead of your platform's default. For most western
  1257. european contries you should set the encoding to
  1258. <code>ISO-8859-1</code>. To do so, make the very first line
  1259. of you build file read like</p>
  1260. <div align="left">
  1261. <table cellspacing="4" cellpadding="0" border="0">
  1262. <tr>
  1263. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1264. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1265. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1266. </tr>
  1267. <tr>
  1268. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1269. <td bgcolor="#ffffff"><pre>
  1270. &lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?&gt;
  1271. </pre></td>
  1272. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1273. </tr>
  1274. <tr>
  1275. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1276. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1277. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1278. </tr>
  1279. </table>
  1280. </div>
  1281. </blockquote>
  1282. </td></tr>
  1283. </table>
  1284. </a>
  1285. <a name="integration">
  1286. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1287. <tr><td bgcolor="#828DA6">
  1288. <font color="#ffffff" face="arial,helvetica,sanserif">
  1289. <strong>
  1290. Is Ant supported by my IDE/Editor?
  1291. </strong>
  1292. </font>
  1293. </td></tr>
  1294. <tr><td>
  1295. <blockquote>
  1296. <p>See the <a href="external.html#IDE and Editor Integration">section
  1297. on IDE integration</a> on our External Tools and Tasks page.</p>
  1298. </blockquote>
  1299. </td></tr>
  1300. </table>
  1301. </a>
  1302. <a name="emacs-mode">
  1303. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1304. <tr><td bgcolor="#828DA6">
  1305. <font color="#ffffff" face="arial,helvetica,sanserif">
  1306. <strong>
  1307. Why doesn't (X)Emacs/vi/MacOS X's project builder
  1308. correctly parse the error messages generated by Ant?
  1309. </strong>
  1310. </font>
  1311. </td></tr>
  1312. <tr><td>
  1313. <blockquote>
  1314. <p>Ant adds a "banner" with the name of the current
  1315. task in front of all logging messages - and there are no built-in
  1316. regular expressions in your editor that would account for
  1317. this.</p>
  1318. <p>You can disable this banner by invoking Ant with the
  1319. <code>-emacs</code> switch. Alternatively, you can add the
  1320. following snippet to your <code>.emacs</code> to make Emacs
  1321. understand Ant's output.</p>
  1322. <div align="left">
  1323. <table cellspacing="4" cellpadding="0" border="0">
  1324. <tr>
  1325. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1326. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1327. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1328. </tr>
  1329. <tr>
  1330. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1331. <td bgcolor="#ffffff"><pre>
  1332. (require 'compile)
  1333. (setq compilation-error-regexp-alist
  1334. (append (list
  1335. ;; works for jikes
  1336. '(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:&quot; 1 2 3)
  1337. ;; works for javac
  1338. '(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):&quot; 1 2))
  1339. compilation-error-regexp-alist))
  1340. </pre></td>
  1341. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1342. </tr>
  1343. <tr>
  1344. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1345. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1346. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1347. </tr>
  1348. </table>
  1349. </div>
  1350. <p>Yet another alternative that preserves most of Ant's
  1351. formatting is to pipe Ant's output through the following Perl
  1352. script by Dirk-Willem van Gulik:</p>
  1353. <div align="left">
  1354. <table cellspacing="4" cellpadding="0" border="0">
  1355. <tr>
  1356. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1357. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1358. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1359. </tr>
  1360. <tr>
  1361. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1362. <td bgcolor="#ffffff"><pre>
  1363. #!/usr/bin/perl
  1364. #
  1365. # May 2001 dirkx@apache.org - remove any
  1366. # [foo] lines from the output; keeping
  1367. # spacing more or less there.
  1368. #
  1369. $|=1;
  1370. while(&lt;STDIN&gt;) {
  1371. if (s/^(\s+)\[(\w+)\]//) {
  1372. if ($2 ne $last) {
  1373. print &quot;$1\[$2\]&quot;;
  1374. $s = ' ' x length($2);
  1375. } else {
  1376. print &quot;$1 $s &quot;;
  1377. };
  1378. $last = $2;
  1379. };
  1380. print;
  1381. };
  1382. </pre></td>
  1383. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1384. </tr>
  1385. <tr>
  1386. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1387. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1388. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1389. </tr>
  1390. </table>
  1391. </div>
  1392. </blockquote>
  1393. </td></tr>
  1394. </table>
  1395. </a>
  1396. <a name="dtd">
  1397. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1398. <tr><td bgcolor="#828DA6">
  1399. <font color="#ffffff" face="arial,helvetica,sanserif">
  1400. <strong>
  1401. Is there a DTD that I can use to validate my build
  1402. files?
  1403. </strong>
  1404. </font>
  1405. </td></tr>
  1406. <tr><td>
  1407. <blockquote>
  1408. <p>An incomplete DTD can be created by the
  1409. <code>&lt;antstructure&gt;</code> task - but this one
  1410. has a few problems:</p>
  1411. <ul>
  1412. <li>It doesn't know about required attributes. Only
  1413. manual tweaking of this file can help here.</li>
  1414. <li>It is not complete - if you add new tasks via
  1415. <code>&lt;taskdef&gt;</code> it won't know about it. See
  1416. <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this
  1417. page</a> by Michel Casabianca for a solution to this
  1418. problem. Note that the DTD you can download at this page
  1419. is based on Ant 0.3.1.</li>
  1420. <li>It may even be an invalid DTD. As Ant allows tasks
  1421. writers to define arbitrary elements, name collisions will
  1422. happen quite frequently - if your version of Ant contains
  1423. the optional <code>&lt;test&gt;</code> and
  1424. <code>&lt;junit&gt;</code> tasks, there are two XML
  1425. elements named <code>test</code> (the task and the nested child
  1426. element of <code>&lt;junit&gt;</code>) with different attribute
  1427. lists. This problem cannot be solved; DTDs don't give a
  1428. syntax rich enough to support this.</li>
  1429. </ul>
  1430. </blockquote>
  1431. </td></tr>
  1432. </table>
  1433. </a>
  1434. <a name="xml-entity-include">
  1435. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1436. <tr><td bgcolor="#828DA6">
  1437. <font color="#ffffff" face="arial,helvetica,sanserif">
  1438. <strong>
  1439. How do I include an XML snippet in my build file?
  1440. </strong>
  1441. </font>
  1442. </td></tr>
  1443. <tr><td>
  1444. <blockquote>
  1445. <p>You can use XML's way of including external files and let
  1446. the parser do the job for Ant:</p>
  1447. <div align="left">
  1448. <table cellspacing="4" cellpadding="0" border="0">
  1449. <tr>
  1450. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1451. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1452. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1453. </tr>
  1454. <tr>
  1455. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1456. <td bgcolor="#ffffff"><pre>
  1457. &lt;?xml version=&quot;1.0&quot;?&gt;
  1458. &lt;!DOCTYPE project [
  1459. &lt;!ENTITY common SYSTEM &quot;file:./common.xml&quot;&gt;
  1460. ]&gt;
  1461. &lt;project name=&quot;test&quot; default=&quot;test&quot; basedir=&quot;.&quot;&gt;
  1462. &lt;target name=&quot;setup&quot;&gt;
  1463. ...
  1464. &lt;/target&gt;
  1465. &amp;common;
  1466. ...
  1467. &lt;/project&gt;
  1468. </pre></td>
  1469. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1470. </tr>
  1471. <tr>
  1472. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1473. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1474. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1475. </tr>
  1476. </table>
  1477. </div>
  1478. <p>will literally include the contents of <code>common.xml</code> where
  1479. you've placed the <code>&amp;common;</code> entity.</p>
  1480. <p>In combination with a DTD, this would look like this:</p>
  1481. <div align="left">
  1482. <table cellspacing="4" cellpadding="0" border="0">
  1483. <tr>
  1484. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1485. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1486. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1487. </tr>
  1488. <tr>
  1489. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1490. <td bgcolor="#ffffff"><pre>
  1491. &lt;!DOCTYPE project PUBLIC &quot;-//ANT//DTD project//EN&quot; &quot;file:./ant.dtd&quot; [
  1492. &lt;!ENTITY include SYSTEM &quot;file:./header.xml&quot;&gt;
  1493. ]&gt;
  1494. </pre></td>
  1495. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1496. </tr>
  1497. <tr>
  1498. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1499. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1500. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1501. </tr>
  1502. </table>
  1503. </div>
  1504. </blockquote>
  1505. </td></tr>
  1506. </table>
  1507. </a>
  1508. <a name="mail-logger">
  1509. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1510. <tr><td bgcolor="#828DA6">
  1511. <font color="#ffffff" face="arial,helvetica,sanserif">
  1512. <strong>
  1513. How do I send an email with the result of my build
  1514. process?
  1515. </strong>
  1516. </font>
  1517. </td></tr>
  1518. <tr><td>
  1519. <blockquote>
  1520. <p>If you are using a nightly build of Ant 1.5 after
  1521. 2001-12-14, you can use the built-in MailLogger:</p>
  1522. <div align="left">
  1523. <table cellspacing="4" cellpadding="0" border="0">
  1524. <tr>
  1525. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1526. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1527. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1528. </tr>
  1529. <tr>
  1530. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1531. <td bgcolor="#ffffff"><pre>
  1532. ant -logger org.apache.tools.ant.listener.MailLogger
  1533. </pre></td>
  1534. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1535. </tr>
  1536. <tr>
  1537. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1538. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1539. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1540. </tr>
  1541. </table>
  1542. </div>
  1543. <p>See the <a href="http://cvs.apache.org/viewcvs/~checkout~/jakarta-ant/docs/manual/listeners.html?content-type=text/html">Listeners
  1544. &amp; Loggers</a> documentation for details on the properties
  1545. required.</p>
  1546. <p>For older versions of Ant, you can use a custom
  1547. BuildListener that sends out an email
  1548. in the buildFinished() method. Will Glozer
  1549. &lt;will.glozer@jda.com&gt; has written such a listener based
  1550. on <a href="http://java.sun.com/products/javamail/">JavaMail</a>.
  1551. The source is:</p>
  1552. <div align="left">
  1553. <table cellspacing="4" cellpadding="0" border="0">
  1554. <tr>
  1555. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1556. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1557. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1558. </tr>
  1559. <tr>
  1560. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1561. <td bgcolor="#ffffff"><pre>
  1562. import java.io.*;
  1563. import java.util.*;
  1564. import javax.mail.*;
  1565. import javax.mail.internet.*;
  1566. import org.apache.tools.ant.*;
  1567. /**
  1568. * A simple listener that waits for a build to finish and sends an email
  1569. * of the results. The settings are stored in &quot;monitor.properties&quot; and
  1570. * are fairly self explanatory.
  1571. *
  1572. * @author Will Glozer
  1573. * @version 1.05a 09/06/2000
  1574. */
  1575. public class BuildMonitor implements BuildListener {
  1576. protected Properties props;
  1577. /**
  1578. * Create a new BuildMonitor.
  1579. */
  1580. public BuildMonitor() throws Exception {
  1581. props = new Properties();
  1582. InputStream is = getClass().getResourceAsStream(&quot;monitor.properties&quot;);
  1583. props.load(is);
  1584. is.close();
  1585. }
  1586. public void buildStarted(BuildEvent e) {
  1587. }
  1588. /**
  1589. * Determine the status of the build and the actions to follow, now that
  1590. * the build has completed.
  1591. *
  1592. * @param e Event describing the build tatus.
  1593. */
  1594. public void buildFinished(BuildEvent e) {
  1595. Throwable th = e.getException();
  1596. String status = (th != null) ? &quot;failed&quot; : &quot;succeeded&quot;;
  1597. try {
  1598. String key = &quot;build.&quot; + status;
  1599. if (props.getProperty(key + &quot;.notify&quot;).equalsIgnoreCase(&quot;false&quot;)) {
  1600. return;
  1601. }
  1602. Session session = Session.getDefaultInstance(props, null);
  1603. MimeMessage message = new MimeMessage(session);
  1604. message.addRecipients(Message.RecipientType.TO, parseAddresses(
  1605. props.getProperty(key + &quot;.email.to&quot;)));
  1606. message.setSubject(props.getProperty(key + &quot;.email.subject&quot;));
  1607. BufferedReader br = new BufferedReader(new FileReader(
  1608. props.getProperty(&quot;build.log&quot;)));
  1609. StringWriter sw = new StringWriter();
  1610. String line = br.readLine();
  1611. while (line != null) {
  1612. sw.write(line);
  1613. sw.write(&quot;\n&quot;);
  1614. line = br.readLine();
  1615. }
  1616. br.close();
  1617. message.setText(sw.toString(), &quot;UTF-8&quot;);
  1618. sw.close();
  1619. Transport transport = session.getTransport();
  1620. transport.connect();
  1621. transport.send(message);
  1622. transport.close();
  1623. } catch (Exception ex) {
  1624. System.out.println(&quot;BuildMonitor failed to send email!&quot;);
  1625. ex.printStackTrace();
  1626. }
  1627. }
  1628. /**
  1629. * Parse a comma separated list of internet email addresses.
  1630. *
  1631. * @param s The list of addresses.
  1632. * @return Array of Addresses.
  1633. */
  1634. protected Address[] parseAddresses(String s) throws Exception {
  1635. StringTokenizer st = new StringTokenizer(s, &quot;,&quot;);
  1636. Address[] addrs = new Address[st.countTokens()];
  1637. for (int i = 0; i &lt; addrs.length; i++) {
  1638. addrs[i] = new InternetAddress(st.nextToken());
  1639. }
  1640. return addrs;
  1641. }
  1642. public void messageLogged(BuildEvent e) {
  1643. }
  1644. public void targetStarted(BuildEvent e) {
  1645. }
  1646. public void targetFinished(BuildEvent e) {
  1647. }
  1648. public void taskStarted(BuildEvent e) {
  1649. }
  1650. public void taskFinished(BuildEvent e) {
  1651. }
  1652. }
  1653. </pre></td>
  1654. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1655. </tr>
  1656. <tr>
  1657. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1658. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1659. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1660. </tr>
  1661. </table>
  1662. </div>
  1663. <p>With a <code>monitor.properties</code> like this:</p>
  1664. <div align="left">
  1665. <table cellspacing="4" cellpadding="0" border="0">
  1666. <tr>
  1667. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1668. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1669. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1670. </tr>
  1671. <tr>
  1672. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1673. <td bgcolor="#ffffff"><pre>
  1674. # configuration for build monitor
  1675. mail.transport.protocol=smtp
  1676. mail.smtp.host=&lt;host&gt;
  1677. mail.from=Will Glozer &lt;will.glozer@jda.com&gt;
  1678. build.log=build.log
  1679. build.failed.notify=true
  1680. build.failed.email.to=will.glozer@jda.com
  1681. build.failed.email.subject=Nightly build failed!
  1682. build.succeeded.notify=true
  1683. build.succeeded.email.to=will.glozer@jda.com
  1684. build.succeeded.email.subject=Nightly build succeeded!
  1685. </pre></td>
  1686. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1687. </tr>
  1688. <tr>
  1689. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1690. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1691. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1692. </tr>
  1693. </table>
  1694. </div>
  1695. <p><code>monitor.properties</code> should be placed right next
  1696. to your compiled <code>BuildMonitor.class</code>. To use it,
  1697. invoke Ant like:</p>
  1698. <div align="left">
  1699. <table cellspacing="4" cellpadding="0" border="0">
  1700. <tr>
  1701. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1702. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1703. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1704. </tr>
  1705. <tr>
  1706. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1707. <td bgcolor="#ffffff"><pre>
  1708. ant -listener BuildMonitor -logfile build.log
  1709. </pre></td>
  1710. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1711. </tr>
  1712. <tr>
  1713. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1714. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1715. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1716. </tr>
  1717. </table>
  1718. </div>
  1719. <p>Make sure that <code>mail.jar</code> from JavaMail and
  1720. <code>activation.jar</code> from the
  1721. <a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java
  1722. Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p>
  1723. </blockquote>
  1724. </td></tr>
  1725. </table>
  1726. </a>
  1727. <a name="listener-properties">
  1728. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1729. <tr><td bgcolor="#828DA6">
  1730. <font color="#ffffff" face="arial,helvetica,sanserif">
  1731. <strong>
  1732. How do I get at the properties that Ant was running
  1733. with from inside BuildListener?
  1734. </strong>
  1735. </font>
  1736. </td></tr>
  1737. <tr><td>
  1738. <blockquote>
  1739. <p>You can get at a hashtable with all the properties that Ant
  1740. has been using through the BuildEvent parameter. For
  1741. example:</p>
  1742. <div align="left">
  1743. <table cellspacing="4" cellpadding="0" border="0">
  1744. <tr>
  1745. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1746. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1747. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1748. </tr>
  1749. <tr>
  1750. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1751. <td bgcolor="#ffffff"><pre>
  1752. public void buildFinished(BuildEvent e) {
  1753. Hashtable table = e.getProject().getProperties();
  1754. String buildpath = (String)table.get(&quot;build.path&quot;);
  1755. ...
  1756. }
  1757. </pre></td>
  1758. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1759. </tr>
  1760. <tr>
  1761. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1762. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1763. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1764. </tr>
  1765. </table>
  1766. </div>
  1767. <p>This is more accurate than just reading the same property
  1768. files that your project does, since it will give the correct
  1769. results for properties that were specified on the Ant command line.</p>
  1770. </blockquote>
  1771. </td></tr>
  1772. </table>
  1773. </a>
  1774. <a name="remove-cr">
  1775. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1776. <tr><td bgcolor="#828DA6">
  1777. <font color="#ffffff" face="arial,helvetica,sanserif">
  1778. <strong>
  1779. &lt;chmod&gt; or &lt;exec&gt; doesn't work in Ant
  1780. 1.3 on Unix
  1781. </strong>
  1782. </font>
  1783. </td></tr>
  1784. <tr><td>
  1785. <blockquote>
  1786. <p>The <code>antRun</code> script in <code>ANT_HOME/bin</code>
  1787. has DOS instead of Unix line endings; you must remove the
  1788. carriage-return characters from this file. This can be done by
  1789. using Ant's <code>&lt;fixcrlf&gt;</code> task
  1790. or something like:</p>
  1791. <div align="left">
  1792. <table cellspacing="4" cellpadding="0" border="0">
  1793. <tr>
  1794. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1795. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1796. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1797. </tr>
  1798. <tr>
  1799. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1800. <td bgcolor="#ffffff"><pre>
  1801. tr -d '\r' &lt; $ANT_HOME/bin/antRun &gt; /tmp/foo
  1802. mv /tmp/foo $ANT_HOME/bin/antRun
  1803. </pre></td>
  1804. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1805. </tr>
  1806. <tr>
  1807. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1808. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1809. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1810. </tr>
  1811. </table>
  1812. </div>
  1813. </blockquote>
  1814. </td></tr>
  1815. </table>
  1816. </a>
  1817. <a name="javadoc-cannot-execute">
  1818. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1819. <tr><td bgcolor="#828DA6">
  1820. <font color="#ffffff" face="arial,helvetica,sanserif">
  1821. <strong>
  1822. JavaDoc failed: java.io.IOException: javadoc: cannot execute
  1823. </strong>
  1824. </font>
  1825. </td></tr>
  1826. <tr><td>
  1827. <blockquote>
  1828. <p>There is a bug in the Solaris reference implementation of
  1829. the JDK (see <a href="http://developer.java.sun.com/developer/bugParade/bugs/4230399.html">http://developer.java.sun.com/developer/bugParade/bugs/4230399.html</a>).
  1830. This also appears to be true under Linux. Moving the JDK to
  1831. the front of the PATH fixes the problem.</p>
  1832. </blockquote>
  1833. </td></tr>
  1834. </table>
  1835. </a>
  1836. <a name="delegating-classloader">
  1837. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1838. <tr><td bgcolor="#828DA6">
  1839. <font color="#ffffff" face="arial,helvetica,sanserif">
  1840. <strong>
  1841. &lt;style&gt; or &lt;junit&gt; ignores my
  1842. &lt;classpath&gt;
  1843. </strong>
  1844. </font>
  1845. </td></tr>
  1846. <tr><td>
  1847. <blockquote>
  1848. <p>These tasks don't ignore your classpath setting, you
  1849. are facing a common problem with delegating classloaders.</p>
  1850. <p>First of all let's state that Ant adds all
  1851. <code>.jar</code> files from <code>ANT_HOME/lib</code> to
  1852. <code>CLASSPATH</code>, therefore "in
  1853. <code>CLASSPATH</code>" shall mean "either in your
  1854. <code>CLASSPATH</code> environment variable or
  1855. <code>ANT_HOME/lib</code>" for the rest of this
  1856. answer.</p>
  1857. <p>This question collects a common type of problem: A task
  1858. needs an external library and it has a nested classpath
  1859. element so that you can point it to this external library, but
  1860. that doesn't work unless you put the external library into the
  1861. <code>CLASSPATH</code>.</p>
  1862. <p>The root of the problem is that the class that needs the
  1863. external library is on the <code>CLASSPATH</code>.</p>
  1864. <p>When you specify a nested <code>&lt;classpath&gt;</code> in
  1865. Ant, Ant creates a new class loader that uses the path you
  1866. have specified. It then tries to load additional classes from
  1867. this classloader.</p>
  1868. <p>In most cases - for example the two cases above - Ant
  1869. doesn't load the external library directly, it is the loaded
  1870. class that does so.</p>
  1871. <p>In the case of <code>&lt;junit&gt;</code> it is the task
  1872. implementation itself and in the case of
  1873. <code>&lt;style&gt;</code> it is the implementation of the
  1874. <code>org.apache.tools.ant.taskdefs.XSLTLiaison</code>
  1875. class.</p>
  1876. <p>Ant's class loader implementation uses Java's
  1877. delegation model, see <a href="http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html">http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html</a>
  1878. the paragraph</p>
  1879. <blockquote>The <code>ClassLoader</code> class uses a
  1880. delegation model to search for classes and resources. Each
  1881. instance of <code>ClassLoader</code> has an associated parent
  1882. class loader. When called upon to find a class or resource, a
  1883. <code>ClassLoader</code> instance will delegate the search for
  1884. the class or resource to its parent class loader before
  1885. attempting to find the class or resource itself. The virtual
  1886. machine's built-in class loader, called the bootstrap
  1887. class loader, does not itself have a parent but may serve as
  1888. the parent of a <code>ClassLoader</code>
  1889. instance.</blockquote>
  1890. <p>This means, Ant's class loader will consult the
  1891. bootstrap class loader first, which tries to load classes from
  1892. <code>CLASSPATH</code>. The bootstrap class loader
  1893. doesn't know anything about Ant's class loader or
  1894. even the path you have specified.</p>
  1895. <p>If the bootstrap class loader can load the class Ant has
  1896. asked it to load, this class will try to load the external
  1897. library from <code>CLASSPATH</code> as well - it doesn't
  1898. know anything else - and will not find it unless the library
  1899. is in <code>CLASSPATH</code> as well.</p>
  1900. <p>To solve this, you have two major options:</p>
  1901. <ol>
  1902. <li>put all external libaries you need in
  1903. <code>CLASSPATH</code> as well this is not what you want,
  1904. otherwise you wouldn't have found this FAQ entry.</li>
  1905. <li>remove the class that loads the external library from
  1906. the <code>CLASSPATH</code>.</li>
  1907. </ol>
  1908. <p>The easiest way to do this is to remove
  1909. <code>optional.jar</code> from <code>ANT_HOME/lib</code>. If
  1910. you do so, you will have to <code>&lt;taskdef&gt;</code> all
  1911. optional tasks and use nested <code>&lt;classpath&gt;</code>
  1912. elements in the <code>&lt;taskdef&gt;</code> tasks that point
  1913. to the new location of <code>optional.jar</code>. Also,
  1914. don't forget to add the new location of
  1915. <code>optional.jar</code> to the
  1916. <code>&lt;classpath&gt;</code> of your
  1917. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code>
  1918. task.</p>
  1919. <p>If you want to avoid to <code>&lt;taskdef&gt;</code> all
  1920. optional tasks you need, the only other option is to remove
  1921. the classes that should not be loaded via the bootstrap class
  1922. loader from <code>optional.jar</code> and put them into a
  1923. separate archive. Add this separate archive to the
  1924. <code>&lt;classpath&gt;</code> of your
  1925. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code> task
  1926. - and make sure the separate archive is not in
  1927. <code>CLASSPATH</code>.</p>
  1928. <p>In the case of <code>&lt;junit&gt;</code> you'd have
  1929. to remove all classes that are in the
  1930. <code>org/apache/tools/ant/taskdefs/optional/junit</code>
  1931. directory, in the <code>&lt;style&gt;</code> case it is one of
  1932. the <code>*Liaison</code> classes in
  1933. <code>org/apache/tools/ant/taskdefs/optional</code>.</p>
  1934. <p>If you use the option to break up <code>optional.jar</code>
  1935. for <code>&lt;junit&gt;</code>, you still have to use a
  1936. <code>&lt;taskdef&gt;</code> with a nested
  1937. <code>&lt;classpath&gt;</code> to define the junit task.</p>
  1938. </blockquote>
  1939. </td></tr>
  1940. </table>
  1941. </a>
  1942. </blockquote>
  1943. </td></tr>
  1944. </table>
  1945. </td>
  1946. </tr>
  1947. <!-- FOOTER -->
  1948. <tr><td colspan="2">
  1949. <hr noshade="" size="1"/>
  1950. </td></tr>
  1951. <tr><td colspan="2">
  1952. <div align="center"><font color="#525D76" size="-1"><em>
  1953. Copyright &#169; 2000-2002, Apache Software Foundation
  1954. </em></font></div>
  1955. </td></tr>
  1956. </table>
  1957. </body>
  1958. </html>
  1959. <!-- end the processing -->