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

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