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

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