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

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