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

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