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

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