source: release-kits/lirk3/resources/gs3-release-maker/ant/docs/manual/running.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 21.1 KB
Line 
1<html>
2
3<head>
4<meta http-equiv="Content-Language" content="en-us">
5<title>Running Apache Ant</title>
6<link rel="stylesheet" type="text/css" href="stylesheets/antmanual.css">
7</head>
8
9<body>
10
11<h1>Running Ant</h1>
12<h2><a name="commandline">Command Line</a></h2>
13<p> If you've installed Ant as described in the
14<a href="install.html"> Installing Ant</a> section,
15running Ant from the command-line is simple: just type
16<code>ant</code>.</p>
17<p>When no arguments are specified, Ant looks for a <code>build.xml</code>
18file in the current directory and, if found, uses that file as the
19build file and runs the target specified in the <code>default</code>
20attribute of the <code>&lt;project&gt;</code> tag.
21To make Ant use
22a build file other than <code>build.xml</code>, use the command-line
23option <nobr><code>-buildfile <i>file</i></code></nobr>,
24where <i>file</i> is the name of the build file you want to use.</p>
25If you use the <nobr><code>-find [<i>file</i>]</code></nobr> option,
26Ant will search for a build file first in the current directory, then in
27the parent directory, and so on, until either a build file is found or the root
28of the filesystem has been reached. By default, it will look for a build file
29called <code>build.xml</code>. To have it search for a build file other
30than <code>build.xml</code>, specify a file argument.
31<strong>Note:</strong> If you include any other flags or arguments
32on the command line after
33the <nobr><code>-find</code></nobr> flag, you must include the file argument
34for the <nobr><code>-find</code></nobr> flag, even if the name of the
35build file you want to find is <code>build.xml</code>.
36
37<p>You can also set <a href="using.html#properties">properties</a> on the
38command line. This can be done with
39the <nobr><code>-D<i>property</i>=<i>value</i></code></nobr> option,
40where <i>property</i> is the name of the property,
41and <i>value</i> is the value for that property. If you specify a
42property that is also set in the build file
43(see the <a href="CoreTasks/property.html">property</a> task),
44the value specified on the
45command line will override the value specified in the
46build file.
47Defining properties on the command line can also be used to pass in
48the value of environment variables - just pass
49<nobr><code>-DMYVAR=%MYVAR%</code></nobr> (Windows) or
50<nobr><code>-DMYVAR=$MYVAR</code></nobr> (Unix)
51to Ant. You can then access
52these variables inside your build file as <code>${MYVAR}</code>.
53You can also access environment variables using the
54<a href="CoreTasks/property.html"> property</a> task's
55<code>environment</code> attribute.
56</p>
57
58<p>Options that affect the amount of logging output by Ant are:
59<nobr><code>-quiet</code></nobr>,
60which instructs Ant to print less
61information to the console;
62<nobr><code>-verbose</code></nobr>, which causes Ant to print
63additional information to the console; and <nobr><code>-debug</code></nobr>,
64which causes Ant to print considerably more additional information.
65</p>
66
67<p>It is also possible to specify one or more targets that should be executed.
68When omitted, the target that is specified in the
69<code>default</code> attribute of the
70<a href="using.html#projects"><code>project</code></a> tag is
71used.</p>
72
73<p>The <nobr><code>-projecthelp</code></nobr> option prints out a list
74of the build file's targets. Targets that include a
75<code>description</code> attribute are listed as &quot;Main targets&quot;,
76those without a <code>description</code> are listed as
77&quot;Subtargets&quot;, then the &quot;Default&quot; target is listed.
78
79<h3><a name="options">Command-line Options Summary</a></h3>
80<pre>ant [options] [target [target2 [target3] ...]]
81Options:
82 -help, -h print this message
83 -projecthelp, -p print project help information
84 -version print the version information and exit
85 -diagnostics print information that might be helpful to
86 diagnose or report problems.
87 -quiet, -q be extra quiet
88 -verbose, -v be extra verbose
89 -debug, -d print debugging information
90 -emacs, -e produce logging information without adornments
91 -lib &lt;path&gt; specifies a path to search for jars and classes
92 -logfile &lt;file&gt; use given file for log
93 -l &lt;file&gt; ''
94 -logger &lt;classname&gt; the class which is to perform logging
95 -listener &lt;classname&gt; add an instance of class as a project listener
96 -noinput do not allow interactive input
97 -buildfile &lt;file&gt; use given buildfile
98 -file &lt;file&gt; ''
99 -f &lt;file&gt; ''
100 -D&lt;property&gt;=&lt;value&gt; use value for given property
101 -keep-going, -k execute all targets that do not depend
102 on failed target(s)
103 -propertyfile &lt;name&gt; load all properties from file with -D
104 properties taking precedence
105 -inputhandler &lt;class&gt; the class which will handle input requests
106 -find &lt;file&gt; (s)earch for buildfile towards the root of
107 -s &lt;file&gt; the filesystem and use it
108 -nice number A niceness value for the main thread:
109 1 (lowest) to 10 (highest); 5 is the default
110 -nouserlib Run ant without using the jar files from ${user.home}/.ant/lib
111 -noclasspath Run ant without using CLASSPATH
112</pre>
113<p>For more information about <code>-logger</code> and
114<code>-listener</code> see
115<a href="listeners.html">Loggers &amp; Listeners</a>.
116<p>For more information about <code>-inputhandler</code> see
117<a href="inputhandler.html">InputHandler</a>.
118
119<h3><a name="libs">Library Directories</a></h3>
120<p>
121Prior to Ant 1.6, all jars in the ANT_HOME/lib would be added to the CLASSPATH
122used to run Ant. This was done in the scripts that started Ant. From Ant 1.6,
123two directories are scanned by default and more can be added as required. The
124default directories scanned are ANT_HOME/lib and a user specific directory,
125${user.home}/.ant/lib. This arrangement allows the Ant installation to be
126shared by many users while still allowing each user to deploy additional jars.
127Such additional jars could be support jars for Ant's optional tasks or jars
128containing third-party tasks to be used in the build. It also allows the main Ant installation to be locked down which will please system adminstrators.
129</p>
130
131<p>
132Additional directories to be searched may be added by using the -lib option.
133The -lib option specifies a search path. Any jars or classes in the directories
134of the path will be added to Ant's classloader. The order in which jars are
135added to the classpath is as follows:
136</p>
137
138<ul>
139 <li>-lib jars in the order specified by the -lib elements on the command line</li>
140 <li>jars from ${user.home}/.ant/lib (unless -nouserlib is set)</li>
141 <li>jars from ANT_HOME/lib</li>
142</ul>
143
144<p>
145Note that the CLASSPATH environment variable is passed to Ant using a -lib
146option. Ant itself is started with a very minimalistic classpath.
147Ant should work perfectly well with an empty CLASSPATH environment variable,
148something the the -noclasspath option actually enforces. We get many more support calls related to classpath problems (especially quoting problems) than
149we like.
150
151</p>
152
153<p>
154The location of ${user.home}/.ant/lib is somewhat dependent on the JVM. On Unix
155systems ${user.home} maps to the user's home directory whilst on recent
156versions of Windows it will be somewhere such as
157C:\Documents&nbsp;and&nbsp;Settings\username\.ant\lib. You should consult your
158JVM documentation for more details.
159</p>
160
161<h3>Examples</h3>
162<blockquote>
163 <pre>ant</pre>
164</blockquote>
165<p>runs Ant using the <code>build.xml</code> file in the current directory, on
166the default target.</p>
167<blockquote>
168 <pre>ant -buildfile test.xml</pre>
169</blockquote>
170<p>runs Ant using the <code>test.xml</code> file in the current directory, on
171the default target.</p>
172<blockquote>
173 <pre>ant -buildfile test.xml dist</pre>
174</blockquote>
175<p>runs Ant using the <code>test.xml</code> file in the current directory, on
176the target called <code>dist</code>.</p>
177<blockquote>
178 <pre>ant -buildfile test.xml -Dbuild=build/classes dist</pre>
179</blockquote>
180<p>runs Ant using the <code>test.xml</code> file in the current directory, on
181the target called <code>dist</code>, setting the <code>build</code> property
182to the value <code>build/classes</code>.</p>
183
184<blockquote>
185 <pre>ant -lib /home/ant/extras</pre>
186</blockquote>
187<p>runs Ant picking up additional task and support jars from the
188/home/ant/extras location
189</p>
190
191<h3><a name="files">Files</a></h3>
192
193<p>The Ant wrapper script for Unix will source (read and evaluate) the
194file <code>~/.antrc</code> before it does anything. On Windows, the Ant
195wrapper batch-file invokes <code>%HOME%\antrc_pre.bat</code> at the start and
196<code>%HOME%\antrc_post.bat</code> at the end. You can use these
197files, for example, to set/unset environment variables that should only be
198visible during the execution of Ant. See the next section for examples.</p>
199
200<h3><a name="envvars">Environment Variables</a></h3>
201
202<p>The wrapper scripts use the following environment variables (if
203set):</p>
204
205<ul>
206 <li><code>JAVACMD</code> - full path of the Java executable. Use this
207 to invoke a different JVM than <code>JAVA_HOME/bin/java(.exe)</code>.</li>
208
209 <li><code>ANT_OPTS</code> - command-line arguments that should be
210 passed to the JVM. For example, you can define system properties or set
211 the maximum Java heap size here.</li>
212
213 <li><code>ANT_ARGS</code> - Ant command-line arguments. For example,
214 set <code>ANT_ARGS</code> to point to a different logger, include a
215 listener, and to include the <code>-find</code> flag.</li>
216 <strong>Note:</strong> If you include <code>-find</code>
217 in <code>ANT_ARGS</code>, you should include the name of the build file
218 to find, even if the file is called <code>build.xml</code>.
219</ul>
220
221<h3><a name="sysprops">Java System Properties</a></h3>
222<p>Some of Ant's core classes can be configured via system properties.</p>
223<p>Here is the result of a search through the codebase. Because system properties are
224available via Project instance, I searched for them with a
225<pre>
226 grep -r -n "getPropert" * &gt; ..\grep.txt
227</pre>
228command. After that I filtered out the often-used but not-so-important values (most of them
229read-only values): <i>path.separator, ant.home, basedir, user.dir, os.name,
230line.separator, java.home, java.version, java.version, user.home, java.class.path</i><br>
231And I filtered out the <i>getPropertyHelper</i> access.</p>
232<table border="1">
233<tr>
234 <th>property name</th>
235 <th>valid values /default value</th>
236 <th>description</th>
237</tr>
238<tr>
239 <td><code>ant.executor.class</code></td>
240 <td>classname; default is org. apache. tools. ant. helper. DefaultExecutor</td>
241 <td><b>Since Ant 1.6.3</b> Ant will delegate Target invocation to the
242org.apache.tools.ant.Executor implementation specified here.
243 </td>
244</tr>
245
246<tr>
247 <td><code>ant.file</code></td>
248 <td>read only: full filename of the build file</td>
249 <td>This is set to the name of the build file. In
250 <a href="CoreTasks/import.html">
251 &lt;import&gt;-ed</a> files, this is set to the containing build file.
252 </td>
253</tr>
254
255<tr>
256 <td><code>ant.file.*</code></td>
257 <td>read only: full filename of the build file of Ant projects
258 </td>
259 <td>This is set to the name of a file by project;
260 this lets you determine the location of <a href="CoreTasks/import.html">
261 &lt;import&gt;-ed</a> files,
262 </td>
263</tr>
264
265<tr>
266 <td><code>ant.input.properties</code></td>
267 <td>filename (required)</td>
268 <td>Name of the file holding the values for the
269 <a href="inputhandler.html">PropertyFileInputHandler</a>.
270 </td>
271</tr>
272<tr>
273 <td><code>ant.logger.defaults</code></td>
274 <!-- add the blank after the slash, so the browser can do a line break -->
275 <td>filename (optional, default '/org/ apache/ tools/ ant/ listener/ defaults.properties')</td>
276 <td>Name of the file holding the color mappings for the
277 <a href="listeners.html#AnsiColorLogger">AnsiColorLogger</a>.
278 </td>
279</tr>
280<tr>
281 <td><code>ant.netrexxc.*</code></td>
282 <td>several formats</td>
283 <td>Use specified values as defaults for <a href="OptionalTasks/netrexxc.html">netrexxc</a>.
284 </td>
285</tr>
286<tr>
287 <td><code>ant.PropertyHelper</code></td>
288 <td>ant-reference-name (optional)</td>
289 <td>Specify the PropertyHelper to use. The object must be of the type
290 org.apache.tools.ant.PropertyHelper. If not defined an object of
291 org.apache.tools.ant.PropertyHelper will be used as PropertyHelper.
292 </td>
293</tr>
294<tr>
295 <td><code>ant.regexp.regexpimpl</code></td>
296 <td>classname</td>
297 <td>classname for a RegExp implementation; if not set Ant tries to
298 find another (JDK14+, Apache Oro...);
299 <a href="CoreTypes/mapper.html#regexp-mapper">RegExp-Mapper</a>
300 "Choice of regular expression implementation"
301 </td>
302</tr>
303<tr>
304 <td><code>ant.reuse.loader</code></td>
305 <td>boolean</td>
306 <td>allow to reuse classloaders
307 used in org.apache.tools.ant.util.ClasspathUtil
308 </td>
309</tr>
310<tr>
311 <td><code>ant.XmlLogger.stylesheet.uri</code></td>
312 <td>filename (default 'log.xsl')</td>
313 <td>Name for the stylesheet to include in the logfile by
314 <a href="listeners.html#XmlLogger">XmlLogger</a>.
315 </td>
316</tr>
317<tr>
318 <td><code>build.compiler</code></td>
319 <td>name</td>
320 <td>Specify the default compiler to use.
321 see <a href="CoreTasks/javac.html">javac</a>,
322 <a href="OptionalTasks/ejb.html#ejbjar_weblogic">EJB Tasks</a>
323 (compiler attribute),
324 <a href="OptionalTasks/icontract.html">IContract</a>,
325 <a href="OptionalTasks/javah.html">javah</a>
326 </td>
327</tr>
328<tr>
329 <td><code>build.compiler.emacs</code></td>
330 <td>boolean (default false)</td>
331 <td>Enable emacs-compatible error messages.
332 see <a href="CoreTasks/javac.html">javac</a> "Jikes Notes"
333 </td>
334</tr>
335<tr>
336 <td><code>build.compiler.fulldepend</code></td>
337 <td>boolean (default false)</td>
338 <td>Enable full dependency checking
339 see <a href="CoreTasks/javac.html">javac</a> "Jikes Notes"
340 </td>
341</tr>
342<tr>
343 <td><code>build.compiler.jvc.extensions</code></td>
344 <td>boolean (default true)</td>
345 <td>enable Microsoft extensions of their java compiler
346 see <a href="CoreTasks/javac.html">javac</a> "Jvc Notes"
347 </td>
348</tr>
349<tr>
350 <td><code>build.compiler.pedantic</code></td>
351 <td>boolean (default false)</td>
352 <td>Enable pedantic warnings.
353 see <a href="CoreTasks/javac.html">javac</a> "Jikes Notes"
354 </td>
355</tr>
356<tr>
357 <td><code>build.compiler.warnings</code></td>
358 <td>Deprecated flag</td>
359 <td> see <a href="CoreTasks/javac.html">javac</a> "Jikes Notes" </td>
360</tr>
361<tr>
362 <td><code>build.rmic</code></td>
363 <td>name</td>
364 <td>control the <a href="CoreTasks/rmic.html">rmic</a> compiler </td>
365</tr>
366<tr>
367 <td><code>build.sysclasspath</code></td>
368 <td>"only", something else</td>
369 <td>only: current threads get the actual class loader
370 (AntClassLoader.setThreadContextLoader()).
371 else: use core loader as default (ComponentHelper.initTasks()). Disable
372 changing the classloader (oata.taskdefs.Classloader.execute() experimental
373 task).
374 <!-- somewhere documented in the manual?? -->
375 </td>
376</tr>
377<tr>
378 <td><code>file.encoding</code></td>
379 <td>name of a supported character set (e.g. UTF-8, ISO-8859-1, US-ASCII)</td>
380 <td>use as default character set of email messages; use as default for source-, dest- and bundleencoding
381 in <a href="OptionalTasks/translate.html">translate</a> <br>
382 see JavaDoc of <a target="_blank" href="http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html">java.nio.charset.Charset</a>
383 for more information about character sets (not used in Ant, but has nice docs).
384 </td>
385</tr>
386<tr>
387 <td><code>jikes.class.path</code></td>
388 <td>path</td>
389 <td>The specified path is added to the classpath if jikes is used as compiler.</td>
390</tr>
391<tr>
392 <td><code>MailLogger.properties.file, MailLogger.*</code></td>
393 <td>filename (optional, defaults derived from Project instance)</td>
394 <td>Name of the file holding properties for sending emails by the
395 <a href="listeners.html#MailLogger">MailLogger</a>. Override properties set
396 inside the buildfile or via command line.
397 </td>
398</tr>
399<tr>
400 <td><code>org.apache.tools.ant.ProjectHelper</code></td>
401 <!-- add the blank after the slash, so the browser can do a line break -->
402 <td>classname (optional, default 'org.apache.tools.ant.ProjectHelper')</td>
403 <td>specifies the classname to use as ProjectHelper. The class must extend
404 org.apache.tools.ant.ProjectHelper.
405 </td>
406</tr>
407<tr>
408 <td><code>p4.port, p4.client, p4.user</code></td>
409 <td>several formats</td>
410 <td>Specify defaults for port-, client- and user-setting of the
411 <a href="OptionalTasks/perforce.html">perforce</a> tasks.
412 </td>
413</tr>
414<tr>
415 <td><code>websphere.home
416 <td>path</td>
417 <td>Points to home directory of websphere.
418 see <a href="OptionalTasks/ejb.html#ejbjar_websphere">EJB Tasks</a>
419 </td>
420</tr>
421<tr>
422 <td><code>XmlLogger.file
423 <td>filename (default 'log.xml')</td>
424 <td>Name for the logfile for <a href="listeners.html#MailLogger">MailLogger</a>.
425 </td>
426</tr>
427</table>
428
429<p>
430If new properties get added (it happens), expect them to appear under the
431"ant." and "org.apache.tools.ant" prefixes, unless the developers have a
432very good reason to use another prefix. Accordingly, please avoid using
433properties that begin with these prefixes. This protects you from future
434Ant releases breaking your build file.
435</p>
436
437<h2><a name="cygwin">Cygwin Users</a></h2>
438<p>The Unix launch script that come with Ant works correctly with Cygwin. You
439should not have any problems launching Ant from the Cygwin shell. It is
440important to note, however, that once Ant is running it is part of the JDK
441which operates as a native Windows application. The JDK is not a Cygwin
442executable, and it therefore has no knowledge of Cygwin paths, etc. In
443particular when using the <code>&lt;exec&gt;</code> task, executable names such
444as &quot;/bin/sh&quot; will not work, even though these work from the Cygwin
445shell from which Ant was launched. You can use an executable name such as
446&quot;sh&quot; and rely on that command being available in the Windows path.
447</p>
448
449<h2><a name="os2">OS/2 Users</a></h2>
450<p>The OS/2 launch script was developed to perform complex tasks. It has two parts:
451<code>ant.cmd</code> which calls Ant and <code>antenv.cmd</code> which sets the environment for Ant.
452Most often you will just call <code>ant.cmd</code> using the same command line options as described
453above. The behaviour can be modified by a number of ways explained below.</p>
454
455<p>Script <code>ant.cmd</code> first verifies whether the Ant environment is set correctly. The
456requirements are:</p>
457<ol>
458<li>Environment variable <code>JAVA_HOME</code> is set.</li>
459<li>Environment variable <code>ANT_HOME</code> is set.</li>
460<li>Environment variable <code>CLASSPATH</code> is set and contains at least one element from
461<code>JAVA_HOME</code> and at least one element from <code>ANT_HOME</code>.</li>
462</ol>
463
464<p>If any of these conditions is violated, script <code>antenv.cmd</code> is called. This script
465first invokes configuration scripts if there exist: the system-wide configuration
466<code>antconf.cmd</code> from the <code>%ETC%</code> directory and then the user configuration
467<code>antrc.cmd</code> from the <code>%HOME%</code> directory. At this moment both
468<code>JAVA_HOME</code> and <code>ANT_HOME</code> must be defined because <code>antenv.cmd</code>
469now adds <code>classes.zip</code> or <code>tools.jar</code> (depending on version of JVM) and
470everything from <code>%ANT_HOME%\lib</code> except <code>ant-*.jar</code> to
471<code>CLASSPATH</code>. Finally <code>ant.cmd</code> calls per-directory configuration
472<code>antrc.cmd</code>. All settings made by <code>ant.cmd</code> are local and are undone when the
473script ends. The settings made by <code>antenv.cmd</code> are persistent during the lifetime of the
474shell (of course unless called automatically from <code>ant.cmd</code>). It is thus possible to call
475<code>antenv.cmd</code> manually and modify some settings before calling <code>ant.cmd</code>.</p>
476
477<p>Scripts <code>envset.cmd</code> and <code>runrc.cmd</code> perform auxiliary tasks. All scripts
478have some documentation inside.</p>
479
480<h2><a name="viajava">Running Ant via Java</a></h2>
481<p>If you have installed Ant in the do-it-yourself way, Ant can be started
482from one of two entry points:</p>
483<blockquote>
484 <pre>java -Dant.home=c:\ant org.apache.tools.ant.Main [options] [target]</pre>
485</blockquote>
486
487<blockquote>
488 <pre>java -Dant.home=c:\ant org.apache.tools.ant.launch.Launcher [options] [target]</pre>
489</blockquote>
490
491<p>
492The first method runs Ant's traditional entry point. The second method uses
493the Ant Launcher introduced in Ant 1.6. The former method does not support
494the -lib option and all required classes are loaded from the CLASSPATH. You must
495ensure that all required jars are available. At a minimum the CLASSPATH should
496include:
497</p>
498
499<ul>
500<li><code>ant.jar</code> and <code>ant-launcher.jar</code></li>
501<li>jars/classes for your XML parser</li>
502<li>the JDK's required jar/zip files</li>
503</ul>
504
505<p>
506The latter method supports the -lib option and will load jars from the
507specified ANT_HOME. You should start the latter with the most minimal
508classpath possible, generally just the ant-launcher.jar.
509</p>
510
511<br>
512<hr>
513<p align="center">Copyright &copy; 2000-2005 The Apache Software Foundation. All rights
514Reserved.</p>
515
516</body>
517</html>
Note: See TracBrowser for help on using the repository browser.