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

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