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

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