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

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