You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

running.html 20 KiB

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