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 kB

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