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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. buildfile and runs the &quot;default&quot; target.
  16. If you use the <code>-find</code> option,
  17. Ant will search for a buildfile first in the current directory, then in
  18. the parent directory, and so on, until either a buildfile is found or the root
  19. of the filesystem has been reached. To make Ant use
  20. a buildfile other than <code>build.xml</code>, use the command-line
  21. option <code>-buildfile <i>file</i></code>,
  22. where <i>file</i> is the name of the buildfile you want to use.</p>
  23. <p>You can also set <a href="using.html#properties">properties</a> that
  24. override properties specified in the
  25. buildfile (see the <a href="CoreTasks/property.html">property</a> task).
  26. This can be done with
  27. the <nobr><code>-D<i>property</i>=<i>value</i></code></nobr> option,
  28. where <i>property</i> is the name of the property,
  29. and <i>value</i> is the value for that property.
  30. This can also be used to pass in the value of environment variables.
  31. Just pass <nobr><code>-DMYVAR=%MYVAR%</code></nobr> (Windows) or
  32. <nobr><code>-DMYVAR=$MYVAR</code></nobr> (Unix)
  33. to Ant - you can then access
  34. these variables inside your buildfile as <code>${MYVAR}</code>.
  35. You can also access environment variables using the <a href="CoreTasks/property.html">
  36. property</a> task.
  37. </p>
  38. <p>Options that affect the amount of logging output by Ant are: <nobr><code>-quiet</code></nobr>,
  39. which instructs Ant to print less
  40. information on the console when running;
  41. <nobr><code>-verbose</code></nobr>, which causes Ant to print
  42. additional information to the console; and <nobr><code>-debug</code></nobr>,
  43. which causes Ant to print considerably more additional information.
  44. </p>
  45. <p>It is also possible to specify one or more targets that should be executed.
  46. When omitted, the target that is specified in the
  47. <code>default</code> attribute of the
  48. <a href="using.html#projects"><code>project</code></a> tag is
  49. used.</p>
  50. <p>The <nobr><code>-projecthelp</code></nobr> option prints out a list
  51. of the buildfile's targets, along with the
  52. text in the <code>description</code> attribute of the target,
  53. if one was specified, followed by a list of those targets without one.</p>
  54. <h3><a name="options">Command-line Options Summary</a></h3>
  55. <pre>ant [options] [target [target2 [target3] ...]]
  56. Options:
  57. -help print this message
  58. -projecthelp print project help information
  59. -version print the version information and exit
  60. -quiet be extra quiet
  61. -verbose be extra verbose
  62. -debug print debugging information
  63. -emacs produce logging information without adornments
  64. -logfile &lt;file&gt; use given file for log
  65. -logger &lt;classname&gt; the class which is to perform logging
  66. -listener &lt;classname&gt; add an instance of class as a project listener
  67. -buildfile &lt;file&gt; use given buildfile
  68. -D&lt;property&gt;=&lt;value&gt; use value for given property
  69. -propertyfile &lt;name&gt; load all properties from file with -D
  70. properties taking precedence
  71. -inputhandler &lt;class&gt; the class which will handle input requests
  72. -find &lt;file&gt; search for buildfile towards the root of the
  73. filesystem and use it
  74. </pre>
  75. <p>For more information about <code>-logger</code> and
  76. <code>-listener</code> see the section <a
  77. href="listeners.html">Loggers &amp; Listeners</a>
  78. <p>For more information about <code>-inputhandler</code> see the
  79. section <a href="inputhandler.html">InputHandler</a>
  80. <h3>Examples</h3>
  81. <blockquote>
  82. <pre>ant</pre>
  83. </blockquote>
  84. <p>runs Ant using the <code>build.xml</code> file in the current directory, on
  85. the default target.</p>
  86. <blockquote>
  87. <pre>ant -buildfile test.xml</pre>
  88. </blockquote>
  89. <p>runs Ant using the <code>test.xml</code> file in the current directory, on
  90. the default target.</p>
  91. <blockquote>
  92. <pre>ant -buildfile test.xml dist</pre>
  93. </blockquote>
  94. <p>runs Ant using the <code>test.xml</code> file in the current directory, on a
  95. target called <code>dist</code>.</p>
  96. <blockquote>
  97. <pre>ant -buildfile test.xml -Dbuild=build/classes dist</pre>
  98. </blockquote>
  99. <p>runs Ant using the <code>test.xml</code> file in the current directory, on a
  100. target called <code>dist</code>, setting the <code>build</code> property to the
  101. value <code>build/classes</code>.</p>
  102. <h3><a name="files">Files</a></h3>
  103. <p>The Ant wrapper script for Unix will source (read and evaluate) the
  104. file <code>~/.antrc</code> before it does anything - the Windows batch
  105. file invokes <code>%HOME%\antrc_pre.bat</code> at the start and
  106. <code>%HOME%\antrc_post.bat</code> at the end. You can use these
  107. files to set/unset environment variables that should only be visible
  108. during the execution of Ant. See the next section for example.</p>
  109. <h3><a name="envvars">Environment Variables</a></h3>
  110. <p>The wrapper scripts use the following environment variables (if
  111. set):</p>
  112. <ul>
  113. <li><code>JAVACMD</code> - full path of the Java executable. Use this
  114. to invoke a different JVM than <code>JAVA_HOME/bin/java(.exe)</code>.</li>
  115. <li><code>ANT_OPTS</code> - command-line arguments that should be
  116. passed to the JVM. For example, you can define system properties or set
  117. the maximum Java heap size here.</li>
  118. <li><code>ANT_ARGS</code> - Ant command-line arguments. For example,
  119. set <code>ANT_ARGS</code> to point to a different logger and to
  120. include the <code>-find</code> flag.</li>
  121. </ul>
  122. <h2><a name="viajava">Running Ant via Java</a></h2>
  123. <p>If you have installed Ant in the do-it-yourself way, Ant can be started
  124. with:</p>
  125. <blockquote>
  126. <pre>java -Dant.home=c:\ant org.apache.tools.ant.Main [options] [target]</pre>
  127. </blockquote>
  128. <p>These instructions actually do exactly the same as the <code>ant</code>
  129. command. The options and target are the same as when running Ant with the <code>ant</code>
  130. command. This example assumes you have set your classpath to include:</p>
  131. <ul>
  132. <li><code>ant.jar</code></li>
  133. <li>jars/classes for your XML parser</li>
  134. <li>the JDK's required jar/zip files</li>
  135. </ul>
  136. <br>
  137. <hr>
  138. <p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All rights
  139. Reserved.</p>
  140. </body>
  141. </html>