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

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