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.xml 51 kB

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