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

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