You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

faq.html 96 KiB

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