1 |
|
---|
2 |
|
---|
3 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
4 | <html lang="en">
|
---|
5 | <!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
|
---|
6 | <head>
|
---|
7 | <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
8 | <title>Apache Ant - Frequently Asked Questions</title>
|
---|
9 | <link type="text/css" href="./page.css" rel="stylesheet">
|
---|
10 | <meta name="author" content="Stefan Bodewig">
|
---|
11 | <meta name="email" content="[email protected]">
|
---|
12 | </head>
|
---|
13 |
|
---|
14 | <body>
|
---|
15 | <p class="navpath">
|
---|
16 | <script src="./breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
|
---|
17 | </p>
|
---|
18 |
|
---|
19 | <div class="logobar">
|
---|
20 | <table width="100%" border="0" cellspacing="0" cellpadding="0">
|
---|
21 | <tr>
|
---|
22 | <td align="left"><img border="0" alt="Apache Ant site" src="./images/group-logo.gif"></td>
|
---|
23 | <td align="center" width="100%"><img alt="Apache Ant logo" border="0" src="./images/project-logo.gif"></td>
|
---|
24 | <td align="right">
|
---|
25 | <form target="_blank" onsubmit="q.value = query.value + ' site:ant.apache.org'" action="http://www.google.com/search" method="get">
|
---|
26 | <table summary="search" border="0" cellspacing="0" cellpadding="0" bgcolor="#4C6C8F">
|
---|
27 | <tr>
|
---|
28 | <td colspan="3"><img height="10" width="1" alt="" src="./images/spacer.gif"></td>
|
---|
29 | </tr>
|
---|
30 | <tr>
|
---|
31 | <td><img height="1" width="1" alt="" src="./images/spacer.gif"></td>
|
---|
32 | <td nowrap="nowrap" class="searchcaption">
|
---|
33 | <input name="q" type="hidden">
|
---|
34 | <input size="15" id="query" type="text">
|
---|
35 | <img height="1" width="5" alt="" src="./images/spacer.gif">
|
---|
36 | <input name="Search" value="Search" type="submit">
|
---|
37 | <br>
|
---|
38 | the Apache Ant site
|
---|
39 | </td>
|
---|
40 | <td><img height="1" width="1" alt="" src="./images/spacer.gif"></td>
|
---|
41 | </tr>
|
---|
42 | <tr>
|
---|
43 | <td><img alt="" border="0" height="10" width="9" src="./images/search-left.gif"></td>
|
---|
44 | <td><img height="1" width="1" alt="" src="./images/spacer.gif"></td>
|
---|
45 | <td><img alt="" border="0" height="10" width="9" src="./images/search-right.gif"></td>
|
---|
46 | </tr>
|
---|
47 | </table>
|
---|
48 | </form>
|
---|
49 | </td>
|
---|
50 | </tr>
|
---|
51 | </table>
|
---|
52 | </div>
|
---|
53 |
|
---|
54 | <div class="tab">
|
---|
55 | <table summary="tab bar" border="0" cellpadding="0" cellspacing="0">
|
---|
56 | <tr>
|
---|
57 | <td width="8"><img alt="" height="5" width="8" src="./images/spacer.gif"></td><td valign="bottom">
|
---|
58 | <table summary="selected tab" style="height: 1.5em" border="0" cellpadding="0" cellspacing="0">
|
---|
59 | <tr>
|
---|
60 | <td valign="top" width="5" bgcolor="#4C6C8F"><img height="5" width="5" alt="" src="./images/tabSel-left.gif"></td><td valign="middle" bgcolor="#4C6C8F"><font color="#ffffff" size="2" face="Arial, Helvetica, Sans-serif"><b>Home</b></font></td><td valign="top" width="5" bgcolor="#4C6C8F"><img height="5" width="5" alt="" src="./images/tabSel-right.gif"></td>
|
---|
61 | </tr>
|
---|
62 | </table>
|
---|
63 | </td>
|
---|
64 | <td width="5"><img alt="" height="8" width="8" src="./images/spacer.gif"></td><td valign="bottom">
|
---|
65 | <table summary="non selected tab" style="height: 1.4em" border="0" cellpadding="0" cellspacing="0">
|
---|
66 | <tr>
|
---|
67 | <td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="./images/tab-left.gif"></td><td valign="middle" bgcolor="#B2C4E0"><a href="./projects/index.html"><font size="2" face="Arial, Helvetica, Sans-serif">Projects</font></a></td><td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="./images/tab-right.gif"></td>
|
---|
68 | </tr>
|
---|
69 | </table>
|
---|
70 | </td>
|
---|
71 | </tr>
|
---|
72 | </table>
|
---|
73 | </div>
|
---|
74 |
|
---|
75 | <div class="bluebar"></div>
|
---|
76 |
|
---|
77 | <div class="menucontainer">
|
---|
78 |
|
---|
79 | <div class="menu">
|
---|
80 | <ul>
|
---|
81 | <li class="menuheader">Apache Ant
|
---|
82 | <ul>
|
---|
83 | <li>
|
---|
84 | <a href="./index.html">Welcome</a>
|
---|
85 | </li>
|
---|
86 | <li>
|
---|
87 | <a href="./license.html">License</a>
|
---|
88 | </li>
|
---|
89 | <li>
|
---|
90 | <a href="./antnews.html">News</a>
|
---|
91 | </li>
|
---|
92 | </ul>
|
---|
93 | </li>
|
---|
94 | <li class="menuheader">Documentation
|
---|
95 | <ul>
|
---|
96 | <li>
|
---|
97 | <a href="./manual/index.html">Manual</a>
|
---|
98 | </li>
|
---|
99 | <li>
|
---|
100 | <a href="./projects.html">Related Projects</a>
|
---|
101 | </li>
|
---|
102 | <li>
|
---|
103 | <a href="./external.html">External Tools and Tasks</a>
|
---|
104 | </li>
|
---|
105 | <li>
|
---|
106 | <a href="./resources.html">Resources</a>
|
---|
107 | </li>
|
---|
108 | <li>
|
---|
109 | <span class="sel">Frequently Asked Questions</span>
|
---|
110 | </li>
|
---|
111 | <li>
|
---|
112 | <a href="http://wiki.apache.org/ant/FrontPage">Wiki</a>
|
---|
113 | </li>
|
---|
114 | <li>
|
---|
115 | <a href="./problems.html">Having Problems?</a>
|
---|
116 | </li>
|
---|
117 | </ul>
|
---|
118 | </li>
|
---|
119 | <li class="menuheader">Download
|
---|
120 | <ul>
|
---|
121 | <li>
|
---|
122 | <a href="http://ant.apache.org/bindownload.cgi">Binary Distributions</a>
|
---|
123 | </li>
|
---|
124 | <li>
|
---|
125 | <a href="http://ant.apache.org/srcdownload.cgi">Source Distributions</a>
|
---|
126 | </li>
|
---|
127 | </ul>
|
---|
128 | </li>
|
---|
129 | <li class="menuheader">Contributing
|
---|
130 | <ul>
|
---|
131 | <li>
|
---|
132 | <a href="./mail.html">Mailing Lists</a>
|
---|
133 | </li>
|
---|
134 | <li>
|
---|
135 | <a href="./svn.html">Subversion Repositories</a>
|
---|
136 | </li>
|
---|
137 | <li>
|
---|
138 | <a href="./nightlies.html">Nightly Builds</a>
|
---|
139 | </li>
|
---|
140 | <li>
|
---|
141 | <a href="./bugs.html">Bug Database</a>
|
---|
142 | </li>
|
---|
143 | <li>
|
---|
144 | <a href="http://www.apache.org/foundation/contributing.html">Donations</a>
|
---|
145 | </li>
|
---|
146 | </ul>
|
---|
147 | </li>
|
---|
148 | <li class="menuheader">Project Management
|
---|
149 | <ul>
|
---|
150 | <li>
|
---|
151 | <a href="./contributors.html">Contributors</a>
|
---|
152 | </li>
|
---|
153 | <li>
|
---|
154 | <a href="./mission.html">Apache Ant Mission</a>
|
---|
155 | </li>
|
---|
156 | <li>
|
---|
157 | <a href="./bylaws.html">Project Bylaws</a>
|
---|
158 | </li>
|
---|
159 | <li>
|
---|
160 | <a href="./legal.html">Legal</a>
|
---|
161 | </li>
|
---|
162 | </ul>
|
---|
163 | </li>
|
---|
164 | </ul>
|
---|
165 | </div>
|
---|
166 | <img style="float: left" height="10" width="10" border="0" alt="" src="./images/menu-left.gif">
|
---|
167 | <img style="float: right" height="10" width="10" border="0" alt="" src="./images/menu-right.gif">
|
---|
168 | </div>
|
---|
169 | <div class="lightbluebar"> </div>
|
---|
170 | <div class="main">
|
---|
171 | <div class="content">
|
---|
172 | <h1 class="title">Frequently Asked Questions</h1>
|
---|
173 |
|
---|
174 | <h3 class="section">Questions</h3>
|
---|
175 | <h4 class="toc">About this FAQ</h4>
|
---|
176 | <ul>
|
---|
177 | <li><a href="#latest-version">
|
---|
178 | Where do I find the latest version of this
|
---|
179 | document?
|
---|
180 | </a></li>
|
---|
181 | <li><a href="#adding-faqs">
|
---|
182 | How can I contribute to this FAQ?
|
---|
183 | </a></li>
|
---|
184 | <li><a href="#creating-faq">
|
---|
185 | How do you create the HTML version of this
|
---|
186 | FAQ?
|
---|
187 | </a></li>
|
---|
188 | </ul>
|
---|
189 | <h4 class="toc">General</h4>
|
---|
190 | <ul>
|
---|
191 | <li><a href="#what-is-ant">
|
---|
192 | What is Apache Ant?
|
---|
193 | </a></li>
|
---|
194 | <li><a href="#ant-name">
|
---|
195 | Why do you call it Ant?
|
---|
196 | </a></li>
|
---|
197 | <li><a href="#history">
|
---|
198 | Tell us a little bit about Ant's history.
|
---|
199 | </a></li>
|
---|
200 | </ul>
|
---|
201 | <h4 class="toc">Installation</h4>
|
---|
202 | <ul>
|
---|
203 | <li><a href="#no-gnu-tar">
|
---|
204 | I get checksum errors when I try to extract the
|
---|
205 | <code>tar.gz</code> distribution file. Why?
|
---|
206 | </a></li>
|
---|
207 | <li><a href="#RedHat_ES_3">
|
---|
208 | How do you get ant-1.6.x (or any version later than
|
---|
209 | 1.5.2) to work on on RedHat ES 3?
|
---|
210 | </a></li>
|
---|
211 | </ul>
|
---|
212 | <h4 class="toc">How do I ...</h4>
|
---|
213 | <ul>
|
---|
214 | <li><a href="#implement-os-specific-configuration">
|
---|
215 | How do I realize os--specific configurations?
|
---|
216 | </a></li>
|
---|
217 | <li><a href="#adding-external-tasks">
|
---|
218 | How do I add an external task that I've written to the
|
---|
219 | page "External Tools and Tasks"?
|
---|
220 | </a></li>
|
---|
221 | <li><a href="#create-extensions">
|
---|
222 | How do I create new tasks?
|
---|
223 | </a></li>
|
---|
224 | <li><a href="#passing-cli-args">
|
---|
225 | How do I pass parameters from the command line to my
|
---|
226 | build file?
|
---|
227 | </a></li>
|
---|
228 | <li><a href="#jikes-switches">
|
---|
229 | How can I use Jikes-specific command-line
|
---|
230 | switches?
|
---|
231 | </a></li>
|
---|
232 | <li><a href="#shell-redirect-1">
|
---|
233 | How do I include a < character in my command-line arguments?
|
---|
234 | </a></li>
|
---|
235 | <li><a href="#shell-redirect-2">
|
---|
236 | How do I redirect standard input or standard output
|
---|
237 | in the <code><exec></code> task?
|
---|
238 | </a></li>
|
---|
239 | <li><a href="#batch-shell-execute">
|
---|
240 | How do I execute a batch file or shell script from Ant?
|
---|
241 | </a></li>
|
---|
242 | <li><a href="#multi-conditions">
|
---|
243 | I want to execute a particular target only if
|
---|
244 | multiple conditions are true.
|
---|
245 | </a></li>
|
---|
246 | <li><a href="#encoding">
|
---|
247 | How can I include national characters like German
|
---|
248 | umlauts in my build file?
|
---|
249 | </a></li>
|
---|
250 | <li><a href="#use-zip-instead-of-jar">
|
---|
251 | How do I use <code>jar</code>'s <code>M</code> switch?
|
---|
252 | I don't want a MANIFEST.
|
---|
253 | </a></li>
|
---|
254 | <li><a href="#propertyvalue-as-name-for-property">
|
---|
255 | How can I do something like <code><property name="prop"
|
---|
256 | value="${${anotherprop}}"/></code> (double expanding the property)?
|
---|
257 | </a></li>
|
---|
258 | </ul>
|
---|
259 | <h4 class="toc">It doesn't work (as expected)</h4>
|
---|
260 | <ul>
|
---|
261 | <li><a href="#genral-advice">
|
---|
262 | General Advice
|
---|
263 | </a></li>
|
---|
264 | <li><a href="#always-recompiles">
|
---|
265 | Why does Ant always recompile all my Java files?
|
---|
266 | </a></li>
|
---|
267 | <li><a href="#defaultexcludes">
|
---|
268 | I've used a <code><delete></code> task to
|
---|
269 | delete unwanted SourceSafe control files (CVS files, editor
|
---|
270 | backup files, etc.), but it doesn't seem to work; the files
|
---|
271 | never get deleted. What's wrong?
|
---|
272 | </a></li>
|
---|
273 | <li><a href="#stop-dependency">
|
---|
274 | I have a target I want to skip if a property is set,
|
---|
275 | so I have <code>unless="property"</code> as an attribute
|
---|
276 | of the target, but all the targets this target
|
---|
277 | depends on are still executed. Why?
|
---|
278 | </a></li>
|
---|
279 | <li><a href="#include-order">
|
---|
280 | In my <code><fileset></code>, I've put in an
|
---|
281 | <code><exclude></code> of all files followed by an
|
---|
282 | <code><include></code> of just the files I want, but it
|
---|
283 | isn't giving me any files at all. What's wrong?
|
---|
284 |
|
---|
285 | </a></li>
|
---|
286 | <li><a href="#properties-not-trimmed">
|
---|
287 | <code>ant</code> failed to build my program via javac
|
---|
288 | even when I put the needed jars in an external
|
---|
289 | <code>build.properties</code> file and reference them by
|
---|
290 | <code>pathelement</code> or <code>classpath refid</code>.
|
---|
291 | </a></li>
|
---|
292 | <li><a href="#winzip-lies">
|
---|
293 | Ant creates WAR files with a lower-case
|
---|
294 | <code>web-inf</code> or JAR files with a lower-case
|
---|
295 | <code>meta-inf</code> directory.
|
---|
296 | </a></li>
|
---|
297 | <li><a href="#NoClassDefFoundError">
|
---|
298 | I installed Ant 1.6.x and now get
|
---|
299 | <code>Exception in thread "main" java.lang.NoClassDefFoundError:
|
---|
300 | </code>
|
---|
301 |
|
---|
302 | </a></li>
|
---|
303 | <li><a href="#InstantiationException">
|
---|
304 | I installed Ant 1.6.x and now get
|
---|
305 | <code>java.lang.InstantiationException: org.apache.tools.ant.Main</code>
|
---|
306 |
|
---|
307 | </a></li>
|
---|
308 | <li><a href="#mangled-manifest">
|
---|
309 |
|
---|
310 | Whenever I use the Ant jar or manifest related tasks, long lines in
|
---|
311 | my manifest are wrapped at 70 characters and the resulting jar does
|
---|
312 | not work in my application server. Why does Ant do this?
|
---|
313 |
|
---|
314 | </a></li>
|
---|
315 | </ul>
|
---|
316 | <h4 class="toc">Ant and IDEs/Editors</h4>
|
---|
317 | <ul>
|
---|
318 | <li><a href="#integration">
|
---|
319 | Is Ant supported by my IDE/Editor?
|
---|
320 | </a></li>
|
---|
321 | <li><a href="#emacs-mode">
|
---|
322 | Why doesn't (X)Emacs/vi/MacOS X's project builder
|
---|
323 | correctly parse the error messages generated by Ant?
|
---|
324 | </a></li>
|
---|
325 | </ul>
|
---|
326 | <h4 class="toc">Advanced Issues</h4>
|
---|
327 | <ul>
|
---|
328 | <li><a href="#dtd">
|
---|
329 | Is there a DTD that I can use to validate my build
|
---|
330 | files?
|
---|
331 | </a></li>
|
---|
332 | <li><a href="#xml-entity-include">
|
---|
333 | How do I include an XML snippet in my build file?
|
---|
334 | </a></li>
|
---|
335 | <li><a href="#mail-logger">
|
---|
336 | How do I send an email with the result of my build
|
---|
337 | process?
|
---|
338 | </a></li>
|
---|
339 | <li><a href="#listener-properties">
|
---|
340 | How do I get at the properties that Ant was running
|
---|
341 | with from inside BuildListener?
|
---|
342 | </a></li>
|
---|
343 | </ul>
|
---|
344 | <h4 class="toc">Known Problems</h4>
|
---|
345 | <ul>
|
---|
346 | <li><a href="#remove-cr">
|
---|
347 | <chmod> or <exec> doesn't work in Ant
|
---|
348 | 1.3 on Unix
|
---|
349 | </a></li>
|
---|
350 | <li><a href="#javadoc-cannot-execute">
|
---|
351 | JavaDoc failed: java.io.IOException: javadoc: cannot execute
|
---|
352 | </a></li>
|
---|
353 | <li><a href="#delegating-classloader">
|
---|
354 | <style> or <junit> ignores my
|
---|
355 | <classpath>
|
---|
356 | </a></li>
|
---|
357 | <li><a href="#delegating-classloader-1.5">
|
---|
358 | <style> or <junit> ignores my
|
---|
359 | <classpath> - Ant 1.5.x version
|
---|
360 | </a></li>
|
---|
361 | <li><a href="#delegating-classloader-1.6">
|
---|
362 | <style> or <junit> ignores my
|
---|
363 | <classpath> - Ant 1.6.x version
|
---|
364 | </a></li>
|
---|
365 | <li><a href="#winxp-jdk14-ant14">
|
---|
366 | When running Ant 1.4 on Windows XP and JDK 1.4, I get
|
---|
367 | various errors when trying to <code><exec></code>, fork
|
---|
368 | <code><java></code> or access environment
|
---|
369 | variables.
|
---|
370 | </a></li>
|
---|
371 | <li><a href="#1.5-cygwin-sh">
|
---|
372 | The <code>ant</code> wrapper script of Ant 1.5 fails
|
---|
373 | for Cygwin if <code>ANT_HOME</code> is set to a Windows style
|
---|
374 | path.
|
---|
375 | </a></li>
|
---|
376 | <li><a href="#1.5.2-zip-broken">
|
---|
377 | <code><zip></code> is broken in Ant 1.5.2.
|
---|
378 | </a></li>
|
---|
379 | <li><a href="#unknownelement.taskcontainer">
|
---|
380 |
|
---|
381 | Why do my custom task containers see Unknown Elements in Ant 1.6
|
---|
382 | - they worked in Ant 1.5?
|
---|
383 |
|
---|
384 | </a></li>
|
---|
385 | <li><a href="#java.exception.stacktrace">
|
---|
386 |
|
---|
387 | The program I run via <java> throws an exception but I
|
---|
388 | can't seem to get the full stack trace.
|
---|
389 |
|
---|
390 | </a></li>
|
---|
391 | <li><a href="#junit-no-runtime-xml">
|
---|
392 |
|
---|
393 | Using format="xml", <junit> fails with a
|
---|
394 | <code>NoClassDefFoundError</code> if forked.
|
---|
395 |
|
---|
396 | </a></li>
|
---|
397 | <li><a href="#xalan-jdk1.5">
|
---|
398 |
|
---|
399 | <code><junitreport></code> doesn't work with JDK 1.5 but
|
---|
400 | worked fine with JDK 1.4.
|
---|
401 |
|
---|
402 | </a></li>
|
---|
403 | </ul>
|
---|
404 |
|
---|
405 | <h3 class="section">Answers</h3>
|
---|
406 | <p class="faq">
|
---|
407 | <a name="latest-version"></a>
|
---|
408 | Where do I find the latest version of this
|
---|
409 | document?
|
---|
410 | </p>
|
---|
411 | <p>The latest version can always be found at Ant's homepage
|
---|
412 | <a href="http://ant.apache.org/faq.html">http://ant.apache.org/faq.html</a>.</p>
|
---|
413 | <p class="faq">
|
---|
414 | <a name="adding-faqs"></a>
|
---|
415 | How can I contribute to this FAQ?
|
---|
416 | </p>
|
---|
417 | <p>The page you are looking it is generated from
|
---|
418 | <a href="http://svn.apache.org/repos/asf/ant/core/trunk/xdocs/faq.xml">this</a>
|
---|
419 | document. If you want to add a new question, please submit
|
---|
420 | a patch against this document to one of Ant's mailing lists;
|
---|
421 | hopefully, the structure is self-explanatory.</p>
|
---|
422 | <p>If you don't know how to create a patch, see the patches
|
---|
423 | section of <a href="http://jakarta.apache.org/site/source.html">this
|
---|
424 | page</a>.</p>
|
---|
425 | <p class="faq">
|
---|
426 | <a name="creating-faq"></a>
|
---|
427 | How do you create the HTML version of this
|
---|
428 | FAQ?
|
---|
429 | </p>
|
---|
430 | <p>We use
|
---|
431 | <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a>
|
---|
432 | to render the HTML version from the original XML file.</p>
|
---|
433 | <p>The Velocity stylesheets used to process the XML files can
|
---|
434 | be found in the <code>xdocs/stylesheets</code> subdirectory of
|
---|
435 | Ant's SVN repository - the build file
|
---|
436 | <code>docs.xml</code> at the top level of the ant SVN
|
---|
437 | module (trunk) is used to drive Anakia.</p>
|
---|
438 | <p>This file assumes that you have the
|
---|
439 | <code>jakarta-site2</code> CVS module checked out as well, but
|
---|
440 | if you follow the instruction from Anakia's homepage, you
|
---|
441 | should get it to work without that. Just make sure all
|
---|
442 | required jars are in the task's classpath.</p>
|
---|
443 | <p class="faq">
|
---|
444 | <a name="what-is-ant"></a>
|
---|
445 | What is Apache Ant?
|
---|
446 | </p>
|
---|
447 | <p> Ant is a Java-based build tool. In theory, it is kind of
|
---|
448 | like Make, without Make's wrinkles and with the full
|
---|
449 | portability of pure Java code.</p>
|
---|
450 | <p class="faq">
|
---|
451 | <a name="ant-name"></a>
|
---|
452 | Why do you call it Ant?
|
---|
453 | </p>
|
---|
454 | <p>According to Ant's original author, James Duncan
|
---|
455 | Davidson, the name is an acronym for "Another Neat
|
---|
456 | Tool".</p>
|
---|
457 | <p>Later explanations go along the lines of "ants
|
---|
458 | do an extremely good job at building things", or
|
---|
459 | "ants are very small and can carry a weight dozens of times
|
---|
460 | their own" - describing what Ant is intended to
|
---|
461 | be.</p>
|
---|
462 | <p class="faq">
|
---|
463 | <a name="history"></a>
|
---|
464 | Tell us a little bit about Ant's history.
|
---|
465 | </p>
|
---|
466 | <p>Initially, Ant was part of the Tomcat code base, when it was
|
---|
467 | donated to the Apache Software Foundation. It was
|
---|
468 | created by James Duncan Davidson, who is also the original
|
---|
469 | author of Tomcat. Ant was there to build Tomcat, nothing
|
---|
470 | else.</p>
|
---|
471 | <p>Soon thereafter, several open source Java projects realized
|
---|
472 | that Ant could solve the problems they had with Makefiles.
|
---|
473 | Starting with the projects hosted at Jakarta and the old Java
|
---|
474 | Apache project, Ant spread like a virus and is now the build
|
---|
475 | tool of choice for a lot of projects.</p>
|
---|
476 | <p>In January 2000, Ant was moved to a separate CVS module and
|
---|
477 | was promoted to a project of its own, independent of
|
---|
478 | Tomcat, and became Apache Ant.</p>
|
---|
479 | <p>The first version of Ant that was exposed to a larger audience
|
---|
480 | was the one that shipped with Tomcat's 3.1 release on 19 April
|
---|
481 | 2000. This version has later been referred to as Ant
|
---|
482 | 0.3.1.</p>
|
---|
483 | <p>The first official release of Ant as a stand-alone product was
|
---|
484 | Ant 1.1, released on 19 July 2000. The complete release
|
---|
485 | history:</p>
|
---|
486 | <table class="ForrestTable" cellspacing="1" cellpadding="4">
|
---|
487 | <tr>
|
---|
488 | <th colspan="1" rowspan="1"
|
---|
489 | valign="top" align="left">
|
---|
490 | Ant Version
|
---|
491 | </th>
|
---|
492 | <th colspan="1" rowspan="1"
|
---|
493 | valign="top" align="left">
|
---|
494 | Release Date
|
---|
495 | </th>
|
---|
496 | </tr>
|
---|
497 | <tr>
|
---|
498 | <td colspan="1" rowspan="1"
|
---|
499 | valign="top" align="left">
|
---|
500 | 1.1
|
---|
501 | </td>
|
---|
502 | <td colspan="1" rowspan="1"
|
---|
503 | valign="top" align="left">
|
---|
504 | 19 July 2000
|
---|
505 | </td>
|
---|
506 | </tr>
|
---|
507 | <tr>
|
---|
508 | <td colspan="1" rowspan="1"
|
---|
509 | valign="top" align="left">
|
---|
510 | 1.2
|
---|
511 | </td>
|
---|
512 | <td colspan="1" rowspan="1"
|
---|
513 | valign="top" align="left">
|
---|
514 | 24 October 2000
|
---|
515 | </td>
|
---|
516 | </tr>
|
---|
517 | <tr>
|
---|
518 | <td colspan="1" rowspan="1"
|
---|
519 | valign="top" align="left">
|
---|
520 | 1.3
|
---|
521 | </td>
|
---|
522 | <td colspan="1" rowspan="1"
|
---|
523 | valign="top" align="left">
|
---|
524 | 3 March 2001
|
---|
525 | </td>
|
---|
526 | </tr>
|
---|
527 | <tr>
|
---|
528 | <td colspan="1" rowspan="1"
|
---|
529 | valign="top" align="left">
|
---|
530 | 1.4
|
---|
531 | </td>
|
---|
532 | <td colspan="1" rowspan="1"
|
---|
533 | valign="top" align="left">
|
---|
534 | 3 September 2001
|
---|
535 | </td>
|
---|
536 | </tr>
|
---|
537 | <tr>
|
---|
538 | <td colspan="1" rowspan="1"
|
---|
539 | valign="top" align="left">
|
---|
540 | 1.4.1
|
---|
541 | </td>
|
---|
542 | <td colspan="1" rowspan="1"
|
---|
543 | valign="top" align="left">
|
---|
544 | 11 October 2001
|
---|
545 | </td>
|
---|
546 | </tr>
|
---|
547 | <tr>
|
---|
548 | <td colspan="1" rowspan="1"
|
---|
549 | valign="top" align="left">
|
---|
550 | 1.5
|
---|
551 | </td>
|
---|
552 | <td colspan="1" rowspan="1"
|
---|
553 | valign="top" align="left">
|
---|
554 | 10 July 2002
|
---|
555 | </td>
|
---|
556 | </tr>
|
---|
557 | <tr>
|
---|
558 | <td colspan="1" rowspan="1"
|
---|
559 | valign="top" align="left">
|
---|
560 | 1.5.1
|
---|
561 | </td>
|
---|
562 | <td colspan="1" rowspan="1"
|
---|
563 | valign="top" align="left">
|
---|
564 | 3 October 2002
|
---|
565 | </td>
|
---|
566 | </tr>
|
---|
567 | <tr>
|
---|
568 | <td colspan="1" rowspan="1"
|
---|
569 | valign="top" align="left">
|
---|
570 | 1.5.2
|
---|
571 | </td>
|
---|
572 | <td colspan="1" rowspan="1"
|
---|
573 | valign="top" align="left">
|
---|
574 | 3 March 2003
|
---|
575 | </td>
|
---|
576 | </tr>
|
---|
577 | <tr>
|
---|
578 | <td colspan="1" rowspan="1"
|
---|
579 | valign="top" align="left">
|
---|
580 | 1.5.3
|
---|
581 | </td>
|
---|
582 | <td colspan="1" rowspan="1"
|
---|
583 | valign="top" align="left">
|
---|
584 | 9 April 2003
|
---|
585 | </td>
|
---|
586 | </tr>
|
---|
587 | <tr>
|
---|
588 | <td colspan="1" rowspan="1"
|
---|
589 | valign="top" align="left">
|
---|
590 | 1.5.4
|
---|
591 | </td>
|
---|
592 | <td colspan="1" rowspan="1"
|
---|
593 | valign="top" align="left">
|
---|
594 | 12 August 2003
|
---|
595 | </td>
|
---|
596 | </tr>
|
---|
597 | <tr>
|
---|
598 | <td colspan="1" rowspan="1"
|
---|
599 | valign="top" align="left">
|
---|
600 | 1.6.0
|
---|
601 | </td>
|
---|
602 | <td colspan="1" rowspan="1"
|
---|
603 | valign="top" align="left">
|
---|
604 | 18 December 2003
|
---|
605 | </td>
|
---|
606 | </tr>
|
---|
607 | <tr>
|
---|
608 | <td colspan="1" rowspan="1"
|
---|
609 | valign="top" align="left">
|
---|
610 | 1.6.1
|
---|
611 | </td>
|
---|
612 | <td colspan="1" rowspan="1"
|
---|
613 | valign="top" align="left">
|
---|
614 | 12 February 2004
|
---|
615 | </td>
|
---|
616 | </tr>
|
---|
617 | <tr>
|
---|
618 | <td colspan="1" rowspan="1"
|
---|
619 | valign="top" align="left">
|
---|
620 | 1.6.2
|
---|
621 | </td>
|
---|
622 | <td colspan="1" rowspan="1"
|
---|
623 | valign="top" align="left">
|
---|
624 | 16 July 2004
|
---|
625 | </td>
|
---|
626 | </tr>
|
---|
627 | <tr>
|
---|
628 | <td colspan="1" rowspan="1"
|
---|
629 | valign="top" align="left">
|
---|
630 | 1.6.3
|
---|
631 | </td>
|
---|
632 | <td colspan="1" rowspan="1"
|
---|
633 | valign="top" align="left">
|
---|
634 | 28 April 2005
|
---|
635 | </td>
|
---|
636 | </tr>
|
---|
637 | <tr>
|
---|
638 | <td colspan="1" rowspan="1"
|
---|
639 | valign="top" align="left">
|
---|
640 | 1.6.4
|
---|
641 | </td>
|
---|
642 | <td colspan="1" rowspan="1"
|
---|
643 | valign="top" align="left">
|
---|
644 | 19 May 2005
|
---|
645 | </td>
|
---|
646 | </tr>
|
---|
647 | <tr>
|
---|
648 | <td colspan="1" rowspan="1"
|
---|
649 | valign="top" align="left">
|
---|
650 | 1.6.5
|
---|
651 | </td>
|
---|
652 | <td colspan="1" rowspan="1"
|
---|
653 | valign="top" align="left">
|
---|
654 | 2 June 2005
|
---|
655 | </td>
|
---|
656 | </tr>
|
---|
657 | <tr>
|
---|
658 | <td colspan="1" rowspan="1"
|
---|
659 | valign="top" align="left">
|
---|
660 | 1.7.0
|
---|
661 | </td>
|
---|
662 | <td colspan="1" rowspan="1"
|
---|
663 | valign="top" align="left">
|
---|
664 | 19 December 2006
|
---|
665 | </td>
|
---|
666 | </tr>
|
---|
667 | </table>
|
---|
668 | <p class="faq">
|
---|
669 | <a name="no-gnu-tar"></a>
|
---|
670 | I get checksum errors when I try to extract the
|
---|
671 | <code>tar.gz</code> distribution file. Why?
|
---|
672 | </p>
|
---|
673 | <p>Ant's distribution contains file names that are longer
|
---|
674 | than 100 characters, which is not supported by the standard
|
---|
675 | tar file format. Several different implementations of tar use
|
---|
676 | different and incompatible ways to work around this
|
---|
677 | restriction.</p>
|
---|
678 | <p>Ant's <tar> task can create tar archives that use
|
---|
679 | the GNU tar extension, and this has been used when putting
|
---|
680 | together the distribution. If you are using a different
|
---|
681 | version of tar (for example, the one shipping with Solaris),
|
---|
682 | you cannot use it to extract the archive.</p>
|
---|
683 | <p>The solution is to either install GNU tar, which can be
|
---|
684 | found <a href="http://www.gnu.org/software/tar/tar.html">here</a>,
|
---|
685 | or use the zip archive instead (you can extract it using
|
---|
686 | <code>jar xf</code>).</p>
|
---|
687 | <p class="faq">
|
---|
688 | <a name="RedHat_ES_3"></a>
|
---|
689 | How do you get ant-1.6.x (or any version later than
|
---|
690 | 1.5.2) to work on on RedHat ES 3?
|
---|
691 | </p>
|
---|
692 | <p>Redhat ES 3.0 comes installed with ant 1.5.2. Even if you
|
---|
693 | have your PATH and ANT_HOME variables set correctly to a later
|
---|
694 | version of ant, you will always be forced to use the
|
---|
695 | preinstalled version.</p>
|
---|
696 | <p>To use a later version of ant on this OS you could do the
|
---|
697 | following:</p>
|
---|
698 | <pre class="code">
|
---|
699 | $ ant -version
|
---|
700 | Apache Ant version 1.5.2-23 compiled on November 12 2003
|
---|
701 | $ su -
|
---|
702 | # rpm -e ant ant-libs
|
---|
703 | # exit
|
---|
704 | $ hash -r
|
---|
705 | $ ant -version
|
---|
706 | Apache Ant version 1.6.2 compiled on July 16 2004
|
---|
707 | </pre>
|
---|
708 | <p class="faq">
|
---|
709 | <a name="implement-os-specific-configuration"></a>
|
---|
710 | How do I realize os--specific configurations?
|
---|
711 | </p>
|
---|
712 | <p>The core idea is using property files which name accords to the
|
---|
713 | os-name. Then simply use the build-in property <tt>os.name</tt>.</p>
|
---|
714 | <p>For better use you should also provide a file with defaul values.
|
---|
715 | But be careful with the correct os-names. For test simply <echo>
|
---|
716 | the ${os.name} on all machines and you can be sure to use the right
|
---|
717 | file names.</p>
|
---|
718 | <pre class="code">
|
---|
719 | <property file="${os.name}.properties"/>
|
---|
720 | <property file="default.properties"/>
|
---|
721 | </pre>
|
---|
722 | <p class="faq">
|
---|
723 | <a name="adding-external-tasks"></a>
|
---|
724 | How do I add an external task that I've written to the
|
---|
725 | page "External Tools and Tasks"?
|
---|
726 | </p>
|
---|
727 | <p>Join and post a message to the dev or user mailing
|
---|
728 | list (one list is enough), including the following
|
---|
729 | information:</p>
|
---|
730 | <ul>
|
---|
731 | <li>the name of the task/tool</li>
|
---|
732 | <li>a short description of the task/tool</li>
|
---|
733 | <li>a Compatibility: entry stating with which version(s) of
|
---|
734 | Ant the tool/task is compatible to</li>
|
---|
735 | <li>a URL: entry linking to the main page of the tool/task</li>
|
---|
736 | <li>a Contact: entry containing the email address or the URL
|
---|
737 | of a webpage for the person or list to contact for issues
|
---|
738 | related to the tool/task. <strong>Note that we'll add a
|
---|
739 | link on the page, so any email address added there is not
|
---|
740 | obfuscated and can (and probably will) be abused by robots
|
---|
741 | harvesting websites for addresses to spam.</strong></li>
|
---|
742 | <li>a License: entry containing the type of license for the
|
---|
743 | tool/task</li>
|
---|
744 | </ul>
|
---|
745 | <p>The preferred format for this information is a patch to <a href="http://svn.apache.org/repos/asf/ant/core/trunk/xdocs/external.xml">this</a>
|
---|
746 | document.</p>
|
---|
747 | <p>If you have written something bigger than a 'simple plugin' to Ant it
|
---|
748 | may be better to add the link to <a href="projects.html">projects.html</a>.
|
---|
749 | The procedure to add it is the same. The file to patch is <a href="http://svn.apache.org/repos/asf/ant/core/trunk/xdocs/projects.xml">this</a>
|
---|
750 | document. The syntax of that file is the same.</p>
|
---|
751 | <p class="faq">
|
---|
752 | <a name="create-extensions"></a>
|
---|
753 | How do I create new tasks?
|
---|
754 | </p>
|
---|
755 | <p>Apart from a lot of information on using Ant, the
|
---|
756 | <a href="manual/index.html">Manual</a> also contains information
|
---|
757 | on how to extend Ant with new tasks. This information
|
---|
758 | can be found under "Developing with Ant".</p>
|
---|
759 | <p>Chances are that someone else already created the task you
|
---|
760 | want to create, it may be wise to see
|
---|
761 | <a href="external.html">External Tools and Tasks</a> and
|
---|
762 | <a href="projects.html">Related Projects</a> first.</p>
|
---|
763 | <p class="faq">
|
---|
764 | <a name="passing-cli-args"></a>
|
---|
765 | How do I pass parameters from the command line to my
|
---|
766 | build file?
|
---|
767 | </p>
|
---|
768 | <p>Use properties. Using <code>ant
|
---|
769 | -D<em>name</em>=<em>value</em></code> lets you define values for
|
---|
770 | properties on the Ant command line. These properties can then be
|
---|
771 | used within your build file as
|
---|
772 | any normal property: <code>${<em>name</em>}</code> will put in
|
---|
773 | <code><em>value</em></code>.</p>
|
---|
774 | <p class="faq">
|
---|
775 | <a name="jikes-switches"></a>
|
---|
776 | How can I use Jikes-specific command-line
|
---|
777 | switches?
|
---|
778 | </p>
|
---|
779 | <p>A couple of switches are supported via "magic"
|
---|
780 | properties:</p>
|
---|
781 | <table class="ForrestTable" cellspacing="1" cellpadding="4">
|
---|
782 | <tr>
|
---|
783 | <th colspan="1" rowspan="1"
|
---|
784 | valign="top" align="left">
|
---|
785 | switch
|
---|
786 | </th>
|
---|
787 | <th colspan="1" rowspan="1"
|
---|
788 | valign="top" align="left">
|
---|
789 | property
|
---|
790 | </th>
|
---|
791 | <th colspan="1" rowspan="1"
|
---|
792 | valign="top" align="left">
|
---|
793 | default
|
---|
794 | </th>
|
---|
795 | </tr>
|
---|
796 | <tr>
|
---|
797 | <td colspan="1" rowspan="1"
|
---|
798 | valign="top" align="left">
|
---|
799 | +E
|
---|
800 | </td>
|
---|
801 | <td colspan="1" rowspan="1"
|
---|
802 | valign="top" align="left">
|
---|
803 | build.compiler.emacs
|
---|
804 | </td>
|
---|
805 | <td colspan="1" rowspan="1"
|
---|
806 | valign="top" align="left">
|
---|
807 | false == not set
|
---|
808 | </td>
|
---|
809 | </tr>
|
---|
810 | <tr>
|
---|
811 | <td colspan="1" rowspan="1"
|
---|
812 | valign="top" align="left">
|
---|
813 | +P
|
---|
814 | </td>
|
---|
815 | <td colspan="1" rowspan="1"
|
---|
816 | valign="top" align="left">
|
---|
817 | build.compiler.pedantic
|
---|
818 | </td>
|
---|
819 | <td colspan="1" rowspan="1"
|
---|
820 | valign="top" align="left">
|
---|
821 | false == not set
|
---|
822 | </td>
|
---|
823 | </tr>
|
---|
824 | <tr>
|
---|
825 | <td colspan="1" rowspan="1"
|
---|
826 | valign="top" align="left">
|
---|
827 | +F
|
---|
828 | </td>
|
---|
829 | <td colspan="1" rowspan="1"
|
---|
830 | valign="top" align="left">
|
---|
831 | build.compiler.fulldepend
|
---|
832 | </td>
|
---|
833 | <td colspan="1" rowspan="1"
|
---|
834 | valign="top" align="left">
|
---|
835 | false == not set
|
---|
836 | </td>
|
---|
837 | </tr>
|
---|
838 | <tr>
|
---|
839 | <td colspan="1" rowspan="1"
|
---|
840 | valign="top" align="left">
|
---|
841 | <strong>(Only for Ant < 1.4; replaced by the
|
---|
842 | <code><strong>nowarn</strong></code>
|
---|
843 | attribute of the <code><strong><javac></strong></code>
|
---|
844 | task after that.)</strong><br />-nowarn
|
---|
845 | </td>
|
---|
846 | <td colspan="1" rowspan="1"
|
---|
847 | valign="top" align="left">
|
---|
848 | build.compiler.warnings
|
---|
849 | </td>
|
---|
850 | <td colspan="1" rowspan="1"
|
---|
851 | valign="top" align="left">
|
---|
852 | true == not set
|
---|
853 | </td>
|
---|
854 | </tr>
|
---|
855 | </table>
|
---|
856 | <p>With Ant >= 1.5, you can also use nested
|
---|
857 | <code><compilerarg></code> elements with the
|
---|
858 | <code><javac></code> task.</p>
|
---|
859 | <p class="faq">
|
---|
860 | <a name="shell-redirect-1"></a>
|
---|
861 | How do I include a < character in my command-line arguments?
|
---|
862 | </p>
|
---|
863 | <p>The short answer is "Use: <code>&lt;</code>".</p>
|
---|
864 | <p>The long answer is that this probably won't do what you
|
---|
865 | want anyway (see <a href="#shell-redirect-2">the next
|
---|
866 | section</a>).</p>
|
---|
867 | <p class="faq">
|
---|
868 | <a name="shell-redirect-2"></a>
|
---|
869 | How do I redirect standard input or standard output
|
---|
870 | in the <code><exec></code> task?
|
---|
871 | </p>
|
---|
872 | <p>Say you want to redirect the standard output stream of the
|
---|
873 | <code>m4</code> command to write to a file, something
|
---|
874 | like:</p>
|
---|
875 | <pre class="code">
|
---|
876 | shell-prompt> m4 foo.m4 > foo
|
---|
877 | </pre>
|
---|
878 | <p>and try to translate it into</p>
|
---|
879 | <pre class="code">
|
---|
880 | <exec executable="m4">
|
---|
881 | <arg value="foo.m4"/>
|
---|
882 | <arg value="&gt;"/>
|
---|
883 | <arg value="foo"/>
|
---|
884 | </exec>
|
---|
885 | </pre>
|
---|
886 | <p>This will not do what you expect. The output redirection is
|
---|
887 | performed by your shell, not the command itself, so this
|
---|
888 | should read:</p>
|
---|
889 | <pre class="code">
|
---|
890 | <exec executable="/bin/sh">
|
---|
891 | <arg value="-c" />
|
---|
892 | <arg value="m4 foo.m4 &gt; foo" />
|
---|
893 | </exec>
|
---|
894 | </pre>
|
---|
895 | <p>Note that you must use the <code>value</code> attribute of
|
---|
896 | <code><arg></code> in the last element, in order to have
|
---|
897 | the command passed as a single, quoted argument. Alternatively,
|
---|
898 | you can use:</p>
|
---|
899 | <pre class="code">
|
---|
900 | <exec executable="/bin/sh">
|
---|
901 | <arg line='-c "m4 foo.m4 &gt; foo"'/>
|
---|
902 | </exec>
|
---|
903 | </pre>
|
---|
904 | <p>Note the double-quotes nested inside the single-quotes.</p>
|
---|
905 | <p class="faq">
|
---|
906 | <a name="batch-shell-execute"></a>
|
---|
907 | How do I execute a batch file or shell script from Ant?
|
---|
908 | </p>
|
---|
909 | <p>On native Unix systems, you should be able to run shell scripts
|
---|
910 | directly. On systems running a Unix-type shell (for example, Cygwin
|
---|
911 | on Windows) execute the (command) shell instead - <code>cmd</code>
|
---|
912 | for batch files, <code>sh</code> for shell scripts - then pass the
|
---|
913 | batch file or shell script (plus any arguments to the script)
|
---|
914 | as a single command, using the <code>/c</code> or
|
---|
915 | <code>-c</code> switch, respectively. See
|
---|
916 | <a href="#shell-redirect-2">the above section</a>
|
---|
917 | for example <code><exec></code> tasks
|
---|
918 | executing <code>sh</code>. For batch files, use something like:</p>
|
---|
919 | <pre class="code">
|
---|
920 | <exec dir="." executable="cmd" os="Windows NT">
|
---|
921 | <arg line="/c test.bat"/>
|
---|
922 | </exec>
|
---|
923 | </pre>
|
---|
924 | <p class="faq">
|
---|
925 | <a name="multi-conditions"></a>
|
---|
926 | I want to execute a particular target only if
|
---|
927 | multiple conditions are true.
|
---|
928 | </p>
|
---|
929 | <p>There are actually several answers to this question.</p>
|
---|
930 | <p>If you have only one set and one unset property to test,
|
---|
931 | you can specify both an <code>if</code> and an <code>unless</code>
|
---|
932 | attribute for the target, and they will act as if they
|
---|
933 | are "anded" together.</p>
|
---|
934 | <p>If you are using a version of Ant 1.3 or earlier, the
|
---|
935 | way to work with all other cases is to chain targets together
|
---|
936 | to determine the specific state you want to test for.</p>
|
---|
937 | <p>To see how this works, assume you have three properties:
|
---|
938 | <code>prop1</code>, <code>prop2</code>, and <code>prop3</code>.
|
---|
939 | You want to test that <code>prop1</code> and <code>prop2</code>
|
---|
940 | are set, and that <code>prop3</code> is not. If the condition
|
---|
941 | holds true you want to echo "yes".</p>
|
---|
942 | <p>Here is the implementation in Ant 1.3 and earlier:</p>
|
---|
943 | <pre class="code">
|
---|
944 | <target name="cond" depends="cond-if"/>
|
---|
945 |
|
---|
946 | <target name="cond-if" if="prop1">
|
---|
947 | <antcall target="cond-if-2"/>
|
---|
948 | </target>
|
---|
949 |
|
---|
950 | <target name="cond-if-2" if="prop2">
|
---|
951 | <antcall target="cond-if-3"/>
|
---|
952 | </target>
|
---|
953 |
|
---|
954 | <target name="cond-if-3" unless="prop3">
|
---|
955 | <echo message="yes"/>
|
---|
956 | </target>
|
---|
957 | </pre>
|
---|
958 | <p>Note: <code><antcall></code> tasks do <em>not</em> pass
|
---|
959 | property changes back up to the environment they were called
|
---|
960 | from, so you wouldn't be able to, for example, set a
|
---|
961 | <code>result</code> property in the <code>cond-if-3</code> target,
|
---|
962 | then do
|
---|
963 | <code><echo message="result is ${result}"/></code>
|
---|
964 | in the <code>cond</code> target.</p>
|
---|
965 | <p>Starting with Ant 1.4, you can use the
|
---|
966 | <code><condition></code> task.</p>
|
---|
967 | <pre class="code">
|
---|
968 | <target name="cond" depends="cond-if,cond-else"/>
|
---|
969 |
|
---|
970 | <target name="check-cond">
|
---|
971 | <condition property="cond-is-true">
|
---|
972 | <and>
|
---|
973 | <not>
|
---|
974 | <equals arg1="${prop1}" arg2="$${prop1}" />
|
---|
975 | </not>
|
---|
976 | <not>
|
---|
977 | <equals arg1="${prop2}" arg2="$${prop2}" />
|
---|
978 | </not>
|
---|
979 | <equals arg1="${prop3}" arg2="$${prop3}" />
|
---|
980 | </and>
|
---|
981 | </condition>
|
---|
982 | </target>
|
---|
983 |
|
---|
984 | <target name="cond-if" depends="check-cond" if="cond-is-true">
|
---|
985 | <echo message="yes"/>
|
---|
986 | </target>
|
---|
987 |
|
---|
988 | <target name="cond-else" depends="check-cond" unless="cond-is-true">
|
---|
989 | <echo message="no"/>
|
---|
990 | </target>
|
---|
991 | </pre>
|
---|
992 | <p>This version takes advantage of two things:</p>
|
---|
993 | <ul>
|
---|
994 | <li>If a property <code>a</code> has not been set,
|
---|
995 | <code>${a}</code> will evaluate to <code>${a}</code>.</li>
|
---|
996 |
|
---|
997 | <li>To get a literal <code>$</code> in Ant, you have to
|
---|
998 | escape it with another <code>$</code> - this will also break
|
---|
999 | the special treatment of the <code>${</code> sequence.</li>
|
---|
1000 | </ul>
|
---|
1001 | <p>Because testing for a literal <code>${property}</code> string
|
---|
1002 | isn't all that readable or easy to understand,
|
---|
1003 | post-1.4.1 Ant introduces the <code><isset></code> element
|
---|
1004 | to the <code><condition></code> task.</p>
|
---|
1005 | <p>Here is the previous example done using
|
---|
1006 | <code><isset></code>:</p>
|
---|
1007 | <pre class="code">
|
---|
1008 | <target name="check-cond">
|
---|
1009 | <condition property="cond-is-true">
|
---|
1010 | <and>
|
---|
1011 | <isset property="prop1"/>
|
---|
1012 | <isset property="prop2"/>
|
---|
1013 | <not>
|
---|
1014 | <isset property="prop3"/>
|
---|
1015 | </not>
|
---|
1016 | </and>
|
---|
1017 | </condition>
|
---|
1018 | </target>
|
---|
1019 | </pre>
|
---|
1020 | <p>The last option is to use a scripting language to set the
|
---|
1021 | properties. This can be particularly handy when you need much
|
---|
1022 | finer control than the simple conditions shown here but, of
|
---|
1023 | course, comes with the overhead of adding JAR files to support
|
---|
1024 | the language, to say nothing of the added maintenance in requiring
|
---|
1025 | two languages to implement a single system. See the
|
---|
1026 | <a href="manual/OptionalTasks/script.html">
|
---|
1027 | <code><script></code> task documentation</a> for more
|
---|
1028 | details.</p>
|
---|
1029 | <p class="faq">
|
---|
1030 | <a name="encoding"></a>
|
---|
1031 | How can I include national characters like German
|
---|
1032 | umlauts in my build file?
|
---|
1033 | </p>
|
---|
1034 | <p>You need to tell the XML parser which character encoding
|
---|
1035 | your build file uses, this is done inside the <a href="http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd">XML
|
---|
1036 | declaration</a>.</p>
|
---|
1037 | <p>By default the parser assumes you are using the UTF-8
|
---|
1038 | encoding instead of your platform's default. For most Western
|
---|
1039 | European countries you should set the encoding to
|
---|
1040 | <code>ISO-8859-1</code>. To do so, make the very first line
|
---|
1041 | of you build file read like</p>
|
---|
1042 | <pre class="code">
|
---|
1043 | <?xml version="1.0" encoding="ISO-8859-1" ?>
|
---|
1044 | </pre>
|
---|
1045 | <p class="faq">
|
---|
1046 | <a name="use-zip-instead-of-jar"></a>
|
---|
1047 | How do I use <code>jar</code>'s <code>M</code> switch?
|
---|
1048 | I don't want a MANIFEST.
|
---|
1049 | </p>
|
---|
1050 | <p>A JAR archive is a ZIP file, so if you don't want a
|
---|
1051 | MANIFEST you can simply use <code><zip></code>.</p>
|
---|
1052 | <p>If your file names contain national characters you should
|
---|
1053 | know that Sun's <code>jar</code> utility like Ant's
|
---|
1054 | <code><jar></code> uses UTF-8 to encode their names while
|
---|
1055 | <code><zip></code> uses your platforms default encoding.
|
---|
1056 | Use the encoding attribute of <code><zip></code> if
|
---|
1057 | necessary.</p>
|
---|
1058 | <p class="faq">
|
---|
1059 | <a name="propertyvalue-as-name-for-property"></a>
|
---|
1060 | How can I do something like <code><property name="prop"
|
---|
1061 | value="${${anotherprop}}"/></code> (double expanding the property)?
|
---|
1062 | </p>
|
---|
1063 | <p>Without any external help you can not.</p>
|
---|
1064 | <p>With <script/>, which needs external libraries, you can do</p>
|
---|
1065 | <pre class="code">
|
---|
1066 | <script language="javascript">
|
---|
1067 | propname = project.getProperty("anotherprop");
|
---|
1068 | project.setNewProperty("prop", propname);
|
---|
1069 | </script>
|
---|
1070 | </pre>
|
---|
1071 | <p>With AntContrib (external task library) you can do <code>
|
---|
1072 | <propertycopy name="prop" from="${anotherprop}"/></code>.</p>
|
---|
1073 | <p>With Ant 1.6 you can simulate the AntContribs <propertycopy>
|
---|
1074 | and avoid the need of an external library:</p>
|
---|
1075 | <pre class="code">
|
---|
1076 | <macrodef name="propertycopy">
|
---|
1077 | <attribute name="name"/>
|
---|
1078 | <attribute name="from"/>
|
---|
1079 | <sequential>
|
---|
1080 | <property name="@{name}" value="${@{from}}"/>
|
---|
1081 | </sequential>
|
---|
1082 | </macrodef>
|
---|
1083 | </pre>
|
---|
1084 | <p class="faq">
|
---|
1085 | <a name="genral-advice"></a>
|
---|
1086 | General Advice
|
---|
1087 | </p>
|
---|
1088 | <p>There are many reasons why Ant doesn't behave as
|
---|
1089 | expected, not all of them are due to Ant bugs. See our <a href="problems.html">Having Problems?</a> page for hints that
|
---|
1090 | may help pinning down the reasons for your problem.</p>
|
---|
1091 | <p class="faq">
|
---|
1092 | <a name="always-recompiles"></a>
|
---|
1093 | Why does Ant always recompile all my Java files?
|
---|
1094 | </p>
|
---|
1095 | <p>In order to find out which files should be compiled, Ant
|
---|
1096 | compares the timestamps of the source files to those of the
|
---|
1097 | resulting <code>.class</code> files. Opening all source files
|
---|
1098 | to find out which package they belong to would be very
|
---|
1099 | inefficient. Instead, Ant expects you to place your
|
---|
1100 | source files in a directory hierarchy that mirrors your
|
---|
1101 | package hierarchy and to point Ant to the root of this
|
---|
1102 | directory tree with the <code>srcdir</code> attribute.</p>
|
---|
1103 | <p>Say you have <code><javac srcdir="src"
|
---|
1104 | destdir="dest"/></code>. If Ant finds a file
|
---|
1105 | <code>src/a/b/C.java</code>, it expects it to be in package
|
---|
1106 | <code>a.b</code> so that the resulting <code>.class</code>
|
---|
1107 | file is going to be <code>dest/a/b/C.class</code>.</p>
|
---|
1108 | <p>If your source-tree directory structure does not match your
|
---|
1109 | package structure, Ant's heuristic won't work, and
|
---|
1110 | it will recompile classes that are up-to-date. Ant is not the
|
---|
1111 | only tool that expects a source-tree layout like this.</p>
|
---|
1112 | <p>If you have Java source files that aren't declared to
|
---|
1113 | be part of any package, you can still use the <code><javac></code>
|
---|
1114 | task to compile these files correctly - just set the
|
---|
1115 | <code>srcdir</code> and <code>destdir</code> attributes to
|
---|
1116 | the actual directory the source
|
---|
1117 | files live in and the directory the class files should go into,
|
---|
1118 | respectively.</p>
|
---|
1119 | <p class="faq">
|
---|
1120 | <a name="defaultexcludes"></a>
|
---|
1121 | I've used a <code><delete></code> task to
|
---|
1122 | delete unwanted SourceSafe control files (CVS files, editor
|
---|
1123 | backup files, etc.), but it doesn't seem to work; the files
|
---|
1124 | never get deleted. What's wrong?
|
---|
1125 | </p>
|
---|
1126 | <p>This is probably happening because, by default, Ant excludes
|
---|
1127 | SourceSafe control files (<code>vssver.scc</code>) and certain other
|
---|
1128 | files from FileSets.</p>
|
---|
1129 | <p>Here's what you probably did:</p>
|
---|
1130 | <pre class="code">
|
---|
1131 | <delete>
|
---|
1132 | <fileset dir="${build.src}" includes="**/vssver.scc"/>
|
---|
1133 | </delete>
|
---|
1134 | </pre>
|
---|
1135 | <p>You need to switch off the default exclusions,
|
---|
1136 | and it will work:</p>
|
---|
1137 | <pre class="code">
|
---|
1138 | <delete>
|
---|
1139 | <fileset dir="${build.src}" includes="**/vssver.scc"
|
---|
1140 | defaultexcludes="no"/>
|
---|
1141 | </delete>
|
---|
1142 | </pre>
|
---|
1143 | <p>For a complete listing of the patterns that are excluded
|
---|
1144 | by default, see <a href="manual/dirtasks.html#defaultexcludes">the user
|
---|
1145 | manual</a>.</p>
|
---|
1146 | <p class="faq">
|
---|
1147 | <a name="stop-dependency"></a>
|
---|
1148 | I have a target I want to skip if a property is set,
|
---|
1149 | so I have <code>unless="property"</code> as an attribute
|
---|
1150 | of the target, but all the targets this target
|
---|
1151 | depends on are still executed. Why?
|
---|
1152 | </p>
|
---|
1153 | <p>The list of dependencies is generated by Ant before any of the
|
---|
1154 | targets are run. This allows dependent targets, such as an
|
---|
1155 | <code>init</code> target, to set properties that can control the
|
---|
1156 | execution of the targets higher in the dependency graph. This
|
---|
1157 | is a good thing.</p>
|
---|
1158 | <p>However, when your dependencies break down the
|
---|
1159 | higher-level task
|
---|
1160 | into several smaller steps, this behaviour becomes
|
---|
1161 | counter-intuitive. There are a couple of solutions available:
|
---|
1162 | </p>
|
---|
1163 | <ol>
|
---|
1164 | <li>Put the same condition on each of the dependent targets.</li>
|
---|
1165 |
|
---|
1166 | <li>Execute the steps using <code><antcall></code>,
|
---|
1167 | instead of specifying them inside the <code>depends</code>
|
---|
1168 | attribute.</li>
|
---|
1169 | </ol>
|
---|
1170 | <p class="faq">
|
---|
1171 | <a name="include-order"></a>
|
---|
1172 | In my <code><fileset></code>, I've put in an
|
---|
1173 | <code><exclude></code> of all files followed by an
|
---|
1174 | <code><include></code> of just the files I want, but it
|
---|
1175 | isn't giving me any files at all. What's wrong?
|
---|
1176 |
|
---|
1177 | </p>
|
---|
1178 | <p>The order of the <code><include></code> and
|
---|
1179 | <code><exclude></code> tags within a <code><fileset></code>
|
---|
1180 | is ignored when the FileSet is created. Instead, all of the
|
---|
1181 | <code><include></code> elements are processed together,
|
---|
1182 | followed by all of the <code><exclude></code>
|
---|
1183 | elements. This means that the <code><exclude></code>
|
---|
1184 | elements only apply to the file list produced by the
|
---|
1185 | <code><include></code> elements.</p>
|
---|
1186 | <p>To get the files you want, focus on just the
|
---|
1187 | <code><include></code> patterns that would be necessary
|
---|
1188 | to get them. If you find you need to trim the list that the
|
---|
1189 | <code><include></code> elements produce, then use
|
---|
1190 | <code><exclude></code> elements.</p>
|
---|
1191 | <p class="faq">
|
---|
1192 | <a name="properties-not-trimmed"></a>
|
---|
1193 | <code>ant</code> failed to build my program via javac
|
---|
1194 | even when I put the needed jars in an external
|
---|
1195 | <code>build.properties</code> file and reference them by
|
---|
1196 | <code>pathelement</code> or <code>classpath refid</code>.
|
---|
1197 | </p>
|
---|
1198 | <p>When <code>ant</code> loads properties from an external
|
---|
1199 | file it doesn't touch the value of properties, trailing blanks
|
---|
1200 | will not be trimmed for example.</p>
|
---|
1201 | <p>If the value represents a file path, like a jar needed to
|
---|
1202 | compile, the task which requires the value, javac for example
|
---|
1203 | would fail to compile since it can't find the file due to
|
---|
1204 | trailing spaces.</p>
|
---|
1205 | <p class="faq">
|
---|
1206 | <a name="winzip-lies"></a>
|
---|
1207 | Ant creates WAR files with a lower-case
|
---|
1208 | <code>web-inf</code> or JAR files with a lower-case
|
---|
1209 | <code>meta-inf</code> directory.
|
---|
1210 | </p>
|
---|
1211 | <p>No it doesn't.</p>
|
---|
1212 | <p>You may have seen these lower-case directory names in
|
---|
1213 | WinZIP, but WinZIP is trying to be helpful (and fails). If
|
---|
1214 | WinZIP encounters a filename that is all upper-case, it
|
---|
1215 | assumes it has come from an old DOS box and changes the case to
|
---|
1216 | all lower-case for you.</p>
|
---|
1217 | <p>If you extract (or just check) the archive with jar, you
|
---|
1218 | will see that the names have the correct case.</p>
|
---|
1219 | <p>With WinZIP (version 8.1 at least), this can be corrected in the
|
---|
1220 | configuration. In the Options/Configuration menu, in the View tab, General
|
---|
1221 | section, check the "Allow all upper case files names" box. The META-INF and
|
---|
1222 | WEB-INF will look correct.</p>
|
---|
1223 | <p class="faq">
|
---|
1224 | <a name="NoClassDefFoundError"></a>
|
---|
1225 | I installed Ant 1.6.x and now get
|
---|
1226 | <code>Exception in thread "main" java.lang.NoClassDefFoundError:
|
---|
1227 | </code>
|
---|
1228 |
|
---|
1229 | </p>
|
---|
1230 | <p>
|
---|
1231 | The cause of this is that there is an old version of ant somewhere in the
|
---|
1232 | class path or configuration.
|
---|
1233 | </p>
|
---|
1234 | <p>
|
---|
1235 | A version of this problem happens with jars that are in the classpath
|
---|
1236 | that include an embedded copy of ant classes.
|
---|
1237 | An example of this is some copies of weblogic.jar.
|
---|
1238 | </p>
|
---|
1239 | <p>
|
---|
1240 | One can check if this is the case by doing (on unix/sh):
|
---|
1241 | <code><pre>
|
---|
1242 | unset CLASSPATH
|
---|
1243 | ant -version
|
---|
1244 | </pre>
|
---|
1245 | </code>
|
---|
1246 | </p>
|
---|
1247 | <p class="faq">
|
---|
1248 | <a name="InstantiationException"></a>
|
---|
1249 | I installed Ant 1.6.x and now get
|
---|
1250 | <code>java.lang.InstantiationException: org.apache.tools.ant.Main</code>
|
---|
1251 |
|
---|
1252 | </p>
|
---|
1253 | <p>
|
---|
1254 | The cause of this is that there is an old version of ant somewhere in the
|
---|
1255 | class path or configuration.
|
---|
1256 | </p>
|
---|
1257 | <p>
|
---|
1258 | A version of this problem may be seen on some linux systems.
|
---|
1259 | Some linux systems (Fedora Core 2 for example), comes with a version
|
---|
1260 | of ant pre-installed. There is a configuration file called
|
---|
1261 | <code>/etc/ant.conf</code> which if present, the ant shell
|
---|
1262 | script will 'dot' include. On Fedora Core 2, the /etc/ant.conf
|
---|
1263 | file resets the <code>ANT_HOME</code> environment variable to
|
---|
1264 | <code>/usr/share/ant</code>. This causes the problem that
|
---|
1265 | an old version of ant (1.5.x in this cause) will be used
|
---|
1266 | with a new version of the ant script file.
|
---|
1267 | </p>
|
---|
1268 | <p>
|
---|
1269 | One can check if this is the case by doing
|
---|
1270 | <code>ant --noconfig -version</code>.
|
---|
1271 | </p>
|
---|
1272 | <p class="faq">
|
---|
1273 | <a name="mangled-manifest"></a>
|
---|
1274 |
|
---|
1275 | Whenever I use the Ant jar or manifest related tasks, long lines in
|
---|
1276 | my manifest are wrapped at 70 characters and the resulting jar does
|
---|
1277 | not work in my application server. Why does Ant do this?
|
---|
1278 |
|
---|
1279 | </p>
|
---|
1280 | <p>
|
---|
1281 | Ant implements the Java
|
---|
1282 | <a href="http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html">Jar
|
---|
1283 | file specification</a>. Please refer to the notes section where it
|
---|
1284 | discusses the maximum allowable length of a line and the concept of
|
---|
1285 | continuation characters.
|
---|
1286 | </p>
|
---|
1287 | <p>
|
---|
1288 | If a jar file produced by Ant does not work in your appserver, and
|
---|
1289 | that failure is due to the wrapped manifest, then you need
|
---|
1290 | to consult your appserver provider, as it is a bug in their
|
---|
1291 | appserver. Far more likely, however, is a problem in your
|
---|
1292 | specification of your classpath. It is not Ant's wrapping of your
|
---|
1293 | classpath that is the problem.
|
---|
1294 | </p>
|
---|
1295 | <p>
|
---|
1296 | Do not raise a bug about this issue until you have checked to ensure
|
---|
1297 | that the problem is not due to your classpath specification.
|
---|
1298 | </p>
|
---|
1299 | <p class="faq">
|
---|
1300 | <a name="integration"></a>
|
---|
1301 | Is Ant supported by my IDE/Editor?
|
---|
1302 | </p>
|
---|
1303 | <p>See the <a href="external.html#IDE and Editor Integration">section
|
---|
1304 | on IDE integration</a> on our External Tools and Tasks page.</p>
|
---|
1305 | <p class="faq">
|
---|
1306 | <a name="emacs-mode"></a>
|
---|
1307 | Why doesn't (X)Emacs/vi/MacOS X's project builder
|
---|
1308 | correctly parse the error messages generated by Ant?
|
---|
1309 | </p>
|
---|
1310 | <p>Ant adds a "banner" with the name of the current
|
---|
1311 | task in front of all logging messages - and there are no built-in
|
---|
1312 | regular expressions in your editor that would account for
|
---|
1313 | this.</p>
|
---|
1314 | <p>You can disable this banner by invoking Ant with the
|
---|
1315 | <code>-emacs</code> switch. To make Ant autodetect
|
---|
1316 | Emacs' compile mode, put this into your
|
---|
1317 | <code>.antrc</code> (contributed by Ville Skyttä).</p>
|
---|
1318 | <pre class="code">
|
---|
1319 | # Detect (X)Emacs compile mode
|
---|
1320 | if [ "$EMACS" = "t" ] ; then
|
---|
1321 | ANT_ARGS="$ANT_ARGS -emacs"
|
---|
1322 | ANT_OPTS="$ANT_OPTS -Dbuild.compiler.emacs=true"
|
---|
1323 | fi
|
---|
1324 | </pre>
|
---|
1325 | <p>Alternatively, you can add the following snippet to your
|
---|
1326 | <code>.emacs</code> to make Emacs understand Ant's
|
---|
1327 | output.</p>
|
---|
1328 | <pre class="code">
|
---|
1329 | (require 'compile)
|
---|
1330 | (setq compilation-error-regexp-alist
|
---|
1331 | (append (list
|
---|
1332 | ;; works for jikes
|
---|
1333 | '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3)
|
---|
1334 | ;; works for javac
|
---|
1335 | '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2))
|
---|
1336 | compilation-error-regexp-alist))
|
---|
1337 | </pre>
|
---|
1338 | <p>Yet another alternative that preserves most of Ant's
|
---|
1339 | formatting is to pipe Ant's output through the following Perl
|
---|
1340 | script by Dirk-Willem van Gulik:</p>
|
---|
1341 | <pre class="code">
|
---|
1342 | #!/usr/bin/perl
|
---|
1343 | #
|
---|
1344 | # May 2001 [email protected] - remove any
|
---|
1345 | # [foo] lines from the output; keeping
|
---|
1346 | # spacing more or less there.
|
---|
1347 | #
|
---|
1348 | $|=1;
|
---|
1349 | while(<STDIN>) {
|
---|
1350 | if (s/^(\s+)\[(\w+)\]//) {
|
---|
1351 | if ($2 ne $last) {
|
---|
1352 | print "$1\[$2\]";
|
---|
1353 | $s = ' ' x length($2);
|
---|
1354 | } else {
|
---|
1355 | print "$1 $s ";
|
---|
1356 | };
|
---|
1357 | $last = $2;
|
---|
1358 | };
|
---|
1359 | print;
|
---|
1360 | };
|
---|
1361 | </pre>
|
---|
1362 | <p class="faq">
|
---|
1363 | <a name="dtd"></a>
|
---|
1364 | Is there a DTD that I can use to validate my build
|
---|
1365 | files?
|
---|
1366 | </p>
|
---|
1367 | <p>An incomplete DTD can be created by the
|
---|
1368 | <code><antstructure></code> task - but this one
|
---|
1369 | has a few problems:</p>
|
---|
1370 | <ul>
|
---|
1371 | <li>It doesn't know about required attributes. Only
|
---|
1372 | manual tweaking of this file can help here.</li>
|
---|
1373 |
|
---|
1374 | <li>It is not complete - if you add new tasks via
|
---|
1375 | <code><taskdef></code> it won't know about it. See
|
---|
1376 | <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this
|
---|
1377 | page</a> by Michel Casabianca for a solution to this
|
---|
1378 | problem. Note that the DTD you can download at this page
|
---|
1379 | is based on Ant 0.3.1.</li>
|
---|
1380 |
|
---|
1381 | <li>It may even be an invalid DTD. As Ant allows tasks
|
---|
1382 | writers to define arbitrary elements, name collisions will
|
---|
1383 | happen quite frequently - if your version of Ant contains
|
---|
1384 | the optional <code><test></code> and
|
---|
1385 | <code><junit></code> tasks, there are two XML
|
---|
1386 | elements named <code>test</code> (the task and the nested child
|
---|
1387 | element of <code><junit></code>) with different attribute
|
---|
1388 | lists. This problem cannot be solved; DTDs don't give a
|
---|
1389 | syntax rich enough to support this.</li>
|
---|
1390 | </ul>
|
---|
1391 | <p class="faq">
|
---|
1392 | <a name="xml-entity-include"></a>
|
---|
1393 | How do I include an XML snippet in my build file?
|
---|
1394 | </p>
|
---|
1395 | <p>You can use XML's way of including external files and let
|
---|
1396 | the parser do the job for Ant:</p>
|
---|
1397 | <pre class="code">
|
---|
1398 | <?xml version="1.0"?>
|
---|
1399 |
|
---|
1400 | <!DOCTYPE project [
|
---|
1401 | <!ENTITY common SYSTEM "common.xml">
|
---|
1402 | ]>
|
---|
1403 |
|
---|
1404 | <project name="test" default="test" basedir=".">
|
---|
1405 |
|
---|
1406 | <target name="setup">
|
---|
1407 | ...
|
---|
1408 | </target>
|
---|
1409 |
|
---|
1410 | &common;
|
---|
1411 |
|
---|
1412 | ...
|
---|
1413 |
|
---|
1414 | </project>
|
---|
1415 | </pre>
|
---|
1416 | <p>will literally include the contents of <code>common.xml</code> where
|
---|
1417 | you've placed the <code>&common;</code> entity.</p>
|
---|
1418 | <p>(The filename <code>common.xml</code> in this example is resolved
|
---|
1419 | relative to the containing XML file by the XML parser. You may also use
|
---|
1420 | an absolute <code>file:</code> protocol URI.)</p>
|
---|
1421 | <p>In combination with a DTD, this would look like this:</p>
|
---|
1422 | <pre class="code">
|
---|
1423 | <!DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "ant.dtd" [
|
---|
1424 | <!ENTITY include SYSTEM "header.xml">
|
---|
1425 | ]>
|
---|
1426 | </pre>
|
---|
1427 | <p>Starting with Ant 1.6, there is a new
|
---|
1428 | <code><import></code> task that can (also) be used to
|
---|
1429 | include build file fragments. Unlike the snippets used with
|
---|
1430 | entity includes, the referenced files have to be complete Ant
|
---|
1431 | build files, though.</p>
|
---|
1432 | <p>The example above would become:</p>
|
---|
1433 | <pre class="code">
|
---|
1434 | <?xml version="1.0"?>
|
---|
1435 | <project name="test" default="test" basedir=".">
|
---|
1436 |
|
---|
1437 | <target name="setup">
|
---|
1438 | ...
|
---|
1439 | </target>
|
---|
1440 |
|
---|
1441 | <import file="./common.xml"/>
|
---|
1442 |
|
---|
1443 | ...
|
---|
1444 |
|
---|
1445 | </project>
|
---|
1446 | </pre>
|
---|
1447 | <p>Unlike entity includes, <code><import></code> will
|
---|
1448 | let you use Ant properties in the file name.</p>
|
---|
1449 | <p class="faq">
|
---|
1450 | <a name="mail-logger"></a>
|
---|
1451 | How do I send an email with the result of my build
|
---|
1452 | process?
|
---|
1453 | </p>
|
---|
1454 | <p>If you are using a nightly build of Ant 1.5 after
|
---|
1455 | 2001-12-14, you can use the built-in MailLogger:</p>
|
---|
1456 | <pre class="code">
|
---|
1457 | ant -logger org.apache.tools.ant.listener.MailLogger
|
---|
1458 | </pre>
|
---|
1459 | <p>See the <a href="http://svn.apache.org/repos/asf/ant/core/trunk/docs/manual/listeners.html">Listeners
|
---|
1460 | & Loggers</a> documentation for details on the properties
|
---|
1461 | required.</p>
|
---|
1462 | <p>For older versions of Ant, you can use a custom
|
---|
1463 | BuildListener that sends out an email
|
---|
1464 | in the buildFinished() method. Will Glozer
|
---|
1465 | <[email protected]> has written such a listener based
|
---|
1466 | on <a href="http://java.sun.com/products/javamail/">JavaMail</a>.
|
---|
1467 | The source is:</p>
|
---|
1468 | <pre class="code">
|
---|
1469 | import java.io.*;
|
---|
1470 | import java.util.*;
|
---|
1471 | import javax.mail.*;
|
---|
1472 | import javax.mail.internet.*;
|
---|
1473 | import org.apache.tools.ant.*;
|
---|
1474 |
|
---|
1475 | /**
|
---|
1476 | * A simple listener that waits for a build to finish and sends an email
|
---|
1477 | * of the results. The settings are stored in "monitor.properties" and
|
---|
1478 | * are fairly self explanatory.
|
---|
1479 | *
|
---|
1480 | * @author Will Glozer
|
---|
1481 | * @version 1.05a 09/06/2000
|
---|
1482 | */
|
---|
1483 | public class BuildMonitor implements BuildListener {
|
---|
1484 | protected Properties props;
|
---|
1485 |
|
---|
1486 | /**
|
---|
1487 | * Create a new BuildMonitor.
|
---|
1488 | */
|
---|
1489 | public BuildMonitor() throws Exception {
|
---|
1490 | props = new Properties();
|
---|
1491 | InputStream is = getClass().getResourceAsStream("monitor.properties");
|
---|
1492 | props.load(is);
|
---|
1493 | is.close();
|
---|
1494 | }
|
---|
1495 |
|
---|
1496 | public void buildStarted(BuildEvent e) {
|
---|
1497 | }
|
---|
1498 |
|
---|
1499 | /**
|
---|
1500 | * Determine the status of the build and the actions to follow, now that
|
---|
1501 | * the build has completed.
|
---|
1502 | *
|
---|
1503 | * @param e Event describing the build status.
|
---|
1504 | */
|
---|
1505 | public void buildFinished(BuildEvent e) {
|
---|
1506 | Throwable th = e.getException();
|
---|
1507 | String status = (th != null) ? "failed" : "succeeded";
|
---|
1508 |
|
---|
1509 | try {
|
---|
1510 | String key = "build." + status;
|
---|
1511 | if (props.getProperty(key + ".notify").equalsIgnoreCase("false")) {
|
---|
1512 | return;
|
---|
1513 | }
|
---|
1514 |
|
---|
1515 | Session session = Session.getDefaultInstance(props, null);
|
---|
1516 |
|
---|
1517 | MimeMessage message = new MimeMessage(session);
|
---|
1518 | message.addRecipients(Message.RecipientType.TO, parseAddresses(
|
---|
1519 | props.getProperty(key + ".email.to")));
|
---|
1520 | message.setSubject(props.getProperty(key + ".email.subject"));
|
---|
1521 |
|
---|
1522 | BufferedReader br = new BufferedReader(new FileReader(
|
---|
1523 | props.getProperty("build.log")));
|
---|
1524 | StringWriter sw = new StringWriter();
|
---|
1525 |
|
---|
1526 | String line = br.readLine();
|
---|
1527 | while (line != null) {
|
---|
1528 | sw.write(line);
|
---|
1529 | sw.write("\n");
|
---|
1530 | line = br.readLine();
|
---|
1531 | }
|
---|
1532 | br.close();
|
---|
1533 |
|
---|
1534 | message.setText(sw.toString(), "UTF-8");
|
---|
1535 | sw.close();
|
---|
1536 |
|
---|
1537 | Transport transport = session.getTransport();
|
---|
1538 | transport.connect();
|
---|
1539 | transport.send(message);
|
---|
1540 | transport.close();
|
---|
1541 | } catch (Exception ex) {
|
---|
1542 | System.out.println("BuildMonitor failed to send email!");
|
---|
1543 | ex.printStackTrace();
|
---|
1544 | }
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | /**
|
---|
1548 | * Parse a comma separated list of internet email addresses.
|
---|
1549 | *
|
---|
1550 | * @param s The list of addresses.
|
---|
1551 | * @return Array of Addresses.
|
---|
1552 | */
|
---|
1553 | protected Address[] parseAddresses(String s) throws Exception {
|
---|
1554 | StringTokenizer st = new StringTokenizer(s, ",");
|
---|
1555 | Address[] addrs = new Address[st.countTokens()];
|
---|
1556 |
|
---|
1557 | for (int i = 0; i < addrs.length; i++) {
|
---|
1558 | addrs[i] = new InternetAddress(st.nextToken());
|
---|
1559 | }
|
---|
1560 | return addrs;
|
---|
1561 | }
|
---|
1562 |
|
---|
1563 | public void messageLogged(BuildEvent e) {
|
---|
1564 | }
|
---|
1565 |
|
---|
1566 | public void targetStarted(BuildEvent e) {
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | public void targetFinished(BuildEvent e) {
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | public void taskStarted(BuildEvent e) {
|
---|
1573 | }
|
---|
1574 |
|
---|
1575 | public void taskFinished(BuildEvent e) {
|
---|
1576 | }
|
---|
1577 | }
|
---|
1578 | </pre>
|
---|
1579 | <p>With a <code>monitor.properties</code> like this:</p>
|
---|
1580 | <pre class="code">
|
---|
1581 | # configuration for build monitor
|
---|
1582 |
|
---|
1583 | mail.transport.protocol=smtp
|
---|
1584 | mail.smtp.host=<host>
|
---|
1585 | mail.from=Will Glozer <[email protected]>
|
---|
1586 |
|
---|
1587 | build.log=build.log
|
---|
1588 |
|
---|
1589 | build.failed.notify=true
|
---|
1590 | [email protected]
|
---|
1591 | build.failed.email.subject=Nightly build failed!
|
---|
1592 |
|
---|
1593 | build.succeeded.notify=true
|
---|
1594 | [email protected]
|
---|
1595 | build.succeeded.email.subject=Nightly build succeeded!
|
---|
1596 | </pre>
|
---|
1597 | <p><code>monitor.properties</code> should be placed right next
|
---|
1598 | to your compiled <code>BuildMonitor.class</code>. To use it,
|
---|
1599 | invoke Ant like:</p>
|
---|
1600 | <pre class="code">
|
---|
1601 | ant -listener BuildMonitor -logfile build.log
|
---|
1602 | </pre>
|
---|
1603 | <p>Make sure that <code>mail.jar</code> from JavaMail and
|
---|
1604 | <code>activation.jar</code> from the
|
---|
1605 | <a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java
|
---|
1606 | Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p>
|
---|
1607 | <p class="faq">
|
---|
1608 | <a name="listener-properties"></a>
|
---|
1609 | How do I get at the properties that Ant was running
|
---|
1610 | with from inside BuildListener?
|
---|
1611 | </p>
|
---|
1612 | <p>You can get at a hashtable with all the properties that Ant
|
---|
1613 | has been using through the BuildEvent parameter. For
|
---|
1614 | example:</p>
|
---|
1615 | <pre class="code">
|
---|
1616 | public void buildFinished(BuildEvent e) {
|
---|
1617 | Hashtable table = e.getProject().getProperties();
|
---|
1618 | String buildpath = (String)table.get("build.path");
|
---|
1619 | ...
|
---|
1620 | }
|
---|
1621 | </pre>
|
---|
1622 | <p>This is more accurate than just reading the same property
|
---|
1623 | files that your project does, since it will give the correct
|
---|
1624 | results for properties that were specified on the Ant command line.</p>
|
---|
1625 | <p class="faq">
|
---|
1626 | <a name="remove-cr"></a>
|
---|
1627 | <chmod> or <exec> doesn't work in Ant
|
---|
1628 | 1.3 on Unix
|
---|
1629 | </p>
|
---|
1630 | <p>The <code>antRun</code> script in <code>ANT_HOME/bin</code>
|
---|
1631 | has DOS instead of Unix line endings; you must remove the
|
---|
1632 | carriage-return characters from this file. This can be done by
|
---|
1633 | using Ant's <code><fixcrlf></code> task
|
---|
1634 | or something like:</p>
|
---|
1635 | <pre class="code">
|
---|
1636 | tr -d '\r' < $ANT_HOME/bin/antRun > /tmp/foo
|
---|
1637 | mv /tmp/foo $ANT_HOME/bin/antRun
|
---|
1638 | </pre>
|
---|
1639 | <p class="faq">
|
---|
1640 | <a name="javadoc-cannot-execute"></a>
|
---|
1641 | JavaDoc failed: java.io.IOException: javadoc: cannot execute
|
---|
1642 | </p>
|
---|
1643 | <p>There is a bug in the Solaris reference implementation of
|
---|
1644 | 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>).
|
---|
1645 | This also appears to be true under Linux. Moving the JDK to
|
---|
1646 | the front of the PATH fixes the problem.</p>
|
---|
1647 | <p class="faq">
|
---|
1648 | <a name="delegating-classloader"></a>
|
---|
1649 | <style> or <junit> ignores my
|
---|
1650 | <classpath>
|
---|
1651 | </p>
|
---|
1652 | <p>Starting with Ant 1.7.0, <junit> will honor your
|
---|
1653 | nested <classpath>.</p>
|
---|
1654 | <p>These tasks don't ignore your classpath setting, you
|
---|
1655 | are facing a common problem with delegating classloaders.</p>
|
---|
1656 | <p>This question collects a common type of problem: A task
|
---|
1657 | needs an external library and it has a nested classpath
|
---|
1658 | element so that you can point it to this external library, but
|
---|
1659 | that doesn't work unless you put the external library
|
---|
1660 | into the <code>CLASSPATH</code> or place it in
|
---|
1661 | <code>ANT_HOME/lib</code>.</p>
|
---|
1662 | <p>Some background is necessary before we can discuss
|
---|
1663 | solutions for <a href="#delegating-classloader-1.5">Ant
|
---|
1664 | 1.5.x</a> and <a href="#delegating-classloader-1.6">Ant
|
---|
1665 | 1.6.x</a>.</p>
|
---|
1666 | <p>When you specify a nested <code><classpath></code> in
|
---|
1667 | Ant, Ant creates a new class loader that uses the path you
|
---|
1668 | have specified. It then tries to load additional classes from
|
---|
1669 | this classloader.</p>
|
---|
1670 | <p>In most cases - for example using <style> or
|
---|
1671 | <junit> - Ant doesn't load the external library
|
---|
1672 | directly, it is the loaded class that does so.</p>
|
---|
1673 | <p>In the case of <code><junit></code> it is the task
|
---|
1674 | implementation itself and in the case of
|
---|
1675 | <code><style></code> it is the implementation of the
|
---|
1676 | <code>org.apache.tools.ant.taskdefs.XSLTLiaison</code>
|
---|
1677 | class.</p>
|
---|
1678 | <p><em>As of Ant 1.7</em> <code><junit></code> no longer
|
---|
1679 | requires you to have <code>junit.jar</code> in Ant's startup
|
---|
1680 | classpath even if <code>ant-junit.jar</code> is present there.</p>
|
---|
1681 | <p>Ant's class loader implementation uses Java's
|
---|
1682 | delegation model, see <a href="http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html">http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html</a>
|
---|
1683 | the paragraph</p>
|
---|
1684 | <blockquote>The <code>ClassLoader</code> class uses a
|
---|
1685 | delegation model to search for classes and resources. Each
|
---|
1686 | instance of <code>ClassLoader</code> has an associated parent
|
---|
1687 | class loader. When called upon to find a class or resource, a
|
---|
1688 | <code>ClassLoader</code> instance will delegate the search for
|
---|
1689 | the class or resource to its parent class loader before
|
---|
1690 | attempting to find the class or resource itself. The virtual
|
---|
1691 | machine's built-in class loader, called the bootstrap
|
---|
1692 | class loader, does not itself have a parent but may serve as
|
---|
1693 | the parent of a <code>ClassLoader</code>
|
---|
1694 | instance.</blockquote>
|
---|
1695 | <p>The possible solutions depend on the version of Ant you
|
---|
1696 | use, see the next sections.</p>
|
---|
1697 | <p class="faq">
|
---|
1698 | <a name="delegating-classloader-1.5"></a>
|
---|
1699 | <style> or <junit> ignores my
|
---|
1700 | <classpath> - Ant 1.5.x version
|
---|
1701 | </p>
|
---|
1702 | <p>Please read <a href="#delegating-classloader">the previous
|
---|
1703 | entry</a> before you go ahead.</p>
|
---|
1704 | <p>First of all let's state that Ant's wrapper script
|
---|
1705 | (<code>ant</code> or <code>ant.bat</code>) adds all
|
---|
1706 | <code>.jar</code> files from <code>ANT_HOME/lib</code> to
|
---|
1707 | <code>CLASSPATH</code>, therefore "in
|
---|
1708 | <code>CLASSPATH</code>" shall mean "either in your
|
---|
1709 | <code>CLASSPATH</code> environment variable or
|
---|
1710 | <code>ANT_HOME/lib</code>" for the rest of this
|
---|
1711 | answer.</p>
|
---|
1712 | <p>The root of the problem is that the class that needs the
|
---|
1713 | external library is on the <code>CLASSPATH</code>.</p>
|
---|
1714 | <p>Let's see what happens when you load the <junit>
|
---|
1715 | task. Ant's class loader will consult the
|
---|
1716 | bootstrap class loader first, which tries to load classes from
|
---|
1717 | <code>CLASSPATH</code>. The bootstrap class loader
|
---|
1718 | doesn't know anything about Ant's class loader or
|
---|
1719 | even the path you have specified.</p>
|
---|
1720 | <p>If the bootstrap class loader can load the class Ant has
|
---|
1721 | asked it to load (which it can if <code>optional.jar</code> is
|
---|
1722 | part of <code>CLASSPATH</code>), this class will try to load
|
---|
1723 | the external library from <code>CLASSPATH</code> as well - it
|
---|
1724 | doesn't know anything else - and will not find it unless
|
---|
1725 | the library is in <code>CLASSPATH</code> as well.</p>
|
---|
1726 | <p>To solve this, you have two major options:</p>
|
---|
1727 | <ol>
|
---|
1728 | <li>put all external libraries you need in
|
---|
1729 | <code>CLASSPATH</code> as well this is not what you want,
|
---|
1730 | otherwise you wouldn't have found this FAQ entry.</li>
|
---|
1731 |
|
---|
1732 | <li>remove the class that loads the external library from
|
---|
1733 | the <code>CLASSPATH</code>.</li>
|
---|
1734 | </ol>
|
---|
1735 | <p>The easiest way to do this is to remove
|
---|
1736 | <code>optional.jar</code> from <code>ANT_HOME/lib</code>. If
|
---|
1737 | you do so, you will have to <code><taskdef></code> all
|
---|
1738 | optional tasks and use nested <code><classpath></code>
|
---|
1739 | elements in the <code><taskdef></code> tasks that point
|
---|
1740 | to the new location of <code>optional.jar</code>. Also,
|
---|
1741 | don't forget to add the new location of
|
---|
1742 | <code>optional.jar</code> to the
|
---|
1743 | <code><classpath></code> of your
|
---|
1744 | <code><style></code> or <code><junit></code>
|
---|
1745 | task.</p>
|
---|
1746 | <p>If you want to avoid to <code><taskdef></code> all
|
---|
1747 | optional tasks you need, the only other option is to remove
|
---|
1748 | the classes that should not be loaded via the bootstrap class
|
---|
1749 | loader from <code>optional.jar</code> and put them into a
|
---|
1750 | separate archive. Add this separate archive to the
|
---|
1751 | <code><classpath></code> of your
|
---|
1752 | <code><style></code> or <code><junit></code> task
|
---|
1753 | - and make sure the separate archive is not in
|
---|
1754 | <code>CLASSPATH</code>.</p>
|
---|
1755 | <p>In the case of <code><junit></code> you'd have
|
---|
1756 | to remove all classes that are in the
|
---|
1757 | <code>org/apache/tools/ant/taskdefs/optional/junit</code>
|
---|
1758 | directory, in the <code><style></code> case it is one of
|
---|
1759 | the <code>*Liaison</code> classes in
|
---|
1760 | <code>org/apache/tools/ant/taskdefs/optional</code>.</p>
|
---|
1761 | <p>If you use the option to break up <code>optional.jar</code>
|
---|
1762 | for <code><junit></code> or remove
|
---|
1763 | <code>ant-junit.jar</code>, you still have to use a
|
---|
1764 | <code><taskdef></code> with a nested
|
---|
1765 | <code><classpath></code> to define the junit task.</p>
|
---|
1766 | <p class="faq">
|
---|
1767 | <a name="delegating-classloader-1.6"></a>
|
---|
1768 | <style> or <junit> ignores my
|
---|
1769 | <classpath> - Ant 1.6.x version
|
---|
1770 | </p>
|
---|
1771 | <p>Please read <a href="#delegating-classloader">the general
|
---|
1772 | entry</a> before you go ahead.</p>
|
---|
1773 | <p>The wrapper script of Ant 1.6.x no longer adds the contents
|
---|
1774 | of <code>ANT_HOME/lib</code> to <code>CLASSPATH</code>,
|
---|
1775 | instead Ant will create a classloader on top of the bootstrap
|
---|
1776 | classloader - let's call it the coreloader for the rest of
|
---|
1777 | this answer - which holds the contents of
|
---|
1778 | <code>ANT_HOME/lib</code>. Ant's core and its tasks will be
|
---|
1779 | loaded through this classloader and not the bootstrap
|
---|
1780 | classloader.</p>
|
---|
1781 | <p>This causes some small but notable differences between Ant
|
---|
1782 | 1.5.x and 1.6.x. Most importantly, a third-party task that is
|
---|
1783 | part of <code>CLASSPATH</code> will no longer work in Ant
|
---|
1784 | 1.6.x since the task now can't find Ant's classes. In a sense
|
---|
1785 | this is the same problem this entry is about, only
|
---|
1786 | <code>ant.jar</code> has become the external library in
|
---|
1787 | question now.</p>
|
---|
1788 | <p>This coreloader also holds the contents of
|
---|
1789 | <code>~/.ant/lib</code> and any file or directory that has
|
---|
1790 | been specified using Ant's <code>-lib</code> command line
|
---|
1791 | argument.</p>
|
---|
1792 | <p>Let's see what happens when you load the <junit>
|
---|
1793 | task. Ant's class loader will consult the bootstrap
|
---|
1794 | class loader first, which tries to load classes from
|
---|
1795 | <code>CLASSPATH</code>. The bootstrap class loader
|
---|
1796 | doesn't know anything about Ant's class loader or
|
---|
1797 | even the path you have specified. If it fails to find the
|
---|
1798 | class using the bootstrap classloader it will try the
|
---|
1799 | coreloader next. Again, the coreloader doesn't know anything
|
---|
1800 | about your path.</p>
|
---|
1801 | <p>If the coreloader can load the class Ant has asked it to
|
---|
1802 | load (which it can if <code>ant-junit.jar</code> is in
|
---|
1803 | <code>ANT_HOME/lib</code>), this class will try to load the
|
---|
1804 | external library from coreloader as well - it doesn't
|
---|
1805 | know anything else - and will not find it unless the library
|
---|
1806 | is in <code>CLASSPATH</code> or the coreloader as well.</p>
|
---|
1807 | <p>To solve this, you have the following major options:</p>
|
---|
1808 | <ol>
|
---|
1809 | <li>put all external libraries you need in
|
---|
1810 | <code>CLASSPATH</code> as well this is not what you want,
|
---|
1811 | otherwise you wouldn't have found this FAQ entry.</li>
|
---|
1812 |
|
---|
1813 | <li>put all external libraries you need in
|
---|
1814 | <code>ANT_HOME/lib</code> or <code>.ant/lib</code>. This
|
---|
1815 | probably still isn't what you want, but you might reconsider
|
---|
1816 | the <code>.ant/lib</code> option.</li>
|
---|
1817 |
|
---|
1818 | <li>Always start Ant with the <code>-lib</code> command line
|
---|
1819 | switch and point to your external libraries (or the
|
---|
1820 | directories holding them).</li>
|
---|
1821 |
|
---|
1822 | <li>remove the class that loads the external library from
|
---|
1823 | the coreloader.</li>
|
---|
1824 | </ol>
|
---|
1825 | <p>In Ant 1.6 <code>optional.jar</code> has been split into
|
---|
1826 | multiple jars, each one containing classes with the same
|
---|
1827 | dependencies on external libraries. You can move the
|
---|
1828 | "offending" jar out of <code>ANT_HOME/lib</code>. For the
|
---|
1829 | <code><junit></code> task it would be
|
---|
1830 | <code>ant-junit.jar</code> and for <code><style></code>
|
---|
1831 | it would be <code>ant-trax.jar</code>
|
---|
1832 | or <code>ant-xslp.jar</code> -
|
---|
1833 | depending on the processor you use.</p>
|
---|
1834 | <p>If you do so, you will have to <code><taskdef></code>
|
---|
1835 | all optional tasks that need the external library and use
|
---|
1836 | nested <code><classpath></code> elements in the
|
---|
1837 | <code><taskdef></code> tasks that point to the new
|
---|
1838 | location of <code>ant-*.jar</code>. Also, don't forget
|
---|
1839 | to add the new location of <code>ant-*.jar</code> to the
|
---|
1840 | <code><classpath></code> of your
|
---|
1841 | <code><style></code> or <code><junit></code>
|
---|
1842 | task.</p>
|
---|
1843 | <p>For example</p>
|
---|
1844 | <pre class="code">
|
---|
1845 | <taskdef name="junit"
|
---|
1846 | class="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
|
---|
1847 | <classpath>
|
---|
1848 | <pathelement location="HOME-OF/junit.jar"/>
|
---|
1849 | <pathelement location="NEW-HOME-OF/ant-junit.jar"/>
|
---|
1850 | </classpath>
|
---|
1851 | </taskdef>
|
---|
1852 | </pre>
|
---|
1853 | <p class="faq">
|
---|
1854 | <a name="winxp-jdk14-ant14"></a>
|
---|
1855 | When running Ant 1.4 on Windows XP and JDK 1.4, I get
|
---|
1856 | various errors when trying to <code><exec></code>, fork
|
---|
1857 | <code><java></code> or access environment
|
---|
1858 | variables.
|
---|
1859 | </p>
|
---|
1860 | <p>Ant < 1.5 doesn't recognize Windows XP as a flavor
|
---|
1861 | of Windows that runs <code>CMD.EXE</code> instead of
|
---|
1862 | <code>COMMAND.COM</code>. JDK 1.3 will tell Ant that Windows
|
---|
1863 | XP is Windows 2000 so the problem doesn't show up
|
---|
1864 | there.</p>
|
---|
1865 | <p>Apart from upgrading to Ant 1.5 or better, setting the
|
---|
1866 | environment variable <code>ANT_OPTS</code> to
|
---|
1867 | <code>-Dos.name=Windows_NT</code> prior to invoking Ant has
|
---|
1868 | been confirmed as a workaround.</p>
|
---|
1869 | <p class="faq">
|
---|
1870 | <a name="1.5-cygwin-sh"></a>
|
---|
1871 | The <code>ant</code> wrapper script of Ant 1.5 fails
|
---|
1872 | for Cygwin if <code>ANT_HOME</code> is set to a Windows style
|
---|
1873 | path.
|
---|
1874 | </p>
|
---|
1875 | <p>This problem has been reported only hours after Ant 1.5 has
|
---|
1876 | been released, see <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=10664">Bug
|
---|
1877 | 10664</a> and all its duplicates.</p>
|
---|
1878 | <p>A fixed version of the wrapper script can be found <a href="http://ant.apache.org/old-releases/v1.5/errata/">here</a>.
|
---|
1879 | Simply replace your script with this version.</p>
|
---|
1880 | <p class="faq">
|
---|
1881 | <a name="1.5.2-zip-broken"></a>
|
---|
1882 | <code><zip></code> is broken in Ant 1.5.2.
|
---|
1883 | </p>
|
---|
1884 | <p>Yes, it is.</p>
|
---|
1885 | <p>The problem reported by most people - see <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17648">Bug
|
---|
1886 | 17648</a> and all its duplicates - is that Ant creates
|
---|
1887 | archives that a partially unreadable by WinZIP. Luckily
|
---|
1888 | <code>jar</code> deals with the archives and so the generated
|
---|
1889 | jars/wars/ears will most likely work for you anyway.</p>
|
---|
1890 | <p>There are additional problems, see bugs <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17780">Bug
|
---|
1891 | 17780</a>, <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17871">Bug
|
---|
1892 | 17871</a> and <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=18403">Bug
|
---|
1893 | 18403</a>. All of them are supposed to be fixed with Ant
|
---|
1894 | 1.5.3 (and only 18403 should exist in 1.5.3beta1).</p>
|
---|
1895 | <p class="faq">
|
---|
1896 | <a name="unknownelement.taskcontainer"></a>
|
---|
1897 |
|
---|
1898 | Why do my custom task containers see Unknown Elements in Ant 1.6
|
---|
1899 | - they worked in Ant 1.5?
|
---|
1900 |
|
---|
1901 | </p>
|
---|
1902 | <p>
|
---|
1903 | The objects added in TaskContainer.addTask(Task task)
|
---|
1904 | have changed from Tasks to UnknownElements.
|
---|
1905 | </p>
|
---|
1906 | <p>
|
---|
1907 | There was a number of valid reasons for this change. But the backward
|
---|
1908 | compatibility problems were not noticed until after Ant 1.6.0 was
|
---|
1909 | released.
|
---|
1910 | </p>
|
---|
1911 | <p>
|
---|
1912 | Your container class will need to be modified to check if the Task
|
---|
1913 | is an UnknownElement and call perform on it to
|
---|
1914 | convert it to a Task and to execute it.
|
---|
1915 | (see apache.tools.ant.taskdefs.Sequential)
|
---|
1916 | </p>
|
---|
1917 | <p>
|
---|
1918 | If you want to do more processing on the task,
|
---|
1919 | you need to use the techniques in apache.tools.ant.taskdefs.Antlib#execute()
|
---|
1920 | This does make use of one 1.6 method call (UE#getRealObject()),
|
---|
1921 | you need to use UE#getTask() instead - this will
|
---|
1922 | return null for non tasks (types like fileset id=x).
|
---|
1923 | </p>
|
---|
1924 | <p>
|
---|
1925 | So.. iterate over the tasks, if they are UEs, convert them to
|
---|
1926 | tasks, using UE#maybeConfigure and UE#getTask()
|
---|
1927 | </p>
|
---|
1928 | <pre class="code">
|
---|
1929 | for (Iterator i = tasks.iterator(); i.hasNext();) {
|
---|
1930 | Task t = (Task) i.next();
|
---|
1931 | if (t instanceof UnknownElement) {
|
---|
1932 | ((UnknownElement) t).maybeConfigure();
|
---|
1933 | t = ((UnknownElement) t).getTask();
|
---|
1934 | if (t == null) {
|
---|
1935 | continue;
|
---|
1936 | }
|
---|
1937 | }
|
---|
1938 | // .... original Custom code
|
---|
1939 | }
|
---|
1940 | </pre>
|
---|
1941 | <p>
|
---|
1942 | This approach should work for ant1.5 and ant1.6.
|
---|
1943 | </p>
|
---|
1944 | <p class="faq">
|
---|
1945 | <a name="java.exception.stacktrace"></a>
|
---|
1946 |
|
---|
1947 | The program I run via <java> throws an exception but I
|
---|
1948 | can't seem to get the full stack trace.
|
---|
1949 |
|
---|
1950 | </p>
|
---|
1951 | <p>This is a know bug that has been fixed after the release of
|
---|
1952 | Ant 1.6.1.</p>
|
---|
1953 | <p>As a workaround, run your <java> task with
|
---|
1954 | <code>fork="true"</code> and Ant will display the full
|
---|
1955 | trace.</p>
|
---|
1956 | <p class="faq">
|
---|
1957 | <a name="junit-no-runtime-xml"></a>
|
---|
1958 |
|
---|
1959 | Using format="xml", <junit> fails with a
|
---|
1960 | <code>NoClassDefFoundError</code> if forked.
|
---|
1961 |
|
---|
1962 | </p>
|
---|
1963 | <p>The XML formatter needs the <a href="http://www.w3.org/DOM/">DOM classes</a> to work. If you
|
---|
1964 | are using JDK 1.4 or later they are included with your Java
|
---|
1965 | Runtime and this problem won't occur. If you are running JDK
|
---|
1966 | 1.3 or earlier, the DOM classes have to be on your
|
---|
1967 | <junit> task's <classpath>.</p>
|
---|
1968 | <p>Prior to Ant 1.6.0 Ant would include the DOM classes from
|
---|
1969 | the XML parser that is used by Ant itself if you set the
|
---|
1970 | includeAntRuntime attribute to true (the default). With Ant
|
---|
1971 | 1.6.0 this has been changed as this behavior made it
|
---|
1972 | impossible to use a different XML parser in your tests.</p>
|
---|
1973 | <p>This means that you have to take care of the DOM classes
|
---|
1974 | explicitly starting with Ant 1.6.0. If you don't need to set
|
---|
1975 | up a different XML parser for your tests, the easiest solution
|
---|
1976 | is to add</p>
|
---|
1977 | <pre class="code">
|
---|
1978 | <pathelement path="${ant.home}/lib/xml-apis.jar:${ant.home}/lib/xercesImpl.jar"/>
|
---|
1979 | </pre>
|
---|
1980 | <p>to your task's <classpath>.</p>
|
---|
1981 | <p class="faq">
|
---|
1982 | <a name="xalan-jdk1.5"></a>
|
---|
1983 |
|
---|
1984 | <code><junitreport></code> doesn't work with JDK 1.5 but
|
---|
1985 | worked fine with JDK 1.4.
|
---|
1986 |
|
---|
1987 | </p>
|
---|
1988 | <p>While JDK 1.4.x contains a version of Xalan-J 2, JDK 1.5
|
---|
1989 | (and later?) have <a href="http://java.sun.com/j2se/1.5.0/compatibility.html#4959783">moved
|
---|
1990 | to XSLTC</a>. Since this task uses Xalan's redirect
|
---|
1991 | extensions for its internal stylesheet, Ant prior to 1.6.2 didn't support
|
---|
1992 | XSLTC. This means that you have to install <a href="http://xml.apache.org/xalan-j/">Xalan-J 2</a> in order
|
---|
1993 | to use this task with JDK 1.5 in older versions of Ant.</p>
|
---|
1994 | <p>Starting with Ant 1.6.2 <code><junitreport></code>
|
---|
1995 | supports JDK 1.5.</p>
|
---|
1996 | </div>
|
---|
1997 | </div>
|
---|
1998 |
|
---|
1999 | <p class="copyright">
|
---|
2000 | <script type="text/javascript" language="JavaScript"><!--
|
---|
2001 | document.write(" - "+"Last Published: " + document.lastModified);
|
---|
2002 | // -->
|
---|
2003 | </script>
|
---|
2004 | </p>
|
---|
2005 | </body>
|
---|
2006 | </html>
|
---|
2007 |
|
---|
2008 |
|
---|
2009 |
|
---|
2010 |
|
---|
2011 |
|
---|
2012 |
|
---|
2013 |
|
---|
2014 |
|
---|
2015 |
|
---|
2016 |
|
---|
2017 |
|
---|