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

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