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 76 kB

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