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

faq.html 67 KiB

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