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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!-- Content Stylesheet for Site -->
  3. <!-- start the processing -->
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  7. <meta name="author" value="Stefan Bodewig">
  8. <meta name="email" value="bodewig@apache.org">
  9. <title>Apache Ant - Frequently Asked Questions</title>
  10. </head>
  11. <body bgcolor="#ffffff" text="#000000" link="#525D76">
  12. <table border="0" width="100%" cellspacing="0">
  13. <!-- TOP IMAGE -->
  14. <tr>
  15. <td align="left">
  16. <a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" border="0"/></a>
  17. </td>
  18. <td align="right">
  19. <a href="http://jakarta.apache.org/ant/"><img src="./artwork/ant_logo_large.gif" alt="Apache Ant" border="0"/></a>
  20. </td>
  21. </tr>
  22. </table>
  23. <table border="0" width="100%" cellspacing="4">
  24. <tr><td colspan="2">
  25. <hr noshade="" size="1"/>
  26. </td></tr>
  27. <tr>
  28. <!-- LEFT SIDE NAVIGATION -->
  29. <td valign="top" nowrap="true">
  30. <p><strong>Apache Ant</strong></p>
  31. <ul>
  32. <li> <a href="./index.html">Front Page</a>
  33. </li>
  34. <li> <a href="./antnews.html">News</a>
  35. </li>
  36. <li> <a href="./manual/index.html">Documentation</a>
  37. </li>
  38. <li> <a href="./projects.html">Related Projects</a>
  39. </li>
  40. <li> <a href="./external.html">External Tools and Tasks</a>
  41. </li>
  42. <li> <a href="./resources.html">Resources</a>
  43. </li>
  44. <li> <a href="./faq.html">Ant FAQ</a>
  45. </li>
  46. <li> <a href="./problems.html">Having Problems?</a>
  47. </li>
  48. </ul>
  49. <p><strong>Download</strong></p>
  50. <ul>
  51. <li> <a href="http://jakarta.apache.org/site/binindex.html">Binaries</a>
  52. </li>
  53. <li> <a href="http://jakarta.apache.org/site/sourceindex.html">Source Code</a>
  54. </li>
  55. </ul>
  56. <p><strong>Jakarta</strong></p>
  57. <ul>
  58. <li> <a href="http://jakarta.apache.org/site/news.html">News & Status</a>
  59. </li>
  60. <li> <a href="http://jakarta.apache.org/site/mission.html">Mission</a>
  61. </li>
  62. <li> <a href="http://jakarta.apache.org/site/guidelines.html">Guidelines Notes</a>
  63. </li>
  64. <li> <a href="http://jakarta.apache.org/site/faqs.html">FAQs</a>
  65. </li>
  66. </ul>
  67. <p><strong>Get Involved</strong></p>
  68. <ul>
  69. <li> <a href="http://jakarta.apache.org/site/getinvolved.html">Overview</a>
  70. </li>
  71. <li> <a href="http://jakarta.apache.org/site/cvsindex.html">CVS Repositories</a>
  72. </li>
  73. <li> <a href="http://jakarta.apache.org/site/mail.html">Mailing Lists</a>
  74. </li>
  75. <li> <a href="http://jakarta.apache.org/site/library.html">Reference Library</a>
  76. </li>
  77. <li> <a href="http://nagoya.apache.org/bugzilla/enter_bug.cgi?product=Ant">Bug Database</a>
  78. </li>
  79. <li> <a href="http://nagoya.apache.org/bugzilla/enter_bug.cgi?product=Ant&bug_severity=Enhancement">Enhancement Requests</a>
  80. </li>
  81. </ul>
  82. </td>
  83. <td align="left" valign="top">
  84. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  85. <tr><td bgcolor="#525D76">
  86. <font color="#ffffff" face="arial,helvetica,sanserif">
  87. <strong>Questions</strong>
  88. </font>
  89. </td></tr>
  90. <tr><td>
  91. <blockquote>
  92. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  93. <tr><td bgcolor="#828DA6">
  94. <font color="#ffffff" face="arial,helvetica,sanserif">
  95. <strong>About this FAQ</strong>
  96. </font>
  97. </td></tr>
  98. <tr><td>
  99. <blockquote>
  100. <ul>
  101. <li><a href="#latest-version">
  102. Where do I find the latest version of this
  103. document?
  104. </a></li>
  105. <li><a href="#adding-faqs">
  106. How can I contribute to this FAQ?
  107. </a></li>
  108. <li><a href="#creating-faq">
  109. How do you create the HTML version of this
  110. FAQ?
  111. </a></li>
  112. </ul>
  113. </blockquote>
  114. </td></tr>
  115. </table>
  116. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  117. <tr><td bgcolor="#828DA6">
  118. <font color="#ffffff" face="arial,helvetica,sanserif">
  119. <strong>General</strong>
  120. </font>
  121. </td></tr>
  122. <tr><td>
  123. <blockquote>
  124. <ul>
  125. <li><a href="#what-is-ant">
  126. What is Apache Ant?
  127. </a></li>
  128. <li><a href="#ant-name">
  129. Why do you call it Ant?
  130. </a></li>
  131. <li><a href="#history">
  132. Tell us a little bit about Ant's history.
  133. </a></li>
  134. </ul>
  135. </blockquote>
  136. </td></tr>
  137. </table>
  138. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  139. <tr><td bgcolor="#828DA6">
  140. <font color="#ffffff" face="arial,helvetica,sanserif">
  141. <strong>Installation</strong>
  142. </font>
  143. </td></tr>
  144. <tr><td>
  145. <blockquote>
  146. <ul>
  147. <li><a href="#no-gnu-tar">
  148. I get checksum errors when I try to extract the
  149. <code>tar.gz</code> distribution file. Why?
  150. </a></li>
  151. </ul>
  152. </blockquote>
  153. </td></tr>
  154. </table>
  155. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  156. <tr><td bgcolor="#828DA6">
  157. <font color="#ffffff" face="arial,helvetica,sanserif">
  158. <strong>Using Ant</strong>
  159. </font>
  160. </td></tr>
  161. <tr><td>
  162. <blockquote>
  163. <ul>
  164. <li><a href="#always-recompiles">
  165. Why does Ant always recompile all my Java files?
  166. </a></li>
  167. <li><a href="#passing-cli-args">
  168. How do I pass parameters from the command line to my
  169. build file?
  170. </a></li>
  171. <li><a href="#jikes-switches">
  172. How can I use Jikes specific command line
  173. switches?
  174. </a></li>
  175. <li><a href="#shell-redirect-1">
  176. How do I include a &lt; character in my command line arguments?
  177. </a></li>
  178. <li><a href="#shell-redirect-2">
  179. How do I redirect standard input or standard output
  180. in the <code>&lt;exec&gt;</code> task?
  181. </a></li>
  182. <li><a href="#defaultexcludes">
  183. I've made a &lt;delete&gt; task to delete unwanted
  184. sourcesafe control files (CVS files, editor backup files), but
  185. it doesn't seem to work. The files never get deleted. What's
  186. wrong?
  187. </a></li>
  188. <li><a href="#multi-conditions">
  189. I want to execute a particular target only if
  190. multiple conditions are true.
  191. </a></li>
  192. <li><a href="#stop-dependency">
  193. I have a target I want to skip if a variable is set,
  194. so I have <code>unless="variable"</code> as an attribute
  195. of the target. The trouble is that all of the targets that this target
  196. depends on are still executed. Why?
  197. </a></li>
  198. <li><a href="#include-order">
  199. In my fileset, I've put in an
  200. <code>&lt;exclude&gt;</code> of all files followed by an
  201. <code>&lt;include&gt;</code> of just the files I want, but it
  202. isn't giving me anything at all. What's wrong?
  203. </a></li>
  204. </ul>
  205. </blockquote>
  206. </td></tr>
  207. </table>
  208. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  209. <tr><td bgcolor="#828DA6">
  210. <font color="#ffffff" face="arial,helvetica,sanserif">
  211. <strong>Ant and IDEs/Editors</strong>
  212. </font>
  213. </td></tr>
  214. <tr><td>
  215. <blockquote>
  216. <ul>
  217. <li><a href="#integration">
  218. Is Ant supported by my IDE/Editor?
  219. </a></li>
  220. <li><a href="#emacs-mode">
  221. Why doesn't (X)Emacs/vi/MacOS X's project builder
  222. parse the error messages generated by Ant correctly?
  223. </a></li>
  224. </ul>
  225. </blockquote>
  226. </td></tr>
  227. </table>
  228. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  229. <tr><td bgcolor="#828DA6">
  230. <font color="#ffffff" face="arial,helvetica,sanserif">
  231. <strong>Advanced issues</strong>
  232. </font>
  233. </td></tr>
  234. <tr><td>
  235. <blockquote>
  236. <ul>
  237. <li><a href="#dtd">
  238. Is there a DTD that I can use to validate my build
  239. files?
  240. </a></li>
  241. <li><a href="#xml-entity-include">
  242. How do I include an XML snippet in my build file?
  243. </a></li>
  244. <li><a href="#mail-logger">
  245. How do I send an email with the result of my build
  246. process?
  247. </a></li>
  248. <li><a href="#listener-properties">
  249. How do I get at the properties that Ant was running
  250. with from inside BuildListener?
  251. </a></li>
  252. </ul>
  253. </blockquote>
  254. </td></tr>
  255. </table>
  256. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  257. <tr><td bgcolor="#828DA6">
  258. <font color="#ffffff" face="arial,helvetica,sanserif">
  259. <strong>Known problems</strong>
  260. </font>
  261. </td></tr>
  262. <tr><td>
  263. <blockquote>
  264. <ul>
  265. <li><a href="#remove-cr">
  266. &lt;chmod&gt; or &lt;exec&gt; don't work in Ant
  267. 1.3 on Unix
  268. </a></li>
  269. <li><a href="#javadoc-cannot-execute">
  270. JavaDoc failed: java.io.IOException: javadoc: cannot execute
  271. </a></li>
  272. </ul>
  273. </blockquote>
  274. </td></tr>
  275. </table>
  276. </blockquote>
  277. </td></tr>
  278. </table>
  279. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  280. <tr><td bgcolor="#525D76">
  281. <font color="#ffffff" face="arial,helvetica,sanserif">
  282. <strong>Answers</strong>
  283. </font>
  284. </td></tr>
  285. <tr><td>
  286. <blockquote>
  287. <a name="latest-version">
  288. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  289. <tr><td bgcolor="#828DA6">
  290. <font color="#ffffff" face="arial,helvetica,sanserif">
  291. <strong>
  292. Where do I find the latest version of this
  293. document?
  294. </strong>
  295. </font>
  296. </td></tr>
  297. <tr><td>
  298. <blockquote>
  299. <p>The latest version can always be found at Ant's homepage
  300. <a href="http://jakarta.apache.org/ant/faq.html">http://jakarta.apache.org/ant/faq.html</a>.</p>
  301. </blockquote>
  302. </td></tr>
  303. </table>
  304. </a>
  305. <a name="adding-faqs">
  306. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  307. <tr><td bgcolor="#828DA6">
  308. <font color="#ffffff" face="arial,helvetica,sanserif">
  309. <strong>
  310. How can I contribute to this FAQ?
  311. </strong>
  312. </font>
  313. </td></tr>
  314. <tr><td>
  315. <blockquote>
  316. <p>The page you are looking it is generated from
  317. <a href="http://cvs.apache.org/viewcvs.cgi/~checkout~/jakarta-ant/xdocs/faq.xml">this</a>
  318. document. If you want to add a new question, please submit
  319. a patch against this document to one of Ant's mailing lists,
  320. the structure is hoped to be self-explaining.</p>
  321. <p>If you don't know how to create a patch, see the patches
  322. section of <a href="http://jakarta.apache.org/site/source.html">this
  323. page</a>.</p>
  324. </blockquote>
  325. </td></tr>
  326. </table>
  327. </a>
  328. <a name="creating-faq">
  329. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  330. <tr><td bgcolor="#828DA6">
  331. <font color="#ffffff" face="arial,helvetica,sanserif">
  332. <strong>
  333. How do you create the HTML version of this
  334. FAQ?
  335. </strong>
  336. </font>
  337. </td></tr>
  338. <tr><td>
  339. <blockquote>
  340. <p>We use
  341. <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a>
  342. to render the HTML version from the original XML file.</p>
  343. <p>The Velocity stylesheets used to process the XML files can
  344. be found in the <code>xdocs/stylesheets</code> subdirectory of
  345. Ant's CVS repository - the build file <code>docs.xml</code> is
  346. used to drive Anakia. This file assumes that you have the
  347. <code>jakarta-site2</code> module checked out from CVS as
  348. well, but if you follow the instruction from Anakia's
  349. homepage, you should get it to work without that. Just make
  350. sure all required jars are in the task's classpath.</p>
  351. </blockquote>
  352. </td></tr>
  353. </table>
  354. </a>
  355. <a name="what-is-ant">
  356. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  357. <tr><td bgcolor="#828DA6">
  358. <font color="#ffffff" face="arial,helvetica,sanserif">
  359. <strong>
  360. What is Apache Ant?
  361. </strong>
  362. </font>
  363. </td></tr>
  364. <tr><td>
  365. <blockquote>
  366. <p> Ant is a Java based build tool. In theory it is kind of
  367. like "make" without makes wrinkles and with the full
  368. portability of pure Java code.</p>
  369. </blockquote>
  370. </td></tr>
  371. </table>
  372. </a>
  373. <a name="ant-name">
  374. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  375. <tr><td bgcolor="#828DA6">
  376. <font color="#ffffff" face="arial,helvetica,sanserif">
  377. <strong>
  378. Why do you call it Ant?
  379. </strong>
  380. </font>
  381. </td></tr>
  382. <tr><td>
  383. <blockquote>
  384. <p>According to Ant's original author James Duncan
  385. Davidson, the name is an acronym for "Another Neat
  386. Tool".</p>
  387. <p>Later explanations go along the lines of "Ants are
  388. doing an extremely good job at building things" or
  389. "Ants are very small and can carry a weight a dozen times
  390. of their own" - describing what Ant is intended to
  391. be.</p>
  392. </blockquote>
  393. </td></tr>
  394. </table>
  395. </a>
  396. <a name="history">
  397. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  398. <tr><td bgcolor="#828DA6">
  399. <font color="#ffffff" face="arial,helvetica,sanserif">
  400. <strong>
  401. Tell us a little bit about Ant's history.
  402. </strong>
  403. </font>
  404. </td></tr>
  405. <tr><td>
  406. <blockquote>
  407. <p>Initially Ant was part of the Tomcat code base when it was
  408. donated to the Apache Software Foundation - it has been
  409. created by James Duncan Davidson, who also is the original
  410. author of Tomcat. Ant was there to build Tomcat, nothing
  411. else.</p>
  412. <p>Soon thereafter several open source Java projects realized
  413. that Ant could solve the problems they had with makefiles.
  414. Starting with the projects hosted at Jakarta and the old Java
  415. Apache project, Ant spread like a virus and now is the build
  416. tool of choice for a lot of projects.</p>
  417. <p>In January 2000 Ant was moved to a separate CVS module and
  418. was promoted to a project of its own, independent of
  419. Tomcat. Ant became Apache Ant.</p>
  420. <p>The first version of Ant that was exposed a lager audience
  421. was the one that shipped with Tomcat's 3.1 release on 19 April
  422. 2000. This version has later been referenced to as Ant
  423. 0.3.1.</p>
  424. <p>The first official release of Ant as a stand alone product was
  425. Ant 1.1 released on 19 July 2000. The complete release
  426. history:</p>
  427. <table>
  428. <tr>
  429. <td bgcolor="#039acc" colspan="" rowspan=""
  430. valign="top" align="left">
  431. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  432. Ant Version
  433. </font>
  434. </td>
  435. <td bgcolor="#039acc" colspan="" rowspan=""
  436. valign="top" align="left">
  437. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  438. Release Date
  439. </font>
  440. </td>
  441. </tr>
  442. <tr>
  443. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  444. valign="top" align="left">
  445. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  446. 1.1
  447. </font>
  448. </td>
  449. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  450. valign="top" align="left">
  451. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  452. 19 July 2000
  453. </font>
  454. </td>
  455. </tr>
  456. <tr>
  457. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  458. valign="top" align="left">
  459. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  460. 1.2
  461. </font>
  462. </td>
  463. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  464. valign="top" align="left">
  465. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  466. 24 October 2000
  467. </font>
  468. </td>
  469. </tr>
  470. <tr>
  471. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  472. valign="top" align="left">
  473. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  474. 1.3
  475. </font>
  476. </td>
  477. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  478. valign="top" align="left">
  479. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  480. 3 March 2001
  481. </font>
  482. </td>
  483. </tr>
  484. <tr>
  485. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  486. valign="top" align="left">
  487. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  488. 1.4
  489. </font>
  490. </td>
  491. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  492. valign="top" align="left">
  493. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  494. 3 September 2001
  495. </font>
  496. </td>
  497. </tr>
  498. <tr>
  499. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  500. valign="top" align="left">
  501. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  502. 1.4.1
  503. </font>
  504. </td>
  505. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  506. valign="top" align="left">
  507. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  508. 11 October 2001
  509. </font>
  510. </td>
  511. </tr>
  512. </table>
  513. </blockquote>
  514. </td></tr>
  515. </table>
  516. </a>
  517. <a name="no-gnu-tar">
  518. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  519. <tr><td bgcolor="#828DA6">
  520. <font color="#ffffff" face="arial,helvetica,sanserif">
  521. <strong>
  522. I get checksum errors when I try to extract the
  523. <code>tar.gz</code> distribution file. Why?
  524. </strong>
  525. </font>
  526. </td></tr>
  527. <tr><td>
  528. <blockquote>
  529. <p>Ant's distribution contains file names that are longer
  530. than 100 characters, which is not supported by the standard
  531. tar file format. Several different implementations of tar use
  532. different and incompatible ways to work around this
  533. restriction.</p>
  534. <p>Ant's &lt;tar&gt; task can create tar archives that use
  535. the GNU tar extension, and this has been used when putting
  536. together the distribution. If you are using a different
  537. version of tar (for example, the one shipping with Solaris),
  538. you cannot use it to extract the archive.</p>
  539. <p>The solution is to either install GNU tar, which can be
  540. found <a href="http://www.gnu.org/software/tar/tar.html">here</a>
  541. or use the zip archive instead (you can extract it using
  542. <code>jar xf</code>).</p>
  543. </blockquote>
  544. </td></tr>
  545. </table>
  546. </a>
  547. <a name="always-recompiles">
  548. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  549. <tr><td bgcolor="#828DA6">
  550. <font color="#ffffff" face="arial,helvetica,sanserif">
  551. <strong>
  552. Why does Ant always recompile all my Java files?
  553. </strong>
  554. </font>
  555. </td></tr>
  556. <tr><td>
  557. <blockquote>
  558. <p>In order to find out which files should be compiled, Ant
  559. compares the timestamps of the source files to those of the
  560. resulting <code>.class</code> files. Opening all source files
  561. to find out which package they belong to would be very
  562. inefficient - instead of this, Ant expects you to place your
  563. source files in a directory hierarchy that mirrors your
  564. package hierarchy and to point Ant to the root of this
  565. directory tree with the <code>srcdir</code> attribute.</p>
  566. <p>Say you have <code>&lt;javac srcdir="src"
  567. destdir="dest" /&gt;</code>. If Ant finds a file
  568. <code>src/a/b/C.java</code> it expects it to be in package
  569. <code>a.b</code> so that the resulting <code>.class</code>
  570. file is going to be <code>dest/a/b/C.class</code>.</p>
  571. <p>If your setup is different, Ant's heuristic won't work and
  572. it will recompile classes that are up to date. Ant is not the
  573. only tool, that expects a source tree layout like this.</p>
  574. </blockquote>
  575. </td></tr>
  576. </table>
  577. </a>
  578. <a name="passing-cli-args">
  579. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  580. <tr><td bgcolor="#828DA6">
  581. <font color="#ffffff" face="arial,helvetica,sanserif">
  582. <strong>
  583. How do I pass parameters from the command line to my
  584. build file?
  585. </strong>
  586. </font>
  587. </td></tr>
  588. <tr><td>
  589. <blockquote>
  590. <p>Use properties: <code>ant
  591. -D&lt;name&gt;=&lt;value&gt;</code> lets you define values for
  592. properties. These can then be used within your build file as
  593. any normal property: <code>${&lt;name&gt;}</code> will put in
  594. <code>&lt;value&gt;</code>.</p>
  595. </blockquote>
  596. </td></tr>
  597. </table>
  598. </a>
  599. <a name="jikes-switches">
  600. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  601. <tr><td bgcolor="#828DA6">
  602. <font color="#ffffff" face="arial,helvetica,sanserif">
  603. <strong>
  604. How can I use Jikes specific command line
  605. switches?
  606. </strong>
  607. </font>
  608. </td></tr>
  609. <tr><td>
  610. <blockquote>
  611. <p>A couple of switches are supported via magic
  612. properties:</p>
  613. <table>
  614. <tr>
  615. <td bgcolor="#039acc" colspan="" rowspan=""
  616. valign="top" align="left">
  617. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  618. switch
  619. </font>
  620. </td>
  621. <td bgcolor="#039acc" colspan="" rowspan=""
  622. valign="top" align="left">
  623. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  624. property
  625. </font>
  626. </td>
  627. <td bgcolor="#039acc" colspan="" rowspan=""
  628. valign="top" align="left">
  629. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  630. default
  631. </font>
  632. </td>
  633. </tr>
  634. <tr>
  635. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  636. valign="top" align="left">
  637. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  638. +E
  639. </font>
  640. </td>
  641. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  642. valign="top" align="left">
  643. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  644. build.compiler.emacs
  645. </font>
  646. </td>
  647. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  648. valign="top" align="left">
  649. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  650. false == not set
  651. </font>
  652. </td>
  653. </tr>
  654. <tr>
  655. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  656. valign="top" align="left">
  657. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  658. +P
  659. </font>
  660. </td>
  661. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  662. valign="top" align="left">
  663. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  664. build.compiler.pedantic
  665. </font>
  666. </td>
  667. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  668. valign="top" align="left">
  669. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  670. false == not set
  671. </font>
  672. </td>
  673. </tr>
  674. <tr>
  675. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  676. valign="top" align="left">
  677. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  678. +F
  679. </font>
  680. </td>
  681. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  682. valign="top" align="left">
  683. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  684. build.compiler.fulldepend
  685. </font>
  686. </td>
  687. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  688. valign="top" align="left">
  689. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  690. false == not set
  691. </font>
  692. </td>
  693. </tr>
  694. <tr>
  695. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  696. valign="top" align="left">
  697. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  698. <strong>only for Ant &lt; 1.4, replaced by the nowarn
  699. attribute of javac after that</strong> -nowarn
  700. </font>
  701. </td>
  702. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  703. valign="top" align="left">
  704. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  705. build.compiler.warnings
  706. </font>
  707. </td>
  708. <td bgcolor="#a0ddf0" colspan="" rowspan=""
  709. valign="top" align="left">
  710. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  711. true == not set
  712. </font>
  713. </td>
  714. </tr>
  715. </table>
  716. </blockquote>
  717. </td></tr>
  718. </table>
  719. </a>
  720. <a name="shell-redirect-1">
  721. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  722. <tr><td bgcolor="#828DA6">
  723. <font color="#ffffff" face="arial,helvetica,sanserif">
  724. <strong>
  725. How do I include a &lt; character in my command line arguments?
  726. </strong>
  727. </font>
  728. </td></tr>
  729. <tr><td>
  730. <blockquote>
  731. <p>The short answer is "Use <code>&amp;lt;</code>".</p>
  732. <p>The long answer is, that this probably won't do what you
  733. want anyway, see <a href="#shell-redirect-2">the next
  734. section</a>.</p>
  735. </blockquote>
  736. </td></tr>
  737. </table>
  738. </a>
  739. <a name="shell-redirect-2">
  740. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  741. <tr><td bgcolor="#828DA6">
  742. <font color="#ffffff" face="arial,helvetica,sanserif">
  743. <strong>
  744. How do I redirect standard input or standard output
  745. in the <code>&lt;exec&gt;</code> task?
  746. </strong>
  747. </font>
  748. </td></tr>
  749. <tr><td>
  750. <blockquote>
  751. <p>Say you want to redirect the standard input stream of the
  752. <code>cat</code> command to read from a file, something
  753. like</p>
  754. <div align="left">
  755. <table cellspacing="4" cellpadding="0" border="0">
  756. <tr>
  757. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  758. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  759. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  760. </tr>
  761. <tr>
  762. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  763. <td bgcolor="#ffffff"><pre>
  764. shell-prompt&gt; cat &lt; foo
  765. </pre></td>
  766. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  767. </tr>
  768. <tr>
  769. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  770. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  771. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  772. </tr>
  773. </table>
  774. </div>
  775. <p>and try to translate it into</p>
  776. <div align="left">
  777. <table cellspacing="4" cellpadding="0" border="0">
  778. <tr>
  779. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  780. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  781. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  782. </tr>
  783. <tr>
  784. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  785. <td bgcolor="#ffffff"><pre>
  786. &lt;exec executable=&quot;cat&quot;&gt;
  787. &lt;arg value=&quot;&amp;lt;&quot; /&gt;
  788. &lt;arg value=&quot;foo&quot; /&gt;
  789. &lt;/exec&gt;
  790. </pre></td>
  791. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  792. </tr>
  793. <tr>
  794. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  795. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  796. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  797. </tr>
  798. </table>
  799. </div>
  800. <p>This will not do what you expect. The input-redirection is
  801. performed by your shell, not the command itself, so this
  802. should read:</p>
  803. <div align="left">
  804. <table cellspacing="4" cellpadding="0" border="0">
  805. <tr>
  806. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  807. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  808. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  809. </tr>
  810. <tr>
  811. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  812. <td bgcolor="#ffffff"><pre>
  813. &lt;exec executable=&quot;/bin/sh&quot;&gt;
  814. &lt;arg value=&quot;-c&quot; /&gt;
  815. &lt;arg value=&quot;cat &amp;lt; foo&quot; /&gt;
  816. &lt;/exec&gt;
  817. </pre></td>
  818. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  819. </tr>
  820. <tr>
  821. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  822. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  823. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  824. </tr>
  825. </table>
  826. </div>
  827. <p>Note, that you must use the <code>value</code> attribute of
  828. <code>&lt;arg&gt;</code> in the last element.</p>
  829. </blockquote>
  830. </td></tr>
  831. </table>
  832. </a>
  833. <a name="defaultexcludes">
  834. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  835. <tr><td bgcolor="#828DA6">
  836. <font color="#ffffff" face="arial,helvetica,sanserif">
  837. <strong>
  838. I've made a &lt;delete&gt; task to delete unwanted
  839. sourcesafe control files (CVS files, editor backup files), but
  840. it doesn't seem to work. The files never get deleted. What's
  841. wrong?
  842. </strong>
  843. </font>
  844. </td></tr>
  845. <tr><td>
  846. <blockquote>
  847. <p>This is probably happening because by default, Ant excludes
  848. SourceSafe control files (<code>vssver.scc</code>) and other
  849. files from FileSets.</p>
  850. <p>Here's what you probably did:</p>
  851. <div align="left">
  852. <table cellspacing="4" cellpadding="0" border="0">
  853. <tr>
  854. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  855. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  856. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  857. </tr>
  858. <tr>
  859. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  860. <td bgcolor="#ffffff"><pre>
  861. &lt;delete&gt;
  862. &lt;fileset dir=&quot;${build.src}&quot; includes=&quot;**/vssver.scc&quot;/&gt;
  863. &lt;/delete&gt;
  864. </pre></td>
  865. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  866. </tr>
  867. <tr>
  868. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  869. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  870. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  871. </tr>
  872. </table>
  873. </div>
  874. <p>You need to switch off the default exclusions and it will work:</p>
  875. <div align="left">
  876. <table cellspacing="4" cellpadding="0" border="0">
  877. <tr>
  878. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  879. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  880. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  881. </tr>
  882. <tr>
  883. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  884. <td bgcolor="#ffffff"><pre>
  885. &lt;delete&gt;
  886. &lt;fileset dir=&quot;${build.src}&quot; includes=&quot;**/vssver.scc&quot;
  887. defaultexcludes=&quot;no&quot;/&gt;
  888. &lt;/delete&gt;
  889. </pre></td>
  890. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  891. </tr>
  892. <tr>
  893. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  894. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  895. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  896. </tr>
  897. </table>
  898. </div>
  899. <p>For a complete listing of the patterns that are excluded
  900. by default, see <a href="manual/dirtasks.html">the user
  901. manual</a>.</p>
  902. </blockquote>
  903. </td></tr>
  904. </table>
  905. </a>
  906. <a name="multi-conditions">
  907. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  908. <tr><td bgcolor="#828DA6">
  909. <font color="#ffffff" face="arial,helvetica,sanserif">
  910. <strong>
  911. I want to execute a particular target only if
  912. multiple conditions are true.
  913. </strong>
  914. </font>
  915. </td></tr>
  916. <tr><td>
  917. <blockquote>
  918. <p>There are actually several answers to this question.</p>
  919. <p>If you have only one set and one unset property to test,
  920. you can put both an <code>if</code> and an <code>unless</code>
  921. attribute into the target. The target will act as if they
  922. are "anded" together.</p>
  923. <p>If you are using a version of Ant 1.3 or earlier, the
  924. way to work with all other cases is to chain targets together
  925. to determine the specific state you wish to test for.</p>
  926. <p>To see how this works, assume you have three properties,
  927. <code>prop1</code>, <code>prop2</code>, and <code>prop3</code>.
  928. You want to test that <code>prop1</code> and <code>prop2</code>
  929. are set, but that <code>prop3</code> is not. If the condition
  930. holds true you want to echo "yes".</p>
  931. <p>Here is the implementation in Ant 1.3 and earlier:</p>
  932. <div align="left">
  933. <table cellspacing="4" cellpadding="0" border="0">
  934. <tr>
  935. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  936. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  937. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  938. </tr>
  939. <tr>
  940. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  941. <td bgcolor="#ffffff"><pre>
  942. &lt;target name=&quot;cond&quot; depends=&quot;cond-if&quot;/&gt;
  943. &lt;target name=&quot;cond-if&quot; if=&quot;prop1&quot;&gt;
  944. &lt;antcall target=&quot;cond-if-2&quot;/&gt;
  945. &lt;/target&gt;
  946. &lt;target name=&quot;cond-if-2&quot; if=&quot;prop2&quot;&gt;
  947. &lt;antcall target=&quot;cond-if-3&quot;/&gt;
  948. &lt;/target&gt;
  949. &lt;target name=&quot;cond-if-3&quot; unless=&quot;prop3&quot;&gt;
  950. &lt;echo message=&quot;yes&quot;/&gt;
  951. &lt;/target&gt;
  952. </pre></td>
  953. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  954. </tr>
  955. <tr>
  956. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  957. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  958. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  959. </tr>
  960. </table>
  961. </div>
  962. <p>Note that <code>&lt;antcall&gt;</code> tasks do not pass
  963. property changes back up to the environment they were called
  964. from.</p>
  965. <p>Starting with Ant 1.4, you can use the
  966. <code>&lt;condition&gt;</code> task.</p>
  967. <div align="left">
  968. <table cellspacing="4" cellpadding="0" border="0">
  969. <tr>
  970. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  971. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  972. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  973. </tr>
  974. <tr>
  975. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  976. <td bgcolor="#ffffff"><pre>
  977. &lt;target name=&quot;cond&quot; depends=&quot;cond-if,cond-else&quot;/&gt;
  978. &lt;target name=&quot;check-cond&quot;&gt;
  979. &lt;condition property=&quot;cond-is-true&quot;&gt;
  980. &lt;and&gt;
  981. &lt;not&gt;
  982. &lt;equals arg1=&quot;${prop1}&quot; arg2=&quot;$${prop1}&quot; /&gt;
  983. &lt;/not&gt;
  984. &lt;not&gt;
  985. &lt;equals arg1=&quot;${prop2}&quot; arg2=&quot;$${prop2}&quot; /&gt;
  986. &lt;/not&gt;
  987. &lt;equals arg1=&quot;${prop3}&quot; arg2=&quot;$${prop3}&quot; /&gt;
  988. &lt;/and&gt;
  989. &lt;/condition&gt;
  990. &lt;/target&gt;
  991. &lt;target name=&quot;cond-if&quot; depends=&quot;check-cond&quot; if=&quot;cond-is-true&quot;&gt;
  992. &lt;echo message=&quot;yes&quot;/&gt;
  993. &lt;/target&gt;
  994. &lt;target name=&quot;cond-else&quot; depends=&quot;check-cond&quot; unless=&quot;cond-is-true&quot;&gt;
  995. &lt;echo message=&quot;no&quot;/&gt;
  996. &lt;/target&gt;
  997. </pre></td>
  998. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  999. </tr>
  1000. <tr>
  1001. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1002. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1003. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1004. </tr>
  1005. </table>
  1006. </div>
  1007. <p>This version takes advantage of two things:</p>
  1008. <ul>
  1009. <li>If a property <code>a</code> has not been set,
  1010. <code>${a}</code> will evaluate to <code>${a}</code>.</li>
  1011. <li>To get a literal <code>$</code> in Ant, you have to
  1012. escape it with another <code>$</code> - this will also break
  1013. the special treatment of the sequence <code>${</code>.</li>
  1014. </ul>
  1015. <p>This is neither readable, nor easy to understand, therefore
  1016. post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element
  1017. to the <code>&lt;condition&gt;</code> task.</p>
  1018. <p>Here is the previous example done using
  1019. <code>&lt;isset&gt;</code>:</p>
  1020. <div align="left">
  1021. <table cellspacing="4" cellpadding="0" border="0">
  1022. <tr>
  1023. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1024. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1025. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1026. </tr>
  1027. <tr>
  1028. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1029. <td bgcolor="#ffffff"><pre>
  1030. &lt;target name=&quot;check-cond&quot;&gt;
  1031. &lt;condition property=&quot;cond-is-true&quot;&gt;
  1032. &lt;and&gt;
  1033. &lt;isset property=&quot;prop1&quot;/&gt;
  1034. &lt;isset property=&quot;prop2&quot;/&gt;
  1035. &lt;not&gt;
  1036. &lt;isset property=&quot;prop3&quot;/&gt;
  1037. &lt;/not&gt;
  1038. &lt;/and&gt;
  1039. &lt;/condition&gt;
  1040. &lt;/target&gt;
  1041. </pre></td>
  1042. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1043. </tr>
  1044. <tr>
  1045. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1046. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1047. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1048. </tr>
  1049. </table>
  1050. </div>
  1051. <p>The last option is to use a scripting language to set the
  1052. properties. This can be particularly handy when you need much
  1053. better control than the simple conditions shown here, but of
  1054. course comes with the overhead of adding JAR files to support
  1055. the language, to say nothing of the added maintenance in requiring
  1056. two languages to implement a single system.</p>
  1057. </blockquote>
  1058. </td></tr>
  1059. </table>
  1060. </a>
  1061. <a name="stop-dependency">
  1062. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1063. <tr><td bgcolor="#828DA6">
  1064. <font color="#ffffff" face="arial,helvetica,sanserif">
  1065. <strong>
  1066. I have a target I want to skip if a variable is set,
  1067. so I have <code>unless="variable"</code> as an attribute
  1068. of the target. The trouble is that all of the targets that this target
  1069. depends on are still executed. Why?
  1070. </strong>
  1071. </font>
  1072. </td></tr>
  1073. <tr><td>
  1074. <blockquote>
  1075. <p>The list of dependencies is generated by Ant before any of the
  1076. targets are run. This allows dependent targets such as an
  1077. <code>init</code> target to set properties that can control the
  1078. execution of the targets higher in the dependency graph. This
  1079. is a good thing.</p>
  1080. <p>When your dependencies actually break down the higher level task
  1081. into several simpler steps, though, this behaviour becomes
  1082. counterintuitive. There are a couple of solutions available:
  1083. </p>
  1084. <ol>
  1085. <li>Put the same condition on each of the dependent targets.</li>
  1086. <li>Execute the steps using <code>&lt;antcall&gt;</code>
  1087. instead of specifying them inside the <code>depends</code>
  1088. attribute.</li>
  1089. </ol>
  1090. </blockquote>
  1091. </td></tr>
  1092. </table>
  1093. </a>
  1094. <a name="include-order">
  1095. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1096. <tr><td bgcolor="#828DA6">
  1097. <font color="#ffffff" face="arial,helvetica,sanserif">
  1098. <strong>
  1099. In my fileset, I've put in an
  1100. <code>&lt;exclude&gt;</code> of all files followed by an
  1101. <code>&lt;include&gt;</code> of just the files I want, but it
  1102. isn't giving me anything at all. What's wrong?
  1103. </strong>
  1104. </font>
  1105. </td></tr>
  1106. <tr><td>
  1107. <blockquote>
  1108. <p>The order of the <code>&lt;include&gt;</code> and
  1109. <code>&lt;exclude&gt;</code> tags within a fileset is ignored
  1110. when the fileset is created. Instead, all of the
  1111. <code>&lt;include&gt;</code> elements are processed together,
  1112. followed by all of the <code>&lt;exclude&gt;</code>
  1113. elements. This means that the <code>&lt;exclude&gt;</code>
  1114. elements only apply to the file list produced by the
  1115. <code>&lt;include&gt;</code> elements.</p>
  1116. <p>To get the files you want, focus on just the
  1117. <code>&lt;include&gt;</code> patterns that would be necessary
  1118. to get them. If you need to trim the list that the includes
  1119. would produce, use excludes.</p>
  1120. </blockquote>
  1121. </td></tr>
  1122. </table>
  1123. </a>
  1124. <a name="integration">
  1125. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1126. <tr><td bgcolor="#828DA6">
  1127. <font color="#ffffff" face="arial,helvetica,sanserif">
  1128. <strong>
  1129. Is Ant supported by my IDE/Editor?
  1130. </strong>
  1131. </font>
  1132. </td></tr>
  1133. <tr><td>
  1134. <blockquote>
  1135. <p>See the <a href="external.html#IDE and Editor Integration">section
  1136. on IDE integration</a> on our external tools page.</p>
  1137. </blockquote>
  1138. </td></tr>
  1139. </table>
  1140. </a>
  1141. <a name="emacs-mode">
  1142. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1143. <tr><td bgcolor="#828DA6">
  1144. <font color="#ffffff" face="arial,helvetica,sanserif">
  1145. <strong>
  1146. Why doesn't (X)Emacs/vi/MacOS X's project builder
  1147. parse the error messages generated by Ant correctly?
  1148. </strong>
  1149. </font>
  1150. </td></tr>
  1151. <tr><td>
  1152. <blockquote>
  1153. <p>Ant adds a "banner" with the name of the current
  1154. task in front of all messages - and there are no built-in
  1155. regular expressions in your Editor that would account for
  1156. this.</p>
  1157. <p>You can disable this banner by invoking Ant with the
  1158. <code>-emacs</code> switch. Alternatively you can add the
  1159. following snippet to your <code>.emacs</code> to make Emacs
  1160. understand Ant's output.</p>
  1161. <div align="left">
  1162. <table cellspacing="4" cellpadding="0" border="0">
  1163. <tr>
  1164. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1165. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1166. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1167. </tr>
  1168. <tr>
  1169. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1170. <td bgcolor="#ffffff"><pre>
  1171. (require 'compile)
  1172. (setq compilation-error-regexp-alist
  1173. (append (list
  1174. ;; works for jikes
  1175. '(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:&quot; 1 2 3)
  1176. ;; works for javac
  1177. '(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):&quot; 1 2))
  1178. compilation-error-regexp-alist))
  1179. </pre></td>
  1180. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1181. </tr>
  1182. <tr>
  1183. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1184. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1185. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1186. </tr>
  1187. </table>
  1188. </div>
  1189. <p>Yet another alternative that preserves most of Ant's
  1190. formatting is to pipe Ant's output through the following Perl
  1191. script by Dirk-Willem van Gulik:</p>
  1192. <div align="left">
  1193. <table cellspacing="4" cellpadding="0" border="0">
  1194. <tr>
  1195. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1196. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1197. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1198. </tr>
  1199. <tr>
  1200. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1201. <td bgcolor="#ffffff"><pre>
  1202. #!/usr/bin/perl
  1203. #
  1204. # May 2001 dirkx@apache.org - remove any
  1205. # [foo] lines from the output; keeping
  1206. # spacing more or less there.
  1207. #
  1208. $|=1;
  1209. while(&lt;STDIN&gt;) {
  1210. if (s/^(\s+)\[(\w+)\]//) {
  1211. if ($2 ne $last) {
  1212. print &quot;$1\[$2\]&quot;;
  1213. $s = ' ' x length($2);
  1214. } else {
  1215. print &quot;$1 $s &quot;;
  1216. };
  1217. $last = $2;
  1218. };
  1219. print;
  1220. };
  1221. </pre></td>
  1222. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1223. </tr>
  1224. <tr>
  1225. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1226. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1227. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1228. </tr>
  1229. </table>
  1230. </div>
  1231. </blockquote>
  1232. </td></tr>
  1233. </table>
  1234. </a>
  1235. <a name="dtd">
  1236. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1237. <tr><td bgcolor="#828DA6">
  1238. <font color="#ffffff" face="arial,helvetica,sanserif">
  1239. <strong>
  1240. Is there a DTD that I can use to validate my build
  1241. files?
  1242. </strong>
  1243. </font>
  1244. </td></tr>
  1245. <tr><td>
  1246. <blockquote>
  1247. <p>An incomplete DTD can be created by the
  1248. <code>&lt;antstructure&gt;</code> task - but this one
  1249. has a few problems:</p>
  1250. <ul>
  1251. <li>It doesn't know about required attributes. Only
  1252. manual tweaking of this file can help here.</li>
  1253. <li>It is not complete - if you add new tasks via
  1254. <code>&lt;taskdef&gt;</code> it won't know about it. See
  1255. <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this
  1256. page</a> by Michel Casabianca for a solution to this
  1257. problem. Note that the DTD you can download at this page
  1258. is based on Ant 0.3.1.</li>
  1259. <li>It may even be an invalid DTD. As Ant allows tasks
  1260. writers to define arbitrary elements, name collisions will
  1261. happen quite frequently - if your version of Ant contains
  1262. the optional <code>&lt;test&gt;</code> and
  1263. <code>&lt;junit&gt;</code> tasks, there are two XML
  1264. elements named test (the task and the nested child element
  1265. of <code>&lt;junit&gt;</code>) with different attribute
  1266. lists. This problem cannot be solved, DTDs don't give a
  1267. syntax rich enough to support this.</li>
  1268. </ul>
  1269. </blockquote>
  1270. </td></tr>
  1271. </table>
  1272. </a>
  1273. <a name="xml-entity-include">
  1274. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1275. <tr><td bgcolor="#828DA6">
  1276. <font color="#ffffff" face="arial,helvetica,sanserif">
  1277. <strong>
  1278. How do I include an XML snippet in my build file?
  1279. </strong>
  1280. </font>
  1281. </td></tr>
  1282. <tr><td>
  1283. <blockquote>
  1284. <p>You can use XML's way of including external files and let
  1285. the parser do the job for Ant:</p>
  1286. <div align="left">
  1287. <table cellspacing="4" cellpadding="0" border="0">
  1288. <tr>
  1289. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1290. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1291. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1292. </tr>
  1293. <tr>
  1294. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1295. <td bgcolor="#ffffff"><pre>
  1296. &lt;?xml version=&quot;1.0&quot;?&gt;
  1297. &lt;!DOCTYPE project [
  1298. &lt;!ENTITY common SYSTEM &quot;file:./common.xml&quot;&gt;
  1299. ]&gt;
  1300. &lt;project name=&quot;test&quot; default=&quot;test&quot; basedir=&quot;.&quot;&gt;
  1301. &lt;target name=&quot;setup&quot;&gt;
  1302. ...
  1303. &lt;/target&gt;
  1304. &amp;common;
  1305. ...
  1306. &lt;/project&gt;
  1307. </pre></td>
  1308. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1309. </tr>
  1310. <tr>
  1311. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1312. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1313. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1314. </tr>
  1315. </table>
  1316. </div>
  1317. <p>will literally include the contents of <code>common.xml</code> where
  1318. you've placed the <code>&amp;common;</code> entity.</p>
  1319. <p>In combination with a DTD, this would look like this:</p>
  1320. <div align="left">
  1321. <table cellspacing="4" cellpadding="0" border="0">
  1322. <tr>
  1323. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1324. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1325. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1326. </tr>
  1327. <tr>
  1328. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1329. <td bgcolor="#ffffff"><pre>
  1330. &lt;!DOCTYPE project PUBLIC &quot;-//ANT//DTD project//EN&quot; &quot;file:./ant.dtd&quot; [
  1331. &lt;!ENTITY include SYSTEM &quot;file:./header.xml&quot;&gt;
  1332. ]&gt;
  1333. </pre></td>
  1334. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1335. </tr>
  1336. <tr>
  1337. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1338. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1339. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1340. </tr>
  1341. </table>
  1342. </div>
  1343. </blockquote>
  1344. </td></tr>
  1345. </table>
  1346. </a>
  1347. <a name="mail-logger">
  1348. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1349. <tr><td bgcolor="#828DA6">
  1350. <font color="#ffffff" face="arial,helvetica,sanserif">
  1351. <strong>
  1352. How do I send an email with the result of my build
  1353. process?
  1354. </strong>
  1355. </font>
  1356. </td></tr>
  1357. <tr><td>
  1358. <blockquote>
  1359. <p>If you are using a nightly-build of Ant 1.5 after
  1360. 2001-12-14, you can use the built-in MailLogger.</p>
  1361. <div align="left">
  1362. <table cellspacing="4" cellpadding="0" border="0">
  1363. <tr>
  1364. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1365. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1366. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1367. </tr>
  1368. <tr>
  1369. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1370. <td bgcolor="#ffffff"><pre>
  1371. ant -logger org.apache.tools.ant.listener.MailLogger
  1372. </pre></td>
  1373. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1374. </tr>
  1375. <tr>
  1376. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1377. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1378. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1379. </tr>
  1380. </table>
  1381. </div>
  1382. <p>See the <a href="http://cvs.apache.org/viewcvs/~checkout~/jakarta-ant/docs/manual/listeners.html?content-type=text/html">Listener
  1383. &amp; Logger documentation</a> for details on the properties
  1384. required.</p>
  1385. <p>For older versions of Ant you can use a custom
  1386. BuildListener, that sends out an email
  1387. in the buildFinished() method. Will Glozer
  1388. &lt;will.glozer@jda.com&gt; has written such a listener based
  1389. on <a href="http://java.sun.com/products/javamail/">JavaMail</a>,
  1390. the source is</p>
  1391. <div align="left">
  1392. <table cellspacing="4" cellpadding="0" border="0">
  1393. <tr>
  1394. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1395. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1396. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1397. </tr>
  1398. <tr>
  1399. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1400. <td bgcolor="#ffffff"><pre>
  1401. import java.io.*;
  1402. import java.util.*;
  1403. import javax.mail.*;
  1404. import javax.mail.internet.*;
  1405. import org.apache.tools.ant.*;
  1406. /**
  1407. * A simple listener that waits for a build to finish and sends an email
  1408. * of the results. The settings are stored in &quot;monitor.properties&quot; and
  1409. * are fairly self explanatory.
  1410. *
  1411. * @author Will Glozer
  1412. * @version 1.05a 09/06/2000
  1413. */
  1414. public class BuildMonitor implements BuildListener {
  1415. protected Properties props;
  1416. /**
  1417. * Create a new BuildMonitor.
  1418. */
  1419. public BuildMonitor() throws Exception {
  1420. props = new Properties();
  1421. InputStream is = getClass().getResourceAsStream(&quot;monitor.properties&quot;);
  1422. props.load(is);
  1423. is.close();
  1424. }
  1425. public void buildStarted(BuildEvent e) {
  1426. }
  1427. /**
  1428. * Determine the status of the build and the actions to follow, now that
  1429. * the build has completed.
  1430. *
  1431. * @param e Event describing the build tatus.
  1432. */
  1433. public void buildFinished(BuildEvent e) {
  1434. Throwable th = e.getException();
  1435. String status = (th != null) ? &quot;failed&quot; : &quot;succeeded&quot;;
  1436. try {
  1437. String key = &quot;build.&quot; + status;
  1438. if (props.getProperty(key + &quot;.notify&quot;).equalsIgnoreCase(&quot;false&quot;)) {
  1439. return;
  1440. }
  1441. Session session = Session.getDefaultInstance(props, null);
  1442. MimeMessage message = new MimeMessage(session);
  1443. message.addRecipients(Message.RecipientType.TO, parseAddresses(
  1444. props.getProperty(key + &quot;.email.to&quot;)));
  1445. message.setSubject(props.getProperty(key + &quot;.email.subject&quot;));
  1446. BufferedReader br = new BufferedReader(new FileReader(
  1447. props.getProperty(&quot;build.log&quot;)));
  1448. StringWriter sw = new StringWriter();
  1449. String line = br.readLine();
  1450. while (line != null) {
  1451. sw.write(line);
  1452. sw.write(&quot;\n&quot;);
  1453. line = br.readLine();
  1454. }
  1455. br.close();
  1456. message.setText(sw.toString(), &quot;UTF-8&quot;);
  1457. sw.close();
  1458. Transport transport = session.getTransport();
  1459. transport.connect();
  1460. transport.send(message);
  1461. transport.close();
  1462. } catch (Exception ex) {
  1463. System.out.println(&quot;BuildMonitor failed to send email!&quot;);
  1464. ex.printStackTrace();
  1465. }
  1466. }
  1467. /**
  1468. * Parse a comma separated list of internet email addresses.
  1469. *
  1470. * @param s The list of addresses.
  1471. * @return Array of Addresses.
  1472. */
  1473. protected Address[] parseAddresses(String s) throws Exception {
  1474. StringTokenizer st = new StringTokenizer(s, &quot;,&quot;);
  1475. Address[] addrs = new Address[st.countTokens()];
  1476. for (int i = 0; i &lt; addrs.length; i++) {
  1477. addrs[i] = new InternetAddress(st.nextToken());
  1478. }
  1479. return addrs;
  1480. }
  1481. public void messageLogged(BuildEvent e) {
  1482. }
  1483. public void targetStarted(BuildEvent e) {
  1484. }
  1485. public void targetFinished(BuildEvent e) {
  1486. }
  1487. public void taskStarted(BuildEvent e) {
  1488. }
  1489. public void taskFinished(BuildEvent e) {
  1490. }
  1491. }
  1492. </pre></td>
  1493. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1494. </tr>
  1495. <tr>
  1496. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1497. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1498. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1499. </tr>
  1500. </table>
  1501. </div>
  1502. <p>With a <code>monitor.properties</code> like this</p>
  1503. <div align="left">
  1504. <table cellspacing="4" cellpadding="0" border="0">
  1505. <tr>
  1506. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1507. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1508. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1509. </tr>
  1510. <tr>
  1511. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1512. <td bgcolor="#ffffff"><pre>
  1513. # configuration for build monitor
  1514. mail.transport.protocol=smtp
  1515. mail.smtp.host=&lt;host&gt;
  1516. mail.from=Will Glozer &lt;will.glozer@jda.com&gt;
  1517. build.log=build.log
  1518. build.failed.notify=true
  1519. build.failed.email.to=will.glozer@jda.com
  1520. build.failed.email.subject=Nightly build failed!
  1521. build.succeeded.notify=true
  1522. build.succeeded.email.to=will.glozer@jda.com
  1523. build.succeeded.email.subject=Nightly build succeeded!
  1524. </pre></td>
  1525. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1526. </tr>
  1527. <tr>
  1528. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1529. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1530. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1531. </tr>
  1532. </table>
  1533. </div>
  1534. <p><code>monitor.properties</code> should be placed right next
  1535. to your compiled <code>BuildMonitor.class</code>. To use it,
  1536. invoke Ant like</p>
  1537. <div align="left">
  1538. <table cellspacing="4" cellpadding="0" border="0">
  1539. <tr>
  1540. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1541. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1542. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1543. </tr>
  1544. <tr>
  1545. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1546. <td bgcolor="#ffffff"><pre>
  1547. ant -listener BuildMonitor -logfile build.log
  1548. </pre></td>
  1549. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1550. </tr>
  1551. <tr>
  1552. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1553. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1554. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1555. </tr>
  1556. </table>
  1557. </div>
  1558. <p>Make sure that <code>mail.jar</code> from JavaMail and
  1559. <code>activation.jar</code> from the
  1560. <a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java
  1561. Beans Activation Framework</a> in your <code>CLASSPATH</code>.</p>
  1562. </blockquote>
  1563. </td></tr>
  1564. </table>
  1565. </a>
  1566. <a name="listener-properties">
  1567. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1568. <tr><td bgcolor="#828DA6">
  1569. <font color="#ffffff" face="arial,helvetica,sanserif">
  1570. <strong>
  1571. How do I get at the properties that Ant was running
  1572. with from inside BuildListener?
  1573. </strong>
  1574. </font>
  1575. </td></tr>
  1576. <tr><td>
  1577. <blockquote>
  1578. <p>You can get at a hashtable with all the properties that Ant
  1579. has been using through the BuildEvent parameter. For
  1580. example:</p>
  1581. <div align="left">
  1582. <table cellspacing="4" cellpadding="0" border="0">
  1583. <tr>
  1584. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1585. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1586. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1587. </tr>
  1588. <tr>
  1589. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1590. <td bgcolor="#ffffff"><pre>
  1591. public void buildFinished(BuildEvent e) {
  1592. Hashtable table = e.getProject().getProperties();
  1593. String buildpath = (String)table.get(&quot;build.path&quot;);
  1594. ...
  1595. }
  1596. </pre></td>
  1597. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1598. </tr>
  1599. <tr>
  1600. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1601. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1602. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1603. </tr>
  1604. </table>
  1605. </div>
  1606. <p>This is more accurate than just reading the same property
  1607. files that your project does, since it will give the correct
  1608. results for properties that are specified on the command line
  1609. when running Ant.</p>
  1610. </blockquote>
  1611. </td></tr>
  1612. </table>
  1613. </a>
  1614. <a name="remove-cr">
  1615. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1616. <tr><td bgcolor="#828DA6">
  1617. <font color="#ffffff" face="arial,helvetica,sanserif">
  1618. <strong>
  1619. &lt;chmod&gt; or &lt;exec&gt; don't work in Ant
  1620. 1.3 on Unix
  1621. </strong>
  1622. </font>
  1623. </td></tr>
  1624. <tr><td>
  1625. <blockquote>
  1626. <p>The <code>antRun</code> script in <code>ANT_HOME/bin</code>
  1627. has DOS instead of Unix line endings, you must remove the
  1628. carriage return characters from this file. This can be done by
  1629. using Ant's &lt;fixcrlf&gt; task or something like:</p>
  1630. <div align="left">
  1631. <table cellspacing="4" cellpadding="0" border="0">
  1632. <tr>
  1633. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1634. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1635. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1636. </tr>
  1637. <tr>
  1638. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1639. <td bgcolor="#ffffff"><pre>
  1640. tr -d '\r' &lt; $ANT_HOME/bin/antRun &gt; /tmp/foo
  1641. mv /tmp/foo $ANT_HOME/bin/antRun
  1642. </pre></td>
  1643. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1644. </tr>
  1645. <tr>
  1646. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1647. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1648. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  1649. </tr>
  1650. </table>
  1651. </div>
  1652. </blockquote>
  1653. </td></tr>
  1654. </table>
  1655. </a>
  1656. <a name="javadoc-cannot-execute">
  1657. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  1658. <tr><td bgcolor="#828DA6">
  1659. <font color="#ffffff" face="arial,helvetica,sanserif">
  1660. <strong>
  1661. JavaDoc failed: java.io.IOException: javadoc: cannot execute
  1662. </strong>
  1663. </font>
  1664. </td></tr>
  1665. <tr><td>
  1666. <blockquote>
  1667. <p>There is a bug in the Solaris reference implementation of
  1668. 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>.
  1669. This also appears to be true under Linux, moving the JDK to
  1670. the front of the PATH fixes the problem.</p>
  1671. </blockquote>
  1672. </td></tr>
  1673. </table>
  1674. </a>
  1675. </blockquote>
  1676. </td></tr>
  1677. </table>
  1678. </td>
  1679. </tr>
  1680. <!-- FOOTER -->
  1681. <tr><td colspan="2">
  1682. <hr noshade="" size="1"/>
  1683. </td></tr>
  1684. <tr><td colspan="2">
  1685. <div align="center"><font color="#525D76" size="-1"><em>
  1686. Copyright &#169; 2000-2002, Apache Software Foundation
  1687. </em></font></div>
  1688. </td></tr>
  1689. </table>
  1690. </body>
  1691. </html>
  1692. <!-- end the processing -->