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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. -quiet be extra quiet
  77. -verbose be extra verbose
  78. -debug print debugging information
  79. -emacs produce logging information without adornments
  80. -logfile &lt;file&gt; write logging output to given file
  81. -logger &lt;classname&gt; the class that is to perform logging
  82. -listener &lt;classname&gt; add an instance of <i>classname</i> as a project listener
  83. -buildfile &lt;file&gt; use given build file
  84. -D&lt;property&gt;=&lt;value&gt; use value for given property
  85. -propertyfile &lt;file&gt; load all properties from <i>file</i> (with -D taking precedence)
  86. -inputhandler &lt;class&gt; the class that will handle input requests
  87. -find [&lt;file&gt;] search for build.xml, or <i>file</i>, towards the root of the
  88. filesystem
  89. </pre>
  90. <p>For more information about <code>-logger</code> and
  91. <code>-listener</code> see
  92. <a href="listeners.html">Loggers &amp; Listeners</a>.
  93. <p>For more information about <code>-inputhandler</code> see
  94. <a href="inputhandler.html">InputHandler</a>.
  95. <h3>Examples</h3>
  96. <blockquote>
  97. <pre>ant</pre>
  98. </blockquote>
  99. <p>runs Ant using the <code>build.xml</code> file in the current directory, on
  100. the default target.</p>
  101. <blockquote>
  102. <pre>ant -buildfile test.xml</pre>
  103. </blockquote>
  104. <p>runs Ant using the <code>test.xml</code> file in the current directory, on
  105. the default target.</p>
  106. <blockquote>
  107. <pre>ant -buildfile test.xml dist</pre>
  108. </blockquote>
  109. <p>runs Ant using the <code>test.xml</code> file in the current directory, on
  110. the target called <code>dist</code>.</p>
  111. <blockquote>
  112. <pre>ant -buildfile test.xml -Dbuild=build/classes dist</pre>
  113. </blockquote>
  114. <p>runs Ant using the <code>test.xml</code> file in the current directory, on
  115. the target called <code>dist</code>, setting the <code>build</code> property
  116. to the value <code>build/classes</code>.</p>
  117. <h3><a name="files">Files</a></h3>
  118. <p>The Ant wrapper script for Unix will source (read and evaluate) the
  119. file <code>~/.antrc</code> before it does anything. On Windows, the Ant
  120. wrapper batch-file invokes <code>%HOME%\antrc_pre.bat</code> at the start and
  121. <code>%HOME%\antrc_post.bat</code> at the end. You can use these
  122. files, for example, to set/unset environment variables that should only be
  123. visible during the execution of Ant. See the next section for examples.</p>
  124. <h3><a name="envvars">Environment Variables</a></h3>
  125. <p>The wrapper scripts use the following environment variables (if
  126. set):</p>
  127. <ul>
  128. <li><code>JAVACMD</code> - full path of the Java executable. Use this
  129. to invoke a different JVM than <code>JAVA_HOME/bin/java(.exe)</code>.</li>
  130. <li><code>ANT_OPTS</code> - command-line arguments that should be
  131. passed to the JVM. For example, you can define system properties or set
  132. the maximum Java heap size here.</li>
  133. <li><code>ANT_ARGS</code> - Ant command-line arguments. For example,
  134. set <code>ANT_ARGS</code> to point to a different logger, include a
  135. listener, and to include the <code>-find</code> flag.</li>
  136. <strong>Note:</strong> If you include <code>-find</code>
  137. in <code>ANT_ARGS</code>, you should include the name of the build file
  138. to find, even if the file is called <code>build.xml</code>.
  139. </ul>
  140. <h2><a name="viajava">Running Ant via Java</a></h2>
  141. <p>If you have installed Ant in the do-it-yourself way, Ant can be started
  142. with:</p>
  143. <blockquote>
  144. <pre>java -Dant.home=c:\ant org.apache.tools.ant.Main [options] [target]</pre>
  145. </blockquote>
  146. <p>These instructions actually do exactly the same as the <code>ant</code>
  147. command. The options and target are the same as when running Ant with the <code>ant</code>
  148. command. This example assumes you have set your classpath to include:</p>
  149. <ul>
  150. <li><code>ant.jar</code></li>
  151. <li>jars/classes for your XML parser</li>
  152. <li>the JDK's required jar/zip files</li>
  153. </ul>
  154. <br>
  155. <hr>
  156. <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
  157. Reserved.</p>
  158. </body>
  159. </html>