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

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