source: release-kits/lirk3/bin/ant-installer/web/manual1.6.2/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: 19.5 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</pre>
109<p>For more information about <code>-logger</code> and
110<code>-listener</code> see
111<a href="listeners.html">Loggers &amp; Listeners</a>.
112<p>For more information about <code>-inputhandler</code> see
113<a href="inputhandler.html">InputHandler</a>.
114
115<h3><a name="libs">Library Directories</a></h3>
116<p>
117Prior to Ant 1.6, all jars in the ANT_HOME/lib would be added to the CLASSPATH
118used to run Ant. This was done in the scripts that started Ant. From Ant 1.6,
119two directories are scanned by default and more can be added as required. The
120default directories scanned are ANT_HOME/lib and a user specific directory,
121${user.home}/.ant/lib. This arrangement allows the Ant installation to be
122shared by many users while still allowing each user to deploy additional jars.
123Such additional jars could be support jars for Ant's optional tasks or jars
124containing third-party tasks to be used in the build. It also allows the main Ant
125installation to be locked down which will please system adminstrators.
126</p>
127
128<p>
129Additional directories to be searched may be added by using the -lib option.
130The -lib option specifies a search path. Any jars or classes in the directories
131of the path will be added to Ant's classloader. The order in which jars are
132added to the classpath is as follows
133</p>
134
135<ul>
136 <li>-lib jars in the order specified by the -lib elements on the command line</li>
137 <li>jars from ${user.home}/.ant/lib</li>
138 <li>jars from ANT_HOME/lib</li>
139</ul>
140
141<p>
142Note that the CLASSPATH environment variable is passed to Ant using a -lib
143option. Ant itself is started with a very minimalistic classpath.
144</p>
145
146<p>
147The location of ${user.home}/.ant/lib is somewhat dependent on the JVM. On Unix
148systems ${user.home} maps to the user's home directory whilst on recent
149versions of Windows it will be somewhere such as
150C:\Documents&nbsp;and&nbsp;Settings\username\.ant\lib. You should consult your
151JVM documentation for more details.
152</p>
153
154<h3>Examples</h3>
155<blockquote>
156 <pre>ant</pre>
157</blockquote>
158<p>runs Ant using the <code>build.xml</code> file in the current directory, on
159the default target.</p>
160<blockquote>
161 <pre>ant -buildfile test.xml</pre>
162</blockquote>
163<p>runs Ant using the <code>test.xml</code> file in the current directory, on
164the default target.</p>
165<blockquote>
166 <pre>ant -buildfile test.xml dist</pre>
167</blockquote>
168<p>runs Ant using the <code>test.xml</code> file in the current directory, on
169the target called <code>dist</code>.</p>
170<blockquote>
171 <pre>ant -buildfile test.xml -Dbuild=build/classes dist</pre>
172</blockquote>
173<p>runs Ant using the <code>test.xml</code> file in the current directory, on
174the target called <code>dist</code>, setting the <code>build</code> property
175to the value <code>build/classes</code>.</p>
176
177<blockquote>
178 <pre>ant -lib /home/ant/extras</pre>
179</blockquote>
180<p>runs Ant picking up additional task and support jars from the
181/home/ant/extras location
182</p>
183
184<h3><a name="files">Files</a></h3>
185
186<p>The Ant wrapper script for Unix will source (read and evaluate) the
187file <code>~/.antrc</code> before it does anything. On Windows, the Ant
188wrapper batch-file invokes <code>%HOME%\antrc_pre.bat</code> at the start and
189<code>%HOME%\antrc_post.bat</code> at the end. You can use these
190files, for example, to set/unset environment variables that should only be
191visible during the execution of Ant. See the next section for examples.</p>
192
193<h3><a name="envvars">Environment Variables</a></h3>
194
195<p>The wrapper scripts use the following environment variables (if
196set):</p>
197
198<ul>
199 <li><code>JAVACMD</code> - full path of the Java executable. Use this
200 to invoke a different JVM than <code>JAVA_HOME/bin/java(.exe)</code>.</li>
201
202 <li><code>ANT_OPTS</code> - command-line arguments that should be
203 passed to the JVM. For example, you can define system properties or set
204 the maximum Java heap size here.</li>
205
206 <li><code>ANT_ARGS</code> - Ant command-line arguments. For example,
207 set <code>ANT_ARGS</code> to point to a different logger, include a
208 listener, and to include the <code>-find</code> flag.</li>
209 <strong>Note:</strong> If you include <code>-find</code>
210 in <code>ANT_ARGS</code>, you should include the name of the build file
211 to find, even if the file is called <code>build.xml</code>.
212</ul>
213
214<h3><a name="sysprops">Java System Properties</a></h3>
215<p>Some of Ants core classes ant tasks can be configured via system properties.</p>
216<p>So here the result of a search through the codebase. Because system properties are
217available via Project instance, I searched for them with a
218<pre>
219 grep -r -n "getPropert" * > ..\grep.txt
220</pre>
221command. After that I filtered out the often-used but not-so-important values (most of them
222read-only values): <i>path.separator, ant.home, basedir, user.dir, os.name, ant.file,
223line.separator, java.home, java.version, java.version, user.home, java.class.path</i><br>
224And I filtered out the <i>getPropertyHelper</i> access.</p>
225<table border="1">
226<tr>
227 <th>property name</th>
228 <th>valid values /default value</th>
229 <th>description</th>
230</tr>
231<tr>
232 <td><code>ant.input.properties</code></td>
233 <td>filename (required)</td>
234 <td>Name of the file holding the values for the
235 <a href="inputhandler.html">PropertyFileInputHandler</a>.
236 </td>
237</tr>
238<tr>
239 <td><code>ant.logger.defaults</code></td>
240 <!-- add the blank after the slash, so the browser can do a line break -->
241 <td>filename (optional, default '/org/ apache/ tools/ ant/ listener/ defaults.properties')</td>
242 <td>Name of the file holding the color mappings for the
243 <a href="listeners.html#AnsiColorLogger">AnsiColorLogger</a>.
244 </td>
245</tr>
246<tr>
247 <td><code>ant.netrexxc.*</code></td>
248 <td>several formats</td>
249 <td>Use specified values as defaults for <a href="OptionalTasks/netrexxc.html">netrexxc</a>.
250 </td>
251</tr>
252<tr>
253 <td><code>ant.PropertyHelper</code></td>
254 <td>ant-reference-name (optional)</td>
255 <td>Specify the PropertyHelper to use. The object must be of the type
256 org.apache.tools.ant.PropertyHelper. If not defined an object of
257 org.apache.tools.ant.PropertyHelper will be used as PropertyHelper.
258 </td>
259</tr>
260<tr>
261 <td><code>ant.regexp.regexpimpl</code></td>
262 <td>classname</td>
263 <td>classname for a RegExp implementation; if not set Ant tries to
264 find another (Jdk14, Oro...);
265 <a href="CoreTypes/mapper.html#regexp-mapper">RegExp-Mapper</a>
266 "Choice of regular expression implementation"
267 </td>
268</tr>
269<tr>
270 <td><code>ant.reuse.loader</code></td>
271 <td>boolean</td>
272 <td>allow to reuse classloaders
273 used in org.apache.tools.ant.util.ClasspathUtil
274 </td>
275</tr>
276<tr>
277 <td><code>ant.XmlLogger.stylesheet.uri</code></td>
278 <td>filename (default 'log.xsl')</td>
279 <td>Name for the stylesheet to include in the logfile by
280 <a href="listeners.html#XmlLogger">XmlLogger</a>.
281 </td>
282</tr>
283<tr>
284 <td><code>build.compiler</code></td>
285 <td>name</td>
286 <td>Specify the default compiler to use.
287 see <a href="CoreTasks/javac.html">javac</a>,
288 <a href="OptionalTasks/ejb.html#ejbjar_weblogic">EJB Tasks</a>
289 (compiler attribute),
290 <a href="OptionalTasks/icontract.html">IContract</a>,
291 <a href="OptionalTasks/javah.html">javah</a>
292 </td>
293</tr>
294<tr>
295 <td><code>build.compiler.emacs</code></td>
296 <td>boolean (default false)</td>
297 <td>Enable emacs-compatible error messages.
298 see <a href="CoreTasks/javac.html">javac</a> "Jikes Notes"
299 </td>
300</tr>
301<tr>
302 <td><code>build.compiler.fulldepend</code></td>
303 <td>boolean (default false)</td>
304 <td>Enable full dependency checking
305 see <a href="CoreTasks/javac.html">javac</a> "Jikes Notes"
306 </td>
307</tr>
308<tr>
309 <td><code>build.compiler.jvc.extensions</code></td>
310 <td>boolean (default true)</td>
311 <td>enable Microsoft extensions of their java compiler
312 see <a href="CoreTasks/javac.html">javac</a> "Jvc Notes"
313 </td>
314</tr>
315<tr>
316 <td><code>build.compiler.pedantic</code></td>
317 <td>boolean (default false)</td>
318 <td>Enable pedantic warnings.
319 see <a href="CoreTasks/javac.html">javac</a> "Jikes Notes"
320 </td>
321</tr>
322<tr>
323 <td><code>build.compiler.warnings</code></td>
324 <td>Deprecated flag</td>
325 <td> see <a href="CoreTasks/javac.html">javac</a> "Jikes Notes" </td>
326</tr>
327<tr>
328 <td><code>build.rmic</code></td>
329 <td>name</td>
330 <td>control the <a href="CoreTasks/rmic.html">rmic</a> compiler </td>
331</tr>
332<tr>
333 <td><code>build.sysclasspath</code></td>
334 <td>"only", something else</td>
335 <td>only: current threads get the actual class loader
336 (AntClassLoader.setThreadContextLoader()).
337 else: use core loader as default (ComponentHelper.initTasks()). Disable
338 changing the classloader (oata.taskdefs.Classloader.execute() experimental
339 task).
340 <!-- somewhere documented in the manual?? -->
341 </td>
342</tr>
343<tr>
344 <td><code>file.encoding</code></td>
345 <td>name of a supported character set (e.g. UTF-8, ISO-8859-1, US-ASCII)</td>
346 <td>use as default character set of email messages; use as default for source-, dest- and bundleencoding
347 in <a href="OptionalTasks/translate.html">translate</a> <br>
348 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>
349 for more information about character sets (not used in Ant, but has nice docs).
350 </td>
351</tr>
352<tr>
353 <td><code>jikes.class.path</code></td>
354 <td>path</td>
355 <td>The specified path is added to the classpath if jikes is used as compiler.</td>
356</tr>
357<tr>
358 <td><code>MailLogger.properties.file, MailLogger.*</code></td>
359 <td>filename (optional, defaults derived from Project instance)</td>
360 <td>Name of the file holding properties for sending emails by the
361 <a href="listeners.html#MailLogger">MailLogger</a>. Override properties set
362 inside the buildfile or via command line.
363 </td>
364</tr>
365<tr>
366 <td><code>org.apache.tools.ant.ProjectHelper</code></td>
367 <!-- add the blank after the slash, so the browser can do a line break -->
368 <td>classname (optional, default 'org. apache. tools. ant. ProjectHelper')</td>
369 <td>specifies the classname to use as ProjectHelper. The class must extend
370 org.apache.tools.ant.ProjectHelper.
371 </td>
372</tr>
373<tr>
374 <td><code>p4.port, p4.client, p4.user</code></td>
375 <td>several formats</td>
376 <td>Specify defaults for port-, client- and user-setting of the
377 <a href="OptionalTasks/perforce.html">perforce</a> tasks.
378 </td>
379</tr>
380<tr>
381 <td><code>websphere.home
382 <td>path</td>
383 <td>Points to home directory of websphere.
384 see <a href="OptionalTasks/ejb.html#ejbjar_websphere">EJB Tasks</a>
385 </td>
386</tr>
387<tr>
388 <td><code>XmlLogger.file
389 <td>filename (default 'log.xml')</td>
390 <td>Name for the logfile for <a href="listeners.html#MailLogger">MailLogger</a>.
391 </td>
392</tr>
393</table>
394
395<h2><a name="cygwin">Cygwin Users</a></h2>
396<p>The Unix launch script that come with Ant works correctly with Cygwin. You
397should not have any problems launching Ant form the Cygwin shell. It is important
398to note however, that once Ant is runing it is part of the JDK which operates as
399a native Windows application. The JDK is not a Cygwin executable, and it therefore
400has no knowledge of the Cygwin paths, etc. In particular when using the &lt;exec&gt;
401task, executable names such as &quot;/bin/sh&quot; will not work, even though these
402work from the Cygwin shell from which Ant was launched. You can use an executable
403name such as &quot;sh&quot; and rely on that command being available in the Windows
404path.
405</p>
406
407<h2><a name="os2">OS/2 Users</a></h2>
408<p>The OS/2 lanuch script was developed so as it can perform complex task. It has two parts:
409<code>ant.cmd</code> which calls Ant and <code>antenv.cmd</code> which sets environment for Ant.
410Most often you will just call <code>ant.cmd</code> using the same command line options as described
411above. The behaviour can be modified by a number of ways explained below.</p>
412
413<p>Script <code>ant.cmd</code> first verifies whether the Ant environment is set correctly. The
414requirements are:</p>
415<ol>
416<li>Environment variable <code>JAVA_HOME</code> is set.</li>
417<li>Environment variable <code>ANT_HOME</code> is set.</li>
418<li>environment variable <code>CLASSPATH</code> is set and contains at least one element from
419<code>JAVA_HOME</code> and at least one element from <code>ANT_HOME</code>.</li>
420</ol>
421
422<p>If any of these conditions is violated, script <code>antenv.cmd</code> is called. This script
423first invokes configuration scripts if there exist: the system-wide configuration
424<code>antconf.cmd</code> from the <code>%ETC%</code> directory and then the user comfiguration
425<code>antrc.cmd</code> from the <code>%HOME%</code> directory. At this moment both
426<code>JAVA_HOME</code> and <code>ANT_HOME</code> must be defined because <code>antenv.cmd</code>
427now adds <code>classes.zip</code> or <code>tools.jar</code> (depending on version of JVM) and
428everything from <code>%ANT_HOME%\lib</code> except <code>ant-*.jar</code> to
429<code>CLASSPATH</code>. Finally <code>ant.cmd</code> calls per-directory configuration
430<code>antrc.cmd</code>. All settings made by <code>ant.cmd</code> are local and are undone when the
431script ends. The settings made by <code>antenv.cmd</code> are persistent during the lifetime of the
432shell (of course unless called automaticaly from <code>ant.cmd</code>). It is thus possible to call
433<code>antenv.cmd</code> manually and modify some settings before calling <code>ant.cmd</code>.</p>
434
435<p>Scripts <code>envset.cmd</code> and <code>runrc.cmd</code> perform auxilliary tasks. All scripts
436have some documentation inside.</p>
437
438<h2><a name="viajava">Running Ant via Java</a></h2>
439<p>If you have installed Ant in the do-it-yourself way, Ant can be started
440with two entry points:</p>
441<blockquote>
442 <pre>java -Dant.home=c:\ant org.apache.tools.ant.Main [options] [target]</pre>
443</blockquote>
444
445<blockquote>
446 <pre>java -Dant.home=c:\ant org.apache.tools.ant.launch.Launcher [options] [target]</pre>
447</blockquote>
448
449<p>
450The first method runs Ant's traditional entry point. The second method uses
451the Ant Launcher introduced in Ant 1.6. The former method does not support
452the -lib option and all required classes are loaded from the CLASSPATH. You must
453ensure that all required jars are available. At a minimum the CLASSPATH should
454include:
455</p>
456
457<ul>
458<li><code>ant.jar</code> and <code>ant-launcher.jar</code></li>
459<li>jars/classes for your XML parser</li>
460<li>the JDK's required jar/zip files</li>
461</ul>
462
463<p>
464The latter method supports the -lib option and will load jars from the
465specified ANT_HOME. You should start the latter with the most minimal
466classpath possible, generally just the ant-launcher.jar.
467</p>
468
469<br>
470<hr>
471<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
472Reserved.</p>
473
474</body>
475</html>
Note: See TracBrowser for help on using the repository browser.