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

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