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

faq.html 62 KiB

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