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

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