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

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