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 kB

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