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 24 KiB

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