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 kB

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