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

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