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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Running Apache Ant</title>
  5. </head>
  6. <body>
  7. <h1>Running Ant</h1>
  8. <h2><a name="commandline">Command Line</a></h2>
  9. <p> If you've installed Ant as described in the
  10. <a href="install.html"> Installing Ant</a> section,
  11. running Ant from the command-line is simple: just type
  12. <code>ant</code>.</p>
  13. <p>When no arguments are specified, Ant looks for a <code>build.xml</code>
  14. file in the current directory and, if found, uses that file as the
  15. build file and runs the target specified in the <code>default</code>
  16. attribute of the <code>&lt;project&gt;</code> tag.
  17. To make Ant use
  18. a build file other than <code>build.xml</code>, use the command-line
  19. option <nobr><code>-buildfile <i>file</i></code></nobr>,
  20. where <i>file</i> is the name of the build file you want to use.</p>
  21. If you use the <nobr><code>-find [<i>file</i>]</code></nobr> option,
  22. Ant will search for a build file first in the current directory, then in
  23. the parent directory, and so on, until either a build file is found or the root
  24. of the filesystem has been reached. By default, it will look for a build file
  25. called <code>build.xml</code>. To have it search for a build file other
  26. than <code>build.xml</code>, specify a file argument.
  27. <strong>Note:</strong> If you include any other flags or arguments
  28. on the command line after
  29. the <nobr><code>-find</code></nobr> flag, you must include the file argument
  30. for the <nobr><code>-find</code></nobr> flag, even if the name of the
  31. build file you want to find is <code>build.xml</code>.
  32. <p>You can also set <a href="using.html#properties">properties</a> on the
  33. command line. This can be done with
  34. the <nobr><code>-D<i>property</i>=<i>value</i></code></nobr> option,
  35. where <i>property</i> is the name of the property,
  36. and <i>value</i> is the value for that property. If you specify a
  37. property that is also set in the build file
  38. (see the <a href="CoreTasks/property.html">property</a> task),
  39. the value specified on the
  40. command line will override the value specified in the
  41. build file.
  42. Defining properties on the command line can also be used to pass in
  43. the value of environment variables - just pass
  44. <nobr><code>-DMYVAR=%MYVAR%</code></nobr> (Windows) or
  45. <nobr><code>-DMYVAR=$MYVAR</code></nobr> (Unix)
  46. to Ant. You can then access
  47. these variables inside your build file as <code>${MYVAR}</code>.
  48. You can also access environment variables using the
  49. <a href="CoreTasks/property.html"> property</a> task's
  50. <code>environment</code> attribute.
  51. </p>
  52. <p>Options that affect the amount of logging output by Ant are:
  53. <nobr><code>-quiet</code></nobr>,
  54. which instructs Ant to print less
  55. information to the console;
  56. <nobr><code>-verbose</code></nobr>, which causes Ant to print
  57. additional information to the console; and <nobr><code>-debug</code></nobr>,
  58. which causes Ant to print considerably more additional information.
  59. </p>
  60. <p>It is also possible to specify one or more targets that should be executed.
  61. When omitted, the target that is specified in the
  62. <code>default</code> attribute of the
  63. <a href="using.html#projects"><code>project</code></a> tag is
  64. used.</p>
  65. <p>The <nobr><code>-projecthelp</code></nobr> option prints out a list
  66. of the build file's targets. Targets that include a
  67. <code>description</code> attribute are listed as &quot;Main targets&quot;,
  68. those without a <code>description</code> are listed as
  69. &quot;Subtargets&quot;, then the &quot;Default&quot; target is listed.
  70. <h3><a name="options">Command-line Options Summary</a></h3>
  71. <pre>ant [options] [target [target2 [target3] ...]]
  72. Options:
  73. -help print this message
  74. -projecthelp print project help information
  75. -version print the version information and exit
  76. -diagnostics print information that might be helpful to
  77. diagnose or report problems.
  78. -quiet, -q be extra quiet
  79. -verbose, -v be extra verbose
  80. -debug print debugging information
  81. -emacs produce logging information without adornments
  82. -logfile &lt;file&gt; use given file for log
  83. -l &lt;file&gt; ''
  84. -logger &lt;classname&gt; the class which is to perform logging
  85. -listener &lt;classname&gt; add an instance of class as a project listener
  86. -buildfile &lt;file&gt; use given buildfile
  87. -file &lt;file&gt; ''
  88. -f &lt;file&gt; ''
  89. -D&lt;property&gt;=&lt;value&gt; use value for given property
  90. -propertyfile &lt;name&gt; load all properties from file with -D
  91. properties taking precedence
  92. -inputhandler &lt;class&gt; the class which will handle input requests
  93. -find &lt;file&gt; search for buildfile towards the root of the
  94. filesystem and use it
  95. </pre>
  96. <p>For more information about <code>-logger</code> and
  97. <code>-listener</code> see
  98. <a href="listeners.html">Loggers &amp; Listeners</a>.
  99. <p>For more information about <code>-inputhandler</code> see
  100. <a href="inputhandler.html">InputHandler</a>.
  101. <h3>Examples</h3>
  102. <blockquote>
  103. <pre>ant</pre>
  104. </blockquote>
  105. <p>runs Ant using the <code>build.xml</code> file in the current directory, on
  106. the default target.</p>
  107. <blockquote>
  108. <pre>ant -buildfile test.xml</pre>
  109. </blockquote>
  110. <p>runs Ant using the <code>test.xml</code> file in the current directory, on
  111. the default target.</p>
  112. <blockquote>
  113. <pre>ant -buildfile test.xml dist</pre>
  114. </blockquote>
  115. <p>runs Ant using the <code>test.xml</code> file in the current directory, on
  116. the target called <code>dist</code>.</p>
  117. <blockquote>
  118. <pre>ant -buildfile test.xml -Dbuild=build/classes dist</pre>
  119. </blockquote>
  120. <p>runs Ant using the <code>test.xml</code> file in the current directory, on
  121. the target called <code>dist</code>, setting the <code>build</code> property
  122. to the value <code>build/classes</code>.</p>
  123. <h3><a name="files">Files</a></h3>
  124. <p>The Ant wrapper script for Unix will source (read and evaluate) the
  125. file <code>~/.antrc</code> before it does anything. On Windows, the Ant
  126. wrapper batch-file invokes <code>%HOME%\antrc_pre.bat</code> at the start and
  127. <code>%HOME%\antrc_post.bat</code> at the end. You can use these
  128. files, for example, to set/unset environment variables that should only be
  129. visible during the execution of Ant. See the next section for examples.</p>
  130. <h3><a name="envvars">Environment Variables</a></h3>
  131. <p>The wrapper scripts use the following environment variables (if
  132. set):</p>
  133. <ul>
  134. <li><code>JAVACMD</code> - full path of the Java executable. Use this
  135. to invoke a different JVM than <code>JAVA_HOME/bin/java(.exe)</code>.</li>
  136. <li><code>ANT_OPTS</code> - command-line arguments that should be
  137. passed to the JVM. For example, you can define system properties or set
  138. the maximum Java heap size here.</li>
  139. <li><code>ANT_ARGS</code> - Ant command-line arguments. For example,
  140. set <code>ANT_ARGS</code> to point to a different logger, include a
  141. listener, and to include the <code>-find</code> flag.</li>
  142. <strong>Note:</strong> If you include <code>-find</code>
  143. in <code>ANT_ARGS</code>, you should include the name of the build file
  144. to find, even if the file is called <code>build.xml</code>.
  145. </ul>
  146. <h2><a name="cygwin">Cygwin Users</a></h2>
  147. <p>The Unix launch script that come with Ant works correctly with Cygwin. You
  148. should not have any problems launching Ant form the Cygwin shell. It is important
  149. to note however, that once Ant is runing it is part of the JDK which operates as
  150. a native Windows application. The JDK is not a Cygwin executable, and it therefore
  151. has no knowledge of the Cygwin paths, etc. In particular when using the &lt;exec&gt;
  152. task, executable names such as &quot;/bin/sh&quot; will not work, even though these
  153. work from the Cygwin shell from which Ant was launched. You can use an executable
  154. name such as &quot;sh&quot; and rely on that command being available in the Windows
  155. path.
  156. </p>
  157. <h2><a name="viajava">Running Ant via Java</a></h2>
  158. <p>If you have installed Ant in the do-it-yourself way, Ant can be started
  159. with:</p>
  160. <blockquote>
  161. <pre>java -Dant.home=c:\ant org.apache.tools.ant.Main [options] [target]</pre>
  162. </blockquote>
  163. <p>These instructions actually do exactly the same as the <code>ant</code>
  164. command. The options and target are the same as when running Ant with the <code>ant</code>
  165. command. This example assumes you have set your classpath to include:</p>
  166. <ul>
  167. <li><code>ant.jar</code></li>
  168. <li>jars/classes for your XML parser</li>
  169. <li>the JDK's required jar/zip files</li>
  170. </ul>
  171. <br>
  172. <hr>
  173. <p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
  174. Reserved.</p>
  175. </body>
  176. </html>