You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

faq.html 66 kB

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