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

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