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 81 kB

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