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 KiB

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