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 104 kB

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