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

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