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 25 kB

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