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 88 KiB

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