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

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