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 kB

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