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

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