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

faq.html 81 kB

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