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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273
  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. </table>
  718. <p class="faq">
  719. <a name="java-version"></a>
  720. Which version of Java is required to run
  721. Apache Ant?
  722. </p>
  723. <p>You will need Java installed on your system, version 1.4 or
  724. later required, 1.5 or later strongly recommended. The later
  725. the version of Java, the more Ant tasks you get.</p>
  726. <p>If only the JRE is present but not a full JDK then many
  727. tasks will not work.</p>
  728. <p>The following table lists the minimum Java versions
  729. required to compile and run Ant. Note that most committers
  730. work with more recent versions of the JDK and that Ant doesn't
  731. get tested much for older versions.</p>
  732. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  733. <tr>
  734. <th colspan="1" rowspan="1"
  735. valign="top" align="left">
  736. Ant Version
  737. </th>
  738. <th colspan="1" rowspan="1"
  739. valign="top" align="left">
  740. Minimum Java Version
  741. </th>
  742. </tr>
  743. <tr>
  744. <td colspan="1" rowspan="1"
  745. valign="top" align="left">
  746. 1.1 up to 1.5.4
  747. </td>
  748. <td colspan="1" rowspan="1"
  749. valign="top" align="left">
  750. 1.1
  751. </td>
  752. </tr>
  753. <tr>
  754. <td colspan="1" rowspan="1"
  755. valign="top" align="left">
  756. 1.6.0 up to 1.6.5
  757. </td>
  758. <td colspan="1" rowspan="1"
  759. valign="top" align="left">
  760. 1.2
  761. </td>
  762. </tr>
  763. <tr>
  764. <td colspan="1" rowspan="1"
  765. valign="top" align="left">
  766. 1.7.0 up to 1.7.1
  767. </td>
  768. <td colspan="1" rowspan="1"
  769. valign="top" align="left">
  770. 1.3
  771. </td>
  772. </tr>
  773. <tr>
  774. <td colspan="1" rowspan="1"
  775. valign="top" align="left">
  776. 1.8.0 up to current svn trunk
  777. </td>
  778. <td colspan="1" rowspan="1"
  779. valign="top" align="left">
  780. 1.4
  781. </td>
  782. </tr>
  783. </table>
  784. <p class="faq">
  785. <a name="no-gnu-tar"></a>
  786. I get checksum errors when I try to extract the
  787. <code>tar.gz</code> distribution file. Why?
  788. </p>
  789. <p>Ant's distribution contains file names that are longer
  790. than 100 characters, which is not supported by the standard
  791. tar file format. Several different implementations of tar use
  792. different and incompatible ways to work around this
  793. restriction.</p>
  794. <p>Ant's &lt;tar&gt; task can create tar archives that use
  795. the GNU tar extension, and this has been used when putting
  796. together the distribution. If you are using a different
  797. version of tar (for example, the one shipping with Solaris),
  798. you cannot use it to extract the archive.</p>
  799. <p>The solution is to either install GNU tar, which can be
  800. found <a href="http://www.gnu.org/software/tar/tar.html">here</a>,
  801. or use the zip archive instead (you can extract it using
  802. <code>jar xf</code>).</p>
  803. <p class="faq">
  804. <a name="RedHat_ES_3"></a>
  805. How do you get ant-1.6.x (or any version later than
  806. 1.5.2) to work on on RedHat ES 3?
  807. </p>
  808. <p>Redhat ES 3.0 comes installed with ant 1.5.2. Even if you
  809. have your PATH and ANT_HOME variables set correctly to a later
  810. version of ant, you will always be forced to use the
  811. preinstalled version.</p>
  812. <p>To use a later version of ant on this OS you could do the
  813. following:</p>
  814. <pre class="code">
  815. $ ant -version
  816. Apache Ant version 1.5.2-23 compiled on November 12 2003
  817. $ su -
  818. # rpm -e ant ant-libs
  819. # exit
  820. $ hash -r
  821. $ ant -version
  822. Apache Ant version 1.6.2 compiled on July 16 2004
  823. </pre>
  824. <p class="faq">
  825. <a name="precompile-jsps"></a>
  826. How to I precompile Java Server Pages (JSPs)?
  827. </p>
  828. <p>Apache Ant has a built in optional task <a href="/manual/Tasks/jspc.html">&lt;jspc&gt;</a>
  829. which was intended for that. <b>But this task is deprecated.</b>
  830. Here the alternative suggested by the manual:</p>
  831. <p><i>Instead of relying on container specific JSP-compilers we suggest deploying
  832. the raw files (*.jsp) and use the container build-in functions: after deploying
  833. run a test suite (e.g. with
  834. <a href="http://jakarta.apache.org/cactus/">Cactus</a> or
  835. <a href="http://httpunit.sourceforge.net/">HttpUnit</a>) against the deployed web
  836. application. So you'll get then test result and the compiled JSPs.</i></p>
  837. <p class="faq">
  838. <a name="implement-os-specific-configuration"></a>
  839. How do I realize os--specific configurations?
  840. </p>
  841. <p>The core idea is using property files which name accords to the
  842. os-name. Then simply use the build-in property <tt>os.name</tt>.</p>
  843. <p>For better use you should also provide a file with default values.
  844. But be careful with the correct os-names. For test simply &lt;echo&gt;
  845. the ${os.name} on all machines and you can be sure to use the right
  846. file names.</p>
  847. <pre class="code">
  848. &lt;property file=&quot;${os.name}.properties&quot;/&gt;
  849. &lt;property file=&quot;default.properties&quot;/&gt;
  850. </pre>
  851. <p class="faq">
  852. <a name="adding-external-tasks"></a>
  853. How do I add an external task that I've written to the
  854. page "External Tools and Tasks"?
  855. </p>
  856. <p>Join and post a message to the dev or user mailing
  857. list (one list is enough), including the following
  858. information:</p>
  859. <ul>
  860. <li>the name of the task/tool</li>
  861. <li>a short description of the task/tool</li>
  862. <li>a Compatibility: entry stating with which version(s) of
  863. Ant the tool/task is compatible to</li>
  864. <li>a URL: entry linking to the main page of the tool/task</li>
  865. <li>a Contact: entry containing the email address or the URL
  866. of a webpage for the person or list to contact for issues
  867. related to the tool/task. <strong>Note that we'll add a
  868. link on the page, so any email address added there is not
  869. obfuscated and can (and probably will) be abused by robots
  870. harvesting websites for addresses to spam.</strong></li>
  871. <li>a License: entry containing the type of license for the
  872. tool/task</li>
  873. </ul>
  874. <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>
  875. document.</p>
  876. <p>If you have written something bigger than a 'simple plugin' to Ant it
  877. may be better to add the link to <a href="projects.html">projects.html</a>.
  878. 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>
  879. document. The syntax of that file is the same.</p>
  880. <p class="faq">
  881. <a name="create-extensions"></a>
  882. How do I create new tasks?
  883. </p>
  884. <p>Apart from a lot of information on using Ant, the
  885. <a href="manual/index.html">Manual</a> also contains information
  886. on how to extend Ant with new tasks. This information
  887. can be found under "Developing with Ant".</p>
  888. <p>Chances are that someone else already created the task you
  889. want to create, it may be wise to see
  890. <a href="external.html">External Tools and Tasks</a> and
  891. <a href="projects.html">Related Projects</a> first.</p>
  892. <p class="faq">
  893. <a name="passing-cli-args"></a>
  894. How do I pass parameters from the command line to my
  895. build file?
  896. </p>
  897. <p>Use properties. Using <code>ant
  898. -D<em>name</em>=<em>value</em></code> lets you define values for
  899. properties on the Ant command line. These properties can then be
  900. used within your build file as
  901. any normal property: <code>${<em>name</em>}</code> will put in
  902. <code><em>value</em></code>.</p>
  903. <p class="faq">
  904. <a name="jikes-switches"></a>
  905. How can I use Jikes-specific command-line
  906. switches?
  907. </p>
  908. <p>A couple of switches are supported via "magic"
  909. properties:</p>
  910. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  911. <tr>
  912. <th colspan="1" rowspan="1"
  913. valign="top" align="left">
  914. switch
  915. </th>
  916. <th colspan="1" rowspan="1"
  917. valign="top" align="left">
  918. property
  919. </th>
  920. <th colspan="1" rowspan="1"
  921. valign="top" align="left">
  922. default
  923. </th>
  924. </tr>
  925. <tr>
  926. <td colspan="1" rowspan="1"
  927. valign="top" align="left">
  928. +E
  929. </td>
  930. <td colspan="1" rowspan="1"
  931. valign="top" align="left">
  932. build.compiler.emacs
  933. </td>
  934. <td colspan="1" rowspan="1"
  935. valign="top" align="left">
  936. false == not set
  937. </td>
  938. </tr>
  939. <tr>
  940. <td colspan="1" rowspan="1"
  941. valign="top" align="left">
  942. +P
  943. </td>
  944. <td colspan="1" rowspan="1"
  945. valign="top" align="left">
  946. build.compiler.pedantic
  947. </td>
  948. <td colspan="1" rowspan="1"
  949. valign="top" align="left">
  950. false == not set
  951. </td>
  952. </tr>
  953. <tr>
  954. <td colspan="1" rowspan="1"
  955. valign="top" align="left">
  956. +F
  957. </td>
  958. <td colspan="1" rowspan="1"
  959. valign="top" align="left">
  960. build.compiler.fulldepend
  961. </td>
  962. <td colspan="1" rowspan="1"
  963. valign="top" align="left">
  964. false == not set
  965. </td>
  966. </tr>
  967. <tr>
  968. <td colspan="1" rowspan="1"
  969. valign="top" align="left">
  970. <strong>(Only for Ant &lt; 1.4; replaced by the
  971. <code><strong>nowarn</strong></code>
  972. attribute of the <code><strong>&lt;javac&gt;</strong></code>
  973. task after that.)</strong><br />-nowarn
  974. </td>
  975. <td colspan="1" rowspan="1"
  976. valign="top" align="left">
  977. build.compiler.warnings
  978. </td>
  979. <td colspan="1" rowspan="1"
  980. valign="top" align="left">
  981. true == not set
  982. </td>
  983. </tr>
  984. </table>
  985. <p>With Ant &gt;= 1.5, you can also use nested
  986. <code>&lt;compilerarg&gt;</code> elements with the
  987. <code>&lt;javac&gt;</code> task.</p>
  988. <p class="faq">
  989. <a name="shell-redirect-1"></a>
  990. How do I include a &lt; character in my command-line arguments?
  991. </p>
  992. <p>The short answer is "Use: <code>&amp;lt;</code>".</p>
  993. <p>The long answer is that this probably won't do what you
  994. want anyway (see <a href="#shell-redirect-2">the next
  995. section</a>).</p>
  996. <p class="faq">
  997. <a name="shell-redirect-2"></a>
  998. How do I redirect standard input or standard output
  999. in the <code>&lt;exec&gt;</code> task?
  1000. </p>
  1001. <p>Say you want to redirect the standard output stream of the
  1002. <code>m4</code> command to write to a file, something
  1003. like:</p>
  1004. <pre class="code">
  1005. shell-prompt&gt; m4 foo.m4 &gt; foo
  1006. </pre>
  1007. <p>and try to translate it into</p>
  1008. <pre class="code">
  1009. &lt;exec executable=&quot;m4&quot;&gt;
  1010. &lt;arg value=&quot;foo.m4&quot;/&gt;
  1011. &lt;arg value=&quot;&amp;gt;&quot;/&gt;
  1012. &lt;arg value=&quot;foo&quot;/&gt;
  1013. &lt;/exec&gt;
  1014. </pre>
  1015. <p>This will not do what you expect. The output redirection is
  1016. performed by your shell, not the command itself, so this
  1017. should read:</p>
  1018. <pre class="code">
  1019. &lt;exec executable=&quot;/bin/sh&quot;&gt;
  1020. &lt;arg value=&quot;-c&quot; /&gt;
  1021. &lt;arg value=&quot;m4 foo.m4 &amp;gt; foo&quot; /&gt;
  1022. &lt;/exec&gt;
  1023. </pre>
  1024. <p>Note that you must use the <code>value</code> attribute of
  1025. <code>&lt;arg&gt;</code> in the last element, in order to have
  1026. the command passed as a single, quoted argument. Alternatively,
  1027. you can use:</p>
  1028. <pre class="code">
  1029. &lt;exec executable=&quot;/bin/sh&quot;&gt;
  1030. &lt;arg line='-c &quot;m4 foo.m4 &amp;gt; foo&quot;'/&gt;
  1031. &lt;/exec&gt;
  1032. </pre>
  1033. <p>Note the double-quotes nested inside the single-quotes.</p>
  1034. <p class="faq">
  1035. <a name="batch-shell-execute"></a>
  1036. How do I execute a batch file or shell script from Ant?
  1037. </p>
  1038. <p>On native Unix systems, you should be able to run shell scripts
  1039. directly. On systems running a Unix-type shell (for example, Cygwin
  1040. on Windows) execute the (command) shell instead - <code>cmd</code>
  1041. for batch files, <code>sh</code> for shell scripts - then pass the
  1042. batch file or shell script (plus any arguments to the script)
  1043. as a single command, using the <code>/c</code> or
  1044. <code>-c</code> switch, respectively. See
  1045. <a href="#shell-redirect-2">the above section</a>
  1046. for example <code>&lt;exec&gt;</code> tasks
  1047. executing <code>sh</code>. For batch files, use something like:</p>
  1048. <pre class="code">
  1049. &lt;exec dir=&quot;.&quot; executable=&quot;cmd&quot; os=&quot;Windows NT&quot;&gt;
  1050. &lt;arg line=&quot;/c test.bat&quot;/&gt;
  1051. &lt;/exec&gt;
  1052. </pre>
  1053. <p class="faq">
  1054. <a name="multi-conditions"></a>
  1055. I want to execute a particular target only if
  1056. multiple conditions are true.
  1057. </p>
  1058. <p>There are actually several answers to this question.</p>
  1059. <p>If you have only one set and one unset property to test,
  1060. you can specify both an <code>if</code> and an <code>unless</code>
  1061. attribute for the target, and they will act as if they
  1062. are "anded" together.</p>
  1063. <p>If you are using a version of Ant 1.3 or earlier, the
  1064. way to work with all other cases is to chain targets together
  1065. to determine the specific state you want to test for.</p>
  1066. <p>To see how this works, assume you have three properties:
  1067. <code>prop1</code>, <code>prop2</code>, and <code>prop3</code>.
  1068. You want to test that <code>prop1</code> and <code>prop2</code>
  1069. are set, and that <code>prop3</code> is not. If the condition
  1070. holds true you want to echo "yes".</p>
  1071. <p>Here is the implementation in Ant 1.3 and earlier:</p>
  1072. <pre class="code">
  1073. &lt;target name=&quot;cond&quot; depends=&quot;cond-if&quot;/&gt;
  1074. &lt;target name=&quot;cond-if&quot; if=&quot;prop1&quot;&gt;
  1075. &lt;antcall target=&quot;cond-if-2&quot;/&gt;
  1076. &lt;/target&gt;
  1077. &lt;target name=&quot;cond-if-2&quot; if=&quot;prop2&quot;&gt;
  1078. &lt;antcall target=&quot;cond-if-3&quot;/&gt;
  1079. &lt;/target&gt;
  1080. &lt;target name=&quot;cond-if-3&quot; unless=&quot;prop3&quot;&gt;
  1081. &lt;echo message=&quot;yes&quot;/&gt;
  1082. &lt;/target&gt;
  1083. </pre>
  1084. <p>Note: <code>&lt;antcall&gt;</code> tasks do <em>not</em> pass
  1085. property changes back up to the environment they were called
  1086. from, so you wouldn't be able to, for example, set a
  1087. <code>result</code> property in the <code>cond-if-3</code> target,
  1088. then do
  1089. <code>&lt;echo message="result is ${result}"/&gt;</code>
  1090. in the <code>cond</code> target.</p>
  1091. <p>Starting with Ant 1.4, you can use the
  1092. <code>&lt;condition&gt;</code> task.</p>
  1093. <pre class="code">
  1094. &lt;target name=&quot;cond&quot; depends=&quot;cond-if,cond-else&quot;/&gt;
  1095. &lt;target name=&quot;check-cond&quot;&gt;
  1096. &lt;condition property=&quot;cond-is-true&quot;&gt;
  1097. &lt;and&gt;
  1098. &lt;not&gt;
  1099. &lt;equals arg1=&quot;${prop1}&quot; arg2=&quot;$${prop1}&quot; /&gt;
  1100. &lt;/not&gt;
  1101. &lt;not&gt;
  1102. &lt;equals arg1=&quot;${prop2}&quot; arg2=&quot;$${prop2}&quot; /&gt;
  1103. &lt;/not&gt;
  1104. &lt;equals arg1=&quot;${prop3}&quot; arg2=&quot;$${prop3}&quot; /&gt;
  1105. &lt;/and&gt;
  1106. &lt;/condition&gt;
  1107. &lt;/target&gt;
  1108. &lt;target name=&quot;cond-if&quot; depends=&quot;check-cond&quot; if=&quot;cond-is-true&quot;&gt;
  1109. &lt;echo message=&quot;yes&quot;/&gt;
  1110. &lt;/target&gt;
  1111. &lt;target name=&quot;cond-else&quot; depends=&quot;check-cond&quot; unless=&quot;cond-is-true&quot;&gt;
  1112. &lt;echo message=&quot;no&quot;/&gt;
  1113. &lt;/target&gt;
  1114. </pre>
  1115. <p>This version takes advantage of two things:</p>
  1116. <ul>
  1117. <li>If a property <code>a</code> has not been set,
  1118. <code>${a}</code> will evaluate to <code>${a}</code>.</li>
  1119. <li>To get a literal <code>$</code> in Ant, you have to
  1120. escape it with another <code>$</code> - this will also break
  1121. the special treatment of the <code>${</code> sequence.</li>
  1122. </ul>
  1123. <p>Because testing for a literal <code>${property}</code> string
  1124. isn't all that readable or easy to understand,
  1125. post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element
  1126. to the <code>&lt;condition&gt;</code> task.</p>
  1127. <p>Here is the previous example done using
  1128. <code>&lt;isset&gt;</code>:</p>
  1129. <pre class="code">
  1130. &lt;target name=&quot;check-cond&quot;&gt;
  1131. &lt;condition property=&quot;cond-is-true&quot;&gt;
  1132. &lt;and&gt;
  1133. &lt;isset property=&quot;prop1&quot;/&gt;
  1134. &lt;isset property=&quot;prop2&quot;/&gt;
  1135. &lt;not&gt;
  1136. &lt;isset property=&quot;prop3&quot;/&gt;
  1137. &lt;/not&gt;
  1138. &lt;/and&gt;
  1139. &lt;/condition&gt;
  1140. &lt;/target&gt;
  1141. </pre>
  1142. <p>The last option is to use a scripting language to set the
  1143. properties. This can be particularly handy when you need much
  1144. finer control than the simple conditions shown here but, of
  1145. course, comes with the overhead of adding JAR files to support
  1146. the language, to say nothing of the added maintenance in requiring
  1147. two languages to implement a single system. See the
  1148. <a href="manual/Tasks/script.html">
  1149. <code>&lt;script&gt;</code> task documentation</a> for more
  1150. details.</p>
  1151. <p class="faq">
  1152. <a name="encoding"></a>
  1153. How can I include national characters like German
  1154. umlauts in my build file?
  1155. </p>
  1156. <p>You need to tell the XML parser which character encoding
  1157. your build file uses, this is done inside the <a href="http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd">XML
  1158. declaration</a>.</p>
  1159. <p>By default the parser assumes you are using the UTF-8
  1160. encoding instead of your platform's default. For most Western
  1161. European countries you should set the encoding to
  1162. <code>ISO-8859-1</code>. To do so, make the very first line
  1163. of you build file read like</p>
  1164. <pre class="code">
  1165. &lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?&gt;
  1166. </pre>
  1167. <p class="faq">
  1168. <a name="use-zip-instead-of-jar"></a>
  1169. How do I use <code>jar</code>'s <code>M</code> switch?
  1170. I don't want a MANIFEST.
  1171. </p>
  1172. <p>A JAR archive is a ZIP file, so if you don't want a
  1173. MANIFEST you can simply use <code>&lt;zip&gt;</code>.</p>
  1174. <p>If your file names contain national characters you should
  1175. know that Sun's <code>jar</code> utility like Ant's
  1176. <code>&lt;jar&gt;</code> uses UTF-8 to encode their names while
  1177. <code>&lt;zip&gt;</code> uses your platforms default encoding.
  1178. Use the encoding attribute of <code>&lt;zip&gt;</code> if
  1179. necessary.</p>
  1180. <p class="faq">
  1181. <a name="propertyvalue-as-name-for-property"></a>
  1182. How can I do something like <code>&lt;property name="prop"
  1183. value="${${anotherprop}}"/&gt;</code> (double expanding the property)?
  1184. </p>
  1185. <p>Without any external help you can not.</p>
  1186. <p>With &lt;script/&gt;, which needs external libraries, you can do</p>
  1187. <pre class="code">
  1188. &lt;script language=&quot;javascript&quot;&gt;
  1189. propname = project.getProperty(&quot;anotherprop&quot;);
  1190. project.setNewProperty(&quot;prop&quot;, propname);
  1191. &lt;/script&gt;
  1192. </pre>
  1193. <p>With AntContrib (external task library) you can do <code>
  1194. &lt;propertycopy name="prop" from="${anotherprop}"/&gt;</code>.</p>
  1195. <p>With Ant 1.6 you can simulate the AntContribs &lt;propertycopy&gt;
  1196. and avoid the need of an external library:</p>
  1197. <pre class="code">
  1198. &lt;macrodef name=&quot;propertycopy&quot;&gt;
  1199. &lt;attribute name=&quot;name&quot;/&gt;
  1200. &lt;attribute name=&quot;from&quot;/&gt;
  1201. &lt;sequential&gt;
  1202. &lt;property name=&quot;@{name}&quot; value=&quot;${@{from}}&quot;/&gt;
  1203. &lt;/sequential&gt;
  1204. &lt;/macrodef&gt;
  1205. </pre>
  1206. <p>With the 'props' antlib (external, but also from Ant) you could
  1207. do the dereferencing with <code>${${anotherprop}</code> - not just
  1208. in the property task - instead everywhere in your buildfile (after
  1209. registering the required property helper).</p>
  1210. <pre class="code">
  1211. &lt;propertyhelper&gt;
  1212. &lt;props:nested /&gt;
  1213. &lt;/propertyhelper&gt;
  1214. &lt;property name=&quot;foo&quot; value=&quot;foo.value&quot; /&gt;
  1215. &lt;property name=&quot;var&quot; value=&quot;foo&quot; /&gt;
  1216. &lt;echo&gt; ${${var}} = foo.value &lt;/echo&gt;</pre>
  1217. <p class="faq">
  1218. <a name="delete-directory-children-only"></a>
  1219. How can I delete everything beneath a particular directory,
  1220. preserving the directory itself?
  1221. </p>
  1222. <p>Most users who go down this path have no problem figuring out that
  1223. <code>&lt;delete includeemptydirs="true" /&gt;</code> will help them. The
  1224. seemingly tricky part is preserving the base directory itself,
  1225. which Ant includes in the directory scan. Fortunately the answer is simple:
  1226. </p>
  1227. <pre class="code">
  1228. &lt;delete includeemptydirs=&quot;true&quot;&gt;
  1229. &lt;fileset dir=&quot;dirtokeep&quot; includes=&quot;**/*&quot; /&gt;
  1230. &lt;/delete&gt;
  1231. </pre>
  1232. <p class="faq">
  1233. <a name="delete-directory-only-if-empty"></a>
  1234. How can I delete a particular directory,
  1235. if and only if it is empty?
  1236. </p>
  1237. <p>Most users who go down this path have no problem figuring
  1238. out that
  1239. <code>&lt;delete includeemptydirs="true" /&gt;</code> will
  1240. help them. The seemingly tricky part is preserving the
  1241. non-empty directories, which Ant includes in the directory
  1242. scan. Fortunately the answer is simple:</p>
  1243. <pre class="code">
  1244. &lt;delete includeemptydirs=&quot;true&quot;&gt;
  1245. &lt;fileset dir=&quot;dirtokeepifnotempty&quot; excludes=&quot;**/*&quot; /&gt;
  1246. &lt;/delete&gt;
  1247. </pre>
  1248. <p class="faq">
  1249. <a name="general-advice"></a>
  1250. General Advice
  1251. </p>
  1252. <p>There are many reasons why Apache Ant doesn't behave as
  1253. expected, not all of them are due to Ant bugs. See our <a href="problems.html">Having Problems?</a> page for hints that
  1254. may help pinning down the reasons for your problem.</p>
  1255. <p class="faq">
  1256. <a name="always-recompiles"></a>
  1257. Why does Ant always recompile all my Java files?
  1258. </p>
  1259. <p>In order to find out which files should be compiled, Ant
  1260. compares the timestamps of the source files to those of the
  1261. resulting <code>.class</code> files. Opening all source files
  1262. to find out which package they belong to would be very
  1263. inefficient. Instead, Ant expects you to place your
  1264. source files in a directory hierarchy that mirrors your
  1265. package hierarchy and to point Ant to the root of this
  1266. directory tree with the <code>srcdir</code> attribute.</p>
  1267. <p>Say you have <code>&lt;javac srcdir="src"
  1268. destdir="dest"/&gt;</code>. If Ant finds a file
  1269. <code>src/a/b/C.java</code>, it expects it to be in package
  1270. <code>a.b</code> so that the resulting <code>.class</code>
  1271. file is going to be <code>dest/a/b/C.class</code>.</p>
  1272. <p>If your source-tree directory structure does not match your
  1273. package structure, Ant's heuristic won't work, and
  1274. it will recompile classes that are up-to-date. Ant is not the
  1275. only tool that expects a source-tree layout like this.</p>
  1276. <p>If you have Java source files that aren't declared to
  1277. be part of any package, you can still use the <code>&lt;javac&gt;</code>
  1278. task to compile these files correctly - just set the
  1279. <code>srcdir</code> and <code>destdir</code> attributes to
  1280. the actual directory the source
  1281. files live in and the directory the class files should go into,
  1282. respectively.</p>
  1283. <p class="faq">
  1284. <a name="defaultexcludes"></a>
  1285. I've used a <code>&lt;delete&gt;</code> task to
  1286. delete unwanted SourceSafe control files (CVS files, editor
  1287. backup files, etc.), but it doesn't seem to work; the files
  1288. never get deleted. What's wrong?
  1289. </p>
  1290. <p>This is probably happening because, by default, Ant excludes
  1291. SourceSafe control files (<code>vssver.scc</code>) and certain other
  1292. files from FileSets.</p>
  1293. <p>Here's what you probably did:</p>
  1294. <pre class="code">
  1295. &lt;delete&gt;
  1296. &lt;fileset dir=&quot;${build.src}&quot; includes=&quot;**/vssver.scc&quot;/&gt;
  1297. &lt;/delete&gt;
  1298. </pre>
  1299. <p>You need to switch off the default exclusions,
  1300. and it will work:</p>
  1301. <pre class="code">
  1302. &lt;delete&gt;
  1303. &lt;fileset dir=&quot;${build.src}&quot; includes=&quot;**/vssver.scc&quot;
  1304. defaultexcludes=&quot;no&quot;/&gt;
  1305. &lt;/delete&gt;
  1306. </pre>
  1307. <p>For a complete listing of the patterns that are excluded
  1308. by default, see <a href="manual/dirtasks.html#defaultexcludes">the user
  1309. manual</a>.</p>
  1310. <p class="faq">
  1311. <a name="stop-dependency"></a>
  1312. I have a target I want to skip if a property is set,
  1313. so I have <code>unless="property"</code> as an attribute
  1314. of the target, but all the targets this target
  1315. depends on are still executed. Why?
  1316. </p>
  1317. <p>The list of dependencies is generated by Ant before any of the
  1318. targets are run. This allows dependent targets, such as an
  1319. <code>init</code> target, to set properties that can control the
  1320. execution of the targets higher in the dependency graph. This
  1321. is a good thing.</p>
  1322. <p>However, when your dependencies break down the
  1323. higher-level task
  1324. into several smaller steps, this behaviour becomes
  1325. counter-intuitive. There are a couple of solutions available:
  1326. </p>
  1327. <ol>
  1328. <li>Put the same condition on each of the dependent targets.</li>
  1329. <li>Execute the steps using <code>&lt;antcall&gt;</code>,
  1330. instead of specifying them inside the <code>depends</code>
  1331. attribute.</li>
  1332. </ol>
  1333. <p class="faq">
  1334. <a name="include-order"></a>
  1335. In my <code>&lt;fileset&gt;</code>, I've put in an
  1336. <code>&lt;exclude&gt;</code> of all files followed by an
  1337. <code>&lt;include&gt;</code> of just the files I want, but it
  1338. isn't giving me any files at all. What's wrong?
  1339. </p>
  1340. <p>The order of the <code>&lt;include&gt;</code> and
  1341. <code>&lt;exclude&gt;</code> tags within a <code>&lt;fileset&gt;</code>
  1342. is ignored when the FileSet is created. Instead, all of the
  1343. <code>&lt;include&gt;</code> elements are processed together,
  1344. followed by all of the <code>&lt;exclude&gt;</code>
  1345. elements. This means that the <code>&lt;exclude&gt;</code>
  1346. elements only apply to the file list produced by the
  1347. <code>&lt;include&gt;</code> elements.</p>
  1348. <p>To get the files you want, focus on just the
  1349. <code>&lt;include&gt;</code> patterns that would be necessary
  1350. to get them. If you find you need to trim the list that the
  1351. <code>&lt;include&gt;</code> elements produce, then use
  1352. <code>&lt;exclude&gt;</code> elements.</p>
  1353. <p class="faq">
  1354. <a name="properties-not-trimmed"></a>
  1355. <code>ant</code> failed to build my program via javac
  1356. even when I put the needed jars in an external
  1357. <code>build.properties</code> file and reference them by
  1358. <code>pathelement</code> or <code>classpath refid</code>.
  1359. </p>
  1360. <p>When <code>ant</code> loads properties from an external
  1361. file it doesn't touch the value of properties, trailing blanks
  1362. will not be trimmed for example.</p>
  1363. <p>If the value represents a file path, like a jar needed to
  1364. compile, the task which requires the value, javac for example
  1365. would fail to compile since it can't find the file due to
  1366. trailing spaces.</p>
  1367. <p class="faq">
  1368. <a name="winzip-lies"></a>
  1369. Ant creates WAR files with a lower-case
  1370. <code>web-inf</code> or JAR files with a lower-case
  1371. <code>meta-inf</code> directory.
  1372. </p>
  1373. <p>No it doesn't.</p>
  1374. <p>You may have seen these lower-case directory names in
  1375. WinZIP, but WinZIP is trying to be helpful (and fails). If
  1376. WinZIP encounters a filename that is all upper-case, it
  1377. assumes it has come from an old DOS box and changes the case to
  1378. all lower-case for you.</p>
  1379. <p>If you extract (or just check) the archive with jar, you
  1380. will see that the names have the correct case.</p>
  1381. <p>With WinZIP (version 8.1 at least), this can be corrected in the
  1382. configuration. In the Options/Configuration menu, in the View tab, General
  1383. section, check the "Allow all upper case files names" box. The META-INF and
  1384. WEB-INF will look correct.</p>
  1385. <p class="faq">
  1386. <a name="NoClassDefFoundError"></a>
  1387. I installed Ant 1.6.x and now get
  1388. <code>Exception in thread "main" java.lang.NoClassDefFoundError:
  1389. </code>
  1390. </p>
  1391. <p>
  1392. The cause of this is that there is an old version of ant somewhere in the
  1393. class path or configuration.
  1394. </p>
  1395. <p>
  1396. A version of this problem happens with jars that are in the classpath
  1397. that include an embedded copy of ant classes.
  1398. An example of this is some copies of weblogic.jar.
  1399. </p>
  1400. <p>
  1401. One can check if this is the case by doing (on unix/sh):
  1402. <code><pre>
  1403. unset CLASSPATH
  1404. ant -version
  1405. </pre>
  1406. </code>
  1407. </p>
  1408. <p class="faq">
  1409. <a name="InstantiationException"></a>
  1410. I installed Ant 1.6.x and now get
  1411. <code>java.lang.InstantiationException: org.apache.tools.ant.Main</code>
  1412. </p>
  1413. <p>
  1414. The cause of this is that there is an old version of ant somewhere in the
  1415. class path or configuration.
  1416. </p>
  1417. <p>
  1418. A version of this problem may be seen on some linux systems.
  1419. Some linux systems (Fedora Core 2 for example), comes with a version
  1420. of ant pre-installed. There is a configuration file called
  1421. <code>/etc/ant.conf</code> which if present, the ant shell
  1422. script will 'dot' include. On Fedora Core 2, the /etc/ant.conf
  1423. file resets the <code>ANT_HOME</code> environment variable to
  1424. <code>/usr/share/ant</code>. This causes the problem that
  1425. an old version of ant (1.5.x in this cause) will be used
  1426. with a new version of the ant script file.
  1427. </p>
  1428. <p>
  1429. One can check if this is the case by doing
  1430. <code>ant --noconfig -version</code>.
  1431. </p>
  1432. <p class="faq">
  1433. <a name="mangled-manifest"></a>
  1434. Whenever I use the Ant jar or manifest related tasks, long lines in
  1435. my manifest are wrapped at 70 characters and the resulting jar does
  1436. not work in my application server. Why does Ant do this?
  1437. </p>
  1438. <p>
  1439. Ant implements the Java
  1440. <a href="http://download.oracle.com/javase/1.4.2/docs/guide/jar/jar.html">Jar
  1441. file specification</a>. Please refer to the notes section where it
  1442. discusses the maximum allowable length of a line and the concept of
  1443. continuation characters.
  1444. </p>
  1445. <p>
  1446. If a jar file produced by Ant does not work in your appserver, and
  1447. that failure is due to the wrapped manifest, then you need
  1448. to consult your appserver provider, as it is a bug in their
  1449. appserver. Far more likely, however, is a problem in your
  1450. specification of your classpath. It is not Ant's wrapping of your
  1451. classpath that is the problem.
  1452. </p>
  1453. <p>
  1454. Do not raise a bug about this issue until you have checked to ensure
  1455. that the problem is not due to your classpath specification.
  1456. </p>
  1457. <p class="faq">
  1458. <a name="CreateProcess_error_2"></a>
  1459. <code>&lt;exec&gt;</code> fails with <code>"Cannot run
  1460. program "...":CreateProcess error=2"</code> on
  1461. Windows.
  1462. </p>
  1463. <p>A common problem is not having the executable on the
  1464. PATH. In case you get an error message <code>Cannot run
  1465. program "...":CreateProcess error=2. The system cannot find
  1466. the path specified.</code> have a look at your PATH
  1467. variable.</p>
  1468. <p>Just type the command directly on the command line and if
  1469. Windows finds it, Ant should do it too. (Otherwise ask on
  1470. the user mailinglist for help.) If Windows can not execute
  1471. the program add the directory of the programm to the PATH
  1472. (<code>set PATH=%PATH%;dirOfProgram</code>) or specify the
  1473. absolute path in the <code>executable</code> attribute in
  1474. your buildfile.</p>
  1475. <p class="faq">
  1476. <a name="integration"></a>
  1477. Is Apache Ant supported by my IDE/Editor?
  1478. </p>
  1479. <p>See the <a href="external.html#IDE and Editor Integration">section
  1480. on IDE integration</a> on our External Tools and Tasks page.</p>
  1481. <p class="faq">
  1482. <a name="emacs-mode"></a>
  1483. Why doesn't (X)Emacs/vi/MacOS X's project builder
  1484. correctly parse the error messages generated by Ant?
  1485. </p>
  1486. <p>Ant adds a "banner" with the name of the current
  1487. task in front of all logging messages - and there are no built-in
  1488. regular expressions in your editor that would account for
  1489. this.</p>
  1490. <p>You can disable this banner by invoking Ant with the
  1491. <code>-emacs</code> switch. To make Ant autodetect
  1492. Emacs' compile mode, put this into your
  1493. <code>.antrc</code> (contributed by Ville Skytt�).</p>
  1494. <pre class="code">
  1495. # Detect (X)Emacs compile mode
  1496. if [ &quot;$EMACS&quot; = &quot;t&quot; ] ; then
  1497. ANT_ARGS=&quot;$ANT_ARGS -emacs&quot;
  1498. ANT_OPTS=&quot;$ANT_OPTS -Dbuild.compiler.emacs=true&quot;
  1499. fi
  1500. </pre>
  1501. <p>Alternatively, you can add the following snippet to your
  1502. <code>.emacs</code> to make Emacs understand Ant's
  1503. output.</p>
  1504. <pre class="code">
  1505. (require 'compile)
  1506. (setq compilation-error-regexp-alist
  1507. (append (list
  1508. ;; works for jikes
  1509. '(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:&quot; 1 2 3)
  1510. ;; works for javac
  1511. '(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):&quot; 1 2))
  1512. compilation-error-regexp-alist))
  1513. </pre>
  1514. <p>Yet another alternative that preserves most of Ant's
  1515. formatting is to pipe Ant's output through the following Perl
  1516. script by Dirk-Willem van Gulik:</p>
  1517. <pre class="code">
  1518. #!/usr/bin/perl
  1519. #
  1520. # May 2001 dirkx@apache.org - remove any
  1521. # [foo] lines from the output; keeping
  1522. # spacing more or less there.
  1523. #
  1524. $|=1;
  1525. while(&lt;STDIN&gt;) {
  1526. if (s/^(\s+)\[(\w+)\]//) {
  1527. if ($2 ne $last) {
  1528. print &quot;$1\[$2\]&quot;;
  1529. $s = ' ' x length($2);
  1530. } else {
  1531. print &quot;$1 $s &quot;;
  1532. };
  1533. $last = $2;
  1534. };
  1535. print;
  1536. };
  1537. </pre>
  1538. <p class="faq">
  1539. <a name="dtd"></a>
  1540. Is there a DTD that I can use to validate my build
  1541. files?
  1542. </p>
  1543. <p>An incomplete DTD can be created by the
  1544. <code>&lt;antstructure&gt;</code> task - but this one
  1545. has a few problems:</p>
  1546. <ul>
  1547. <li>It doesn't know about required attributes. Only
  1548. manual tweaking of this file can help here.</li>
  1549. <li>It is not complete - if you add new tasks via
  1550. <code>&lt;taskdef&gt;</code> it won't know about it. See
  1551. <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this
  1552. page</a> by Michel Casabianca for a solution to this
  1553. problem. Note that the DTD you can download at this page
  1554. is based on Apache Ant 0.3.1.</li>
  1555. <li>It may even be an invalid DTD. As Ant allows tasks
  1556. writers to define arbitrary elements, name collisions will
  1557. happen quite frequently - if your version of Ant contains
  1558. the optional <code>&lt;test&gt;</code> and
  1559. <code>&lt;junit&gt;</code> tasks, there are two XML
  1560. elements named <code>test</code> (the task and the nested child
  1561. element of <code>&lt;junit&gt;</code>) with different attribute
  1562. lists. This problem cannot be solved; DTDs don't give a
  1563. syntax rich enough to support this.</li>
  1564. </ul>
  1565. <p class="faq">
  1566. <a name="xml-entity-include"></a>
  1567. How do I include an XML snippet in my build file?
  1568. </p>
  1569. <p>You can use XML's way of including external files and let
  1570. the parser do the job for Ant:</p>
  1571. <pre class="code">
  1572. &lt;?xml version=&quot;1.0&quot;?&gt;
  1573. &lt;!DOCTYPE project [
  1574. &lt;!ENTITY common SYSTEM &quot;common.xml&quot;&gt;
  1575. ]&gt;
  1576. &lt;project name=&quot;test&quot; default=&quot;test&quot; basedir=&quot;.&quot;&gt;
  1577. &lt;target name=&quot;setup&quot;&gt;
  1578. ...
  1579. &lt;/target&gt;
  1580. &amp;common;
  1581. ...
  1582. &lt;/project&gt;
  1583. </pre>
  1584. <p>will literally include the contents of <code>common.xml</code> where
  1585. you've placed the <code>&amp;common;</code> entity.</p>
  1586. <p>(The filename <code>common.xml</code> in this example is resolved
  1587. relative to the containing XML file by the XML parser. You may also use
  1588. an absolute <code>file:</code> protocol URI.)</p>
  1589. <p>In combination with a DTD, this would look like this:</p>
  1590. <pre class="code">
  1591. &lt;!DOCTYPE project PUBLIC &quot;-//ANT//DTD project//EN&quot; &quot;ant.dtd&quot; [
  1592. &lt;!ENTITY include SYSTEM &quot;header.xml&quot;&gt;
  1593. ]&gt;
  1594. </pre>
  1595. <p>Starting with Ant 1.6, there is a new
  1596. <code>&lt;import&gt;</code> task that can (also) be used to
  1597. include build file fragments. Unlike the snippets used with
  1598. entity includes, the referenced files have to be complete Ant
  1599. build files, though.</p>
  1600. <p>The example above would become:</p>
  1601. <pre class="code">
  1602. &lt;?xml version=&quot;1.0&quot;?&gt;
  1603. &lt;project name=&quot;test&quot; default=&quot;test&quot; basedir=&quot;.&quot;&gt;
  1604. &lt;target name=&quot;setup&quot;&gt;
  1605. ...
  1606. &lt;/target&gt;
  1607. &lt;import file=&quot;./common.xml&quot;/&gt;
  1608. ...
  1609. &lt;/project&gt;
  1610. </pre>
  1611. <p>Unlike entity includes, <code>&lt;import&gt;</code> will
  1612. let you use Ant properties in the file name.</p>
  1613. <p class="faq">
  1614. <a name="mail-logger"></a>
  1615. How do I send an email with the result of my build
  1616. process?
  1617. </p>
  1618. <p>If you are using a nightly build of Ant 1.5 after
  1619. 2001-12-14, you can use the built-in MailLogger:</p>
  1620. <pre class="code">
  1621. ant -logger org.apache.tools.ant.listener.MailLogger
  1622. </pre>
  1623. <p>See the <a href="http://svn.apache.org/repos/asf/ant/core/trunk/docs/manual/listeners.html">Listeners
  1624. &amp; Loggers</a> documentation for details on the properties
  1625. required.</p>
  1626. <p>For older versions of Ant, you can use a custom
  1627. BuildListener that sends out an email
  1628. in the buildFinished() method. Will Glozer
  1629. &lt;will.glozer@jda.com&gt; has written such a listener based
  1630. on <a href="http://www.oracle.com/technetwork/java/index-jsp-139225.html">JavaMail</a>.
  1631. The source is:</p>
  1632. <pre class="code">
  1633. import java.io.*;
  1634. import java.util.*;
  1635. import javax.mail.*;
  1636. import javax.mail.internet.*;
  1637. import org.apache.tools.ant.*;
  1638. /**
  1639. * A simple listener that waits for a build to finish and sends an email
  1640. * of the results. The settings are stored in &quot;monitor.properties&quot; and
  1641. * are fairly self explanatory.
  1642. *
  1643. * @author Will Glozer
  1644. * @version 1.05a 09/06/2000
  1645. */
  1646. public class BuildMonitor implements BuildListener {
  1647. protected Properties props;
  1648. /**
  1649. * Create a new BuildMonitor.
  1650. */
  1651. public BuildMonitor() throws Exception {
  1652. props = new Properties();
  1653. InputStream is = getClass().getResourceAsStream(&quot;monitor.properties&quot;);
  1654. props.load(is);
  1655. is.close();
  1656. }
  1657. public void buildStarted(BuildEvent e) {
  1658. }
  1659. /**
  1660. * Determine the status of the build and the actions to follow, now that
  1661. * the build has completed.
  1662. *
  1663. * @param e Event describing the build status.
  1664. */
  1665. public void buildFinished(BuildEvent e) {
  1666. Throwable th = e.getException();
  1667. String status = (th != null) ? &quot;failed&quot; : &quot;succeeded&quot;;
  1668. try {
  1669. String key = &quot;build.&quot; + status;
  1670. if (props.getProperty(key + &quot;.notify&quot;).equalsIgnoreCase(&quot;false&quot;)) {
  1671. return;
  1672. }
  1673. Session session = Session.getDefaultInstance(props, null);
  1674. MimeMessage message = new MimeMessage(session);
  1675. message.addRecipients(Message.RecipientType.TO, parseAddresses(
  1676. props.getProperty(key + &quot;.email.to&quot;)));
  1677. message.setSubject(props.getProperty(key + &quot;.email.subject&quot;));
  1678. BufferedReader br = new BufferedReader(new FileReader(
  1679. props.getProperty(&quot;build.log&quot;)));
  1680. StringWriter sw = new StringWriter();
  1681. String line = br.readLine();
  1682. while (line != null) {
  1683. sw.write(line);
  1684. sw.write(&quot;\n&quot;);
  1685. line = br.readLine();
  1686. }
  1687. br.close();
  1688. message.setText(sw.toString(), &quot;UTF-8&quot;);
  1689. sw.close();
  1690. Transport transport = session.getTransport();
  1691. transport.connect();
  1692. transport.send(message);
  1693. transport.close();
  1694. } catch (Exception ex) {
  1695. System.out.println(&quot;BuildMonitor failed to send email!&quot;);
  1696. ex.printStackTrace();
  1697. }
  1698. }
  1699. /**
  1700. * Parse a comma separated list of internet email addresses.
  1701. *
  1702. * @param s The list of addresses.
  1703. * @return Array of Addresses.
  1704. */
  1705. protected Address[] parseAddresses(String s) throws Exception {
  1706. StringTokenizer st = new StringTokenizer(s, &quot;,&quot;);
  1707. Address[] addrs = new Address[st.countTokens()];
  1708. for (int i = 0; i &lt; addrs.length; i++) {
  1709. addrs[i] = new InternetAddress(st.nextToken());
  1710. }
  1711. return addrs;
  1712. }
  1713. public void messageLogged(BuildEvent e) {
  1714. }
  1715. public void targetStarted(BuildEvent e) {
  1716. }
  1717. public void targetFinished(BuildEvent e) {
  1718. }
  1719. public void taskStarted(BuildEvent e) {
  1720. }
  1721. public void taskFinished(BuildEvent e) {
  1722. }
  1723. }
  1724. </pre>
  1725. <p>With a <code>monitor.properties</code> like this:</p>
  1726. <pre class="code">
  1727. # configuration for build monitor
  1728. mail.transport.protocol=smtp
  1729. mail.smtp.host=&lt;host&gt;
  1730. mail.from=Will Glozer &lt;will.glozer@jda.com&gt;
  1731. build.log=build.log
  1732. build.failed.notify=true
  1733. build.failed.email.to=will.glozer@jda.com
  1734. build.failed.email.subject=Nightly build failed!
  1735. build.succeeded.notify=true
  1736. build.succeeded.email.to=will.glozer@jda.com
  1737. build.succeeded.email.subject=Nightly build succeeded!
  1738. </pre>
  1739. <p><code>monitor.properties</code> should be placed right next
  1740. to your compiled <code>BuildMonitor.class</code>. To use it,
  1741. invoke Ant like:</p>
  1742. <pre class="code">
  1743. ant -listener BuildMonitor -logfile build.log
  1744. </pre>
  1745. <p>Make sure that <code>mail.jar</code> from JavaMail and
  1746. <code>activation.jar</code> from the
  1747. <a href="http://www.oracle.com/technetwork/java/javase/jaf-135115.html">Java
  1748. Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p>
  1749. <p class="faq">
  1750. <a name="listener-properties"></a>
  1751. How do I get at the properties that Ant was running
  1752. with from inside BuildListener?
  1753. </p>
  1754. <p>You can get at a hashtable with all the properties that Ant
  1755. has been using through the BuildEvent parameter. For
  1756. example:</p>
  1757. <pre class="code">
  1758. public void buildFinished(BuildEvent e) {
  1759. Hashtable table = e.getProject().getProperties();
  1760. String buildpath = (String)table.get(&quot;build.path&quot;);
  1761. ...
  1762. }
  1763. </pre>
  1764. <p>This is more accurate than just reading the same property
  1765. files that your project does, since it will give the correct
  1766. results for properties that were specified on the Ant command line.</p>
  1767. <p class="faq">
  1768. <a name="input-makes-exec-hang"></a>
  1769. <code>&lt;exec&gt;</code> causes other tasks to hang
  1770. or leads to strange behaviour of <code>&lt;input&gt;</code>
  1771. tasks.
  1772. </p>
  1773. <p>When Apache Ant forks a new process for example by using the
  1774. <code>&lt;exec&gt;</code>, <code>&lt;apply&gt;</code>
  1775. or <code>&lt;java&gt;</code> tasks, it will also start a
  1776. new thread reading from standard input and sending
  1777. everything that it has read to that process.</p>
  1778. <p>Unfortunately Ant has no way to know whether the forked
  1779. process is ever going to read any input, so it will start such
  1780. a thread even if the process doesn't need one.</p>
  1781. <p>This behaviour leads to strange side effects like the Ant
  1782. process
  1783. being <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=34461">suspended
  1784. when a build forking new process is run as a background
  1785. process</a> on Unix-like systems or
  1786. <code>&lt;input&gt;</code>
  1787. tasks <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=41024">requiring
  1788. additional inputs</a> if they come after
  1789. an <code>&lt;exec&gt;</code> task.</p>
  1790. <p>Fortunately there is a workaround for this, always specify
  1791. <code>inputstring=""</code> for
  1792. any <code>&lt;exec&gt;</code> task (or one of its sibblings)
  1793. if you know the forked process doesn't consume any
  1794. input.</p>
  1795. <p class="faq">
  1796. <a name="javac-stackoverflow"></a>
  1797. <code>&lt;javac&gt;</code> causes a
  1798. StackOverflowError
  1799. </p>
  1800. <p>For some Java source files it is possible
  1801. that <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=45370">causes
  1802. a StackOverlowError</a> is thrown inside Sun's javac
  1803. compiler. As far as we can tell this is not triggered by a
  1804. bug in Ant.</p>
  1805. <p>It is possible to work around this problem by setting
  1806. <code>&lt;javac&gt;</code>'s fork attribute to true.</p>
  1807. <p class="faq">
  1808. <a name="170-requires-junit"></a>
  1809. Ant 1.7.0 doesn't build from sources without
  1810. JUnit
  1811. </p>
  1812. <p>When building Ant 1.7.0 from the source release without
  1813. junit.jar the build fails with the message "We cannot build
  1814. the test jar unless JUnit is present".</p>
  1815. <p>With Ant 1.7.0 we've started to add ant-testutil.jar as
  1816. part of the distribution and this causes a hard dependency on
  1817. JUnit - at least in version 1.7.0. Unfortunately the
  1818. installation docs don't say so.</p>
  1819. <p>There are two workarounds:</p>
  1820. <ol>
  1821. <li>Add junit.jar to your CLASSPATH when building Ant.</li>
  1822. <li>Change Ant's buildfile and remove test-jar from the
  1823. depends list of the dist-lite target.</li>
  1824. </ol>
  1825. <p class="faq">
  1826. <a name="remove-cr"></a>
  1827. &lt;chmod&gt; or &lt;exec&gt; doesn't work in Ant
  1828. 1.3 on Unix
  1829. </p>
  1830. <p>The <code>antRun</code> script in <code>ANT_HOME/bin</code>
  1831. has DOS instead of Unix line endings; you must remove the
  1832. carriage-return characters from this file. This can be done by
  1833. using Ant's <code>&lt;fixcrlf&gt;</code> task
  1834. or something like:</p>
  1835. <pre class="code">
  1836. tr -d '\r' &lt; $ANT_HOME/bin/antRun &gt; /tmp/foo
  1837. mv /tmp/foo $ANT_HOME/bin/antRun
  1838. </pre>
  1839. <p class="faq">
  1840. <a name="delegating-classloader"></a>
  1841. &lt;style&gt; or &lt;junit&gt; ignores my
  1842. &lt;classpath&gt;
  1843. </p>
  1844. <p>Starting with Ant 1.7.0, &lt;junit&gt; will honor your
  1845. nested &lt;classpath&gt;.</p>
  1846. <p>These tasks don't ignore your classpath setting, you
  1847. are facing a common problem with delegating classloaders.</p>
  1848. <p>This question collects a common type of problem: A task
  1849. needs an external library and it has a nested classpath
  1850. element so that you can point it to this external library, but
  1851. that doesn't work unless you put the external library
  1852. into the <code>CLASSPATH</code> or place it in
  1853. <code>ANT_HOME/lib</code>.</p>
  1854. <p>Some background is necessary before we can discuss
  1855. solutions for <a href="#delegating-classloader-1.5">Ant
  1856. 1.5.x</a> and <a href="#delegating-classloader-1.6">Ant
  1857. 1.6.x</a>.</p>
  1858. <p>When you specify a nested <code>&lt;classpath&gt;</code> in
  1859. Ant, Ant creates a new class loader that uses the path you
  1860. have specified. It then tries to load additional classes from
  1861. this classloader.</p>
  1862. <p>In most cases - for example using &lt;style&gt; or
  1863. &lt;junit&gt; - Ant doesn't load the external library
  1864. directly, it is the loaded class that does so.</p>
  1865. <p>In the case of <code>&lt;junit&gt;</code> it is the task
  1866. implementation itself and in the case of
  1867. <code>&lt;style&gt;</code> it is the implementation of the
  1868. <code>org.apache.tools.ant.taskdefs.XSLTLiaison</code>
  1869. class.</p>
  1870. <p><em>As of Ant 1.7</em> <code>&lt;junit&gt;</code> no longer
  1871. requires you to have <code>junit.jar</code> in Ant's startup
  1872. classpath even if <code>ant-junit.jar</code> is present there.</p>
  1873. <p>Ant's class loader implementation uses Java's
  1874. 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>
  1875. the paragraph</p>
  1876. <blockquote>The <code>ClassLoader</code> class uses a
  1877. delegation model to search for classes and resources. Each
  1878. instance of <code>ClassLoader</code> has an associated parent
  1879. class loader. When called upon to find a class or resource, a
  1880. <code>ClassLoader</code> instance will delegate the search for
  1881. the class or resource to its parent class loader before
  1882. attempting to find the class or resource itself. The virtual
  1883. machine's built-in class loader, called the bootstrap
  1884. class loader, does not itself have a parent but may serve as
  1885. the parent of a <code>ClassLoader</code>
  1886. instance.</blockquote>
  1887. <p>The possible solutions depend on the version of Ant you
  1888. use, see the next sections.</p>
  1889. <p class="faq">
  1890. <a name="delegating-classloader-1.5"></a>
  1891. &lt;style&gt; or &lt;junit&gt; ignores my
  1892. &lt;classpath&gt; - Ant 1.5.x version
  1893. </p>
  1894. <p>Please read <a href="#delegating-classloader">the previous
  1895. entry</a> before you go ahead.</p>
  1896. <p>First of all let's state that Ant's wrapper script
  1897. (<code>ant</code> or <code>ant.bat</code>) adds all
  1898. <code>.jar</code> files from <code>ANT_HOME/lib</code> to
  1899. <code>CLASSPATH</code>, therefore "in
  1900. <code>CLASSPATH</code>" shall mean "either in your
  1901. <code>CLASSPATH</code> environment variable or
  1902. <code>ANT_HOME/lib</code>" for the rest of this
  1903. answer.</p>
  1904. <p>The root of the problem is that the class that needs the
  1905. external library is on the <code>CLASSPATH</code>.</p>
  1906. <p>Let's see what happens when you load the &lt;junit&gt;
  1907. task. Ant's class loader will consult the
  1908. bootstrap class loader first, which tries to load classes from
  1909. <code>CLASSPATH</code>. The bootstrap class loader
  1910. doesn't know anything about Ant's class loader or
  1911. even the path you have specified.</p>
  1912. <p>If the bootstrap class loader can load the class Ant has
  1913. asked it to load (which it can if <code>optional.jar</code> is
  1914. part of <code>CLASSPATH</code>), this class will try to load
  1915. the external library from <code>CLASSPATH</code> as well - it
  1916. doesn't know anything else - and will not find it unless
  1917. the library is in <code>CLASSPATH</code> as well.</p>
  1918. <p>To solve this, you have two major options:</p>
  1919. <ol>
  1920. <li>put all external libraries you need in
  1921. <code>CLASSPATH</code> as well this is not what you want,
  1922. otherwise you wouldn't have found this FAQ entry.</li>
  1923. <li>remove the class that loads the external library from
  1924. the <code>CLASSPATH</code>.</li>
  1925. </ol>
  1926. <p>The easiest way to do this is to remove
  1927. <code>optional.jar</code> from <code>ANT_HOME/lib</code>. If
  1928. you do so, you will have to <code>&lt;taskdef&gt;</code> all
  1929. optional tasks and use nested <code>&lt;classpath&gt;</code>
  1930. elements in the <code>&lt;taskdef&gt;</code> tasks that point
  1931. to the new location of <code>optional.jar</code>. Also,
  1932. don't forget to add the new location of
  1933. <code>optional.jar</code> to the
  1934. <code>&lt;classpath&gt;</code> of your
  1935. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code>
  1936. task.</p>
  1937. <p>If you want to avoid to <code>&lt;taskdef&gt;</code> all
  1938. optional tasks you need, the only other option is to remove
  1939. the classes that should not be loaded via the bootstrap class
  1940. loader from <code>optional.jar</code> and put them into a
  1941. separate archive. Add this separate archive to the
  1942. <code>&lt;classpath&gt;</code> of your
  1943. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code> task
  1944. - and make sure the separate archive is not in
  1945. <code>CLASSPATH</code>.</p>
  1946. <p>In the case of <code>&lt;junit&gt;</code> you'd have
  1947. to remove all classes that are in the
  1948. <code>org/apache/tools/ant/taskdefs/optional/junit</code>
  1949. directory, in the <code>&lt;style&gt;</code> case it is one of
  1950. the <code>*Liaison</code> classes in
  1951. <code>org/apache/tools/ant/taskdefs/optional</code>.</p>
  1952. <p>If you use the option to break up <code>optional.jar</code>
  1953. for <code>&lt;junit&gt;</code> or remove
  1954. <code>ant-junit.jar</code>, you still have to use a
  1955. <code>&lt;taskdef&gt;</code> with a nested
  1956. <code>&lt;classpath&gt;</code> to define the junit task.</p>
  1957. <p class="faq">
  1958. <a name="delegating-classloader-1.6"></a>
  1959. &lt;style&gt; or &lt;junit&gt; ignores my
  1960. &lt;classpath&gt; - Ant 1.6.x version
  1961. </p>
  1962. <p>Please read <a href="#delegating-classloader">the general
  1963. entry</a> before you go ahead.</p>
  1964. <p>The wrapper script of Ant 1.6.x no longer adds the contents
  1965. of <code>ANT_HOME/lib</code> to <code>CLASSPATH</code>,
  1966. instead Ant will create a classloader on top of the bootstrap
  1967. classloader - let's call it the coreloader for the rest of
  1968. this answer - which holds the contents of
  1969. <code>ANT_HOME/lib</code>. Ant's core and its tasks will be
  1970. loaded through this classloader and not the bootstrap
  1971. classloader.</p>
  1972. <p>This causes some small but notable differences between Ant
  1973. 1.5.x and 1.6.x. Most importantly, a third-party task that is
  1974. part of <code>CLASSPATH</code> will no longer work in Ant
  1975. 1.6.x since the task now can't find Ant's classes. In a sense
  1976. this is the same problem this entry is about, only
  1977. <code>ant.jar</code> has become the external library in
  1978. question now.</p>
  1979. <p>This coreloader also holds the contents of
  1980. <code>~/.ant/lib</code> and any file or directory that has
  1981. been specified using Ant's <code>-lib</code> command line
  1982. argument.</p>
  1983. <p>Let's see what happens when you load the &lt;junit&gt;
  1984. task. Ant's class loader will consult the bootstrap
  1985. class loader first, which tries to load classes from
  1986. <code>CLASSPATH</code>. The bootstrap class loader
  1987. doesn't know anything about Ant's class loader or
  1988. even the path you have specified. If it fails to find the
  1989. class using the bootstrap classloader it will try the
  1990. coreloader next. Again, the coreloader doesn't know anything
  1991. about your path.</p>
  1992. <p>If the coreloader can load the class Ant has asked it to
  1993. load (which it can if <code>ant-junit.jar</code> is in
  1994. <code>ANT_HOME/lib</code>), this class will try to load the
  1995. external library from coreloader as well - it doesn't
  1996. know anything else - and will not find it unless the library
  1997. is in <code>CLASSPATH</code> or the coreloader as well.</p>
  1998. <p>To solve this, you have the following major options:</p>
  1999. <ol>
  2000. <li>put all external libraries you need in
  2001. <code>CLASSPATH</code> as well this is not what you want,
  2002. otherwise you wouldn't have found this FAQ entry.</li>
  2003. <li>put all external libraries you need in
  2004. <code>ANT_HOME/lib</code> or <code>.ant/lib</code>. This
  2005. probably still isn't what you want, but you might reconsider
  2006. the <code>.ant/lib</code> option.</li>
  2007. <li>Always start Ant with the <code>-lib</code> command line
  2008. switch and point to your external libraries (or the
  2009. directories holding them).</li>
  2010. <li>remove the class that loads the external library from
  2011. the coreloader.</li>
  2012. </ol>
  2013. <p>In Ant 1.6 <code>optional.jar</code> has been split into
  2014. multiple jars, each one containing classes with the same
  2015. dependencies on external libraries. You can move the
  2016. "offending" jar out of <code>ANT_HOME/lib</code>. For the
  2017. <code>&lt;junit&gt;</code> task it would be
  2018. <code>ant-junit.jar</code>.</p>
  2019. <p>If you do so, you will have to <code>&lt;taskdef&gt;</code>
  2020. all optional tasks that need the external library and use
  2021. nested <code>&lt;classpath&gt;</code> elements in the
  2022. <code>&lt;taskdef&gt;</code> tasks that point to the new
  2023. location of <code>ant-*.jar</code>. Also, don't forget
  2024. to add the new location of <code>ant-*.jar</code> to the
  2025. <code>&lt;classpath&gt;</code> of your
  2026. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code>
  2027. task.</p>
  2028. <p>For example</p>
  2029. <pre class="code">
  2030. &lt;taskdef name=&quot;junit&quot;
  2031. class=&quot;org.apache.tools.ant.taskdefs.optional.junit.JUnitTask&quot;&gt;
  2032. &lt;classpath&gt;
  2033. &lt;pathelement location=&quot;HOME-OF/junit.jar&quot;/&gt;
  2034. &lt;pathelement location=&quot;NEW-HOME-OF/ant-junit.jar&quot;/&gt;
  2035. &lt;/classpath&gt;
  2036. &lt;/taskdef&gt;
  2037. </pre>
  2038. <p class="faq">
  2039. <a name="unknownelement.taskcontainer"></a>
  2040. Why do my custom task containers see Unknown Elements in Ant 1.6
  2041. - they worked in Ant 1.5?
  2042. </p>
  2043. <p>
  2044. The objects added in TaskContainer.addTask(Task task)
  2045. have changed from Tasks to UnknownElements.
  2046. </p>
  2047. <p>
  2048. There was a number of valid reasons for this change. But the backward
  2049. compatibility problems were not noticed until after Ant 1.6.0 was
  2050. released.
  2051. </p>
  2052. <p>
  2053. Your container class will need to be modified to check if the Task
  2054. is an UnknownElement and call perform on it to
  2055. convert it to a Task and to execute it.
  2056. (see apache.tools.ant.taskdefs.Sequential)
  2057. </p>
  2058. <p>
  2059. If you want to do more processing on the task,
  2060. you need to use the techniques in apache.tools.ant.taskdefs.Antlib#execute()
  2061. This does make use of one 1.6 method call (UE#getRealObject()),
  2062. you need to use UE#getTask() instead - this will
  2063. return null for non tasks (types like fileset id=x).
  2064. </p>
  2065. <p>
  2066. So.. iterate over the tasks, if they are UEs, convert them to
  2067. tasks, using UE#maybeConfigure and UE#getTask()
  2068. </p>
  2069. <pre class="code">
  2070. for (Iterator i = tasks.iterator(); i.hasNext();) {
  2071. Task t = (Task) i.next();
  2072. if (t instanceof UnknownElement) {
  2073. ((UnknownElement) t).maybeConfigure();
  2074. t = ((UnknownElement) t).getTask();
  2075. if (t == null) {
  2076. continue;
  2077. }
  2078. }
  2079. // .... original Custom code
  2080. }
  2081. </pre>
  2082. <p>
  2083. This approach should work for ant1.5 and ant1.6.
  2084. </p>
  2085. <p class="faq">
  2086. <a name="oom-on-mac"></a>
  2087. Ant runs into an infinite loop/throws an OutOfMemoryError
  2088. when I compile my project under Mac OS X.
  2089. </p>
  2090. <p>Apple's Java VMs reside
  2091. in <code>/System/Library/Frameworks/JavaVM.framework/Versions/X.Y.Z</code>
  2092. and <code>JAVA_HOME</code> will usually be something
  2093. like <code>/System/Library/Frameworks/JavaVM.framework/Versions/X.Y.Z/Home</code>.</p>
  2094. <p>Inside this home directory there is a symbolic link
  2095. named <code>shared_bundle</code> that links three levels up,
  2096. i.e. to <code>/System/Library/Frameworks/JavaVM.framework</code>.</p>
  2097. <p>If your build file contains a <code>fileset</code> like</p>
  2098. <pre class="code">
  2099. &lt;fileset dir=&quot;${java.home}&quot; includes=&quot;**/*.jar&quot;/&gt;
  2100. </pre>
  2101. <p>Ant is going to follow the <code>shared_bundle</code>
  2102. symlink and ends up recursing into all your installed VMs.
  2103. Even worse, it will
  2104. enter <code>/System/Library/Frameworks/JavaVM.framework/Versions/X.Y.Z/Home</code>
  2105. and will once again follow the same symlink.</p>
  2106. <p>Ant versions after Ant 1.7.1 will detect the infinite loop
  2107. they are in, but the resulting fileset may still be too big to
  2108. deal with, in particular if you have many different VM
  2109. versions installed. The problem is amplified by the fact that
  2110. each installed version has a <code>shared_bundle</code>
  2111. symlink in it.</p>
  2112. <p>One solution is to not allow the fileset to follow symbolic
  2113. links at all, like in</p>
  2114. <pre class="code">
  2115. &lt;fileset dir=&quot;${java.home}&quot; includes=&quot;**/*.jar&quot; followsymlinks=&quot;false&quot;/&gt;
  2116. </pre>
  2117. <p>another one excludes the <code>shared_bundle</code>
  2118. directories:</p>
  2119. <pre class="code">
  2120. &lt;fileset dir=&quot;${java.home}&quot; includes=&quot;**/*.jar&quot; excludes=&quot;**/shared_bundle/**&quot;/&gt;
  2121. </pre>
  2122. <p>For Ant 1.7.1 and earlier
  2123. excluding <code>shared_bundle</code> may not be enough since
  2124. there is another symlink <code>bundle</code> that points to
  2125. the <code>Home</code> directory and will cause infite
  2126. recursions as well.</p>
  2127. <p class="faq">
  2128. <a name="extension-point-and-import"></a>
  2129. <code>extension-point</code> doesn't work
  2130. with <code>import</code> like the documentation
  2131. states.
  2132. </p>
  2133. <p>Yes, there is
  2134. a <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=48804">bug
  2135. in Ant 1.8.0</a>.</p>
  2136. <p>When using two build files like</p>
  2137. <pre class="code">
  2138. importing.xml:
  2139. &lt;project&gt;
  2140. ...
  2141. &lt;import file=&quot;imported.xml&quot;/&gt;
  2142. &lt;target name=&quot;bar&quot; extensionOf=&quot;foo&quot;/&gt;
  2143. &lt;/project&gt;
  2144. imported.xml:
  2145. &lt;project&gt;
  2146. &lt;extension-point name=&quot;foo&quot;/&gt;
  2147. &lt;/project&gt;
  2148. </pre>
  2149. <p>Ant 1.8.0 will fail, claiming there was no extension point
  2150. named "foo".</p>
  2151. <p>This bug has been fixed for Ant 1.8.1. For Ant 1.8.0 there
  2152. is
  2153. a <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=48804#c9">work-around</a>:
  2154. add an additional layer of importing like in</p>
  2155. <pre class="code">
  2156. importing.xml:
  2157. &lt;project&gt;
  2158. &lt;target name=&quot;bar&quot; extensionOf=&quot;foo&quot;/&gt;
  2159. &lt;/project&gt;
  2160. imported.xml:
  2161. &lt;project&gt;
  2162. &lt;extension-point name=&quot;foo&quot;/&gt;
  2163. &lt;/project&gt;
  2164. build.xml:
  2165. &lt;project&gt;
  2166. &lt;import file=&quot;imported.xml&quot;/&gt;
  2167. &lt;import file=&quot;importing.xml&quot;/&gt;
  2168. &lt;/project&gt;
  2169. </pre>
  2170. </div>
  2171. </div>
  2172. <p class="copyright">
  2173. <script type="text/javascript" language="JavaScript"><!--
  2174. document.write(" - "+"Last Published: " + document.lastModified);
  2175. // -->
  2176. </script>
  2177. </p>
  2178. </body>
  2179. </html>