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

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