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 76 KiB

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