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.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Apache Ant User Manual</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. -find &lt;file&gt; search for buildfile towards the root of the
  72. filesystem and use it
  73. </pre>
  74. <p>For more information about <code>-logger</code> and
  75. <code>-listener</code> see the section <a
  76. href="listeners.html">Loggers &amp; Listeners</a>
  77. <h3>Examples</h3>
  78. <blockquote>
  79. <pre>ant</pre>
  80. </blockquote>
  81. <p>runs Ant using the <code>build.xml</code> file in the current directory, on
  82. the default target.</p>
  83. <blockquote>
  84. <pre>ant -buildfile test.xml</pre>
  85. </blockquote>
  86. <p>runs Ant using the <code>test.xml</code> file in the current directory, on
  87. the default target.</p>
  88. <blockquote>
  89. <pre>ant -buildfile test.xml dist</pre>
  90. </blockquote>
  91. <p>runs Ant using the <code>test.xml</code> file in the current directory, on a
  92. target called <code>dist</code>.</p>
  93. <blockquote>
  94. <pre>ant -buildfile test.xml -Dbuild=build/classes dist</pre>
  95. </blockquote>
  96. <p>runs Ant using the <code>test.xml</code> file in the current directory, on a
  97. target called <code>dist</code>, setting the <code>build</code> property to the
  98. value <code>build/classes</code>.</p>
  99. <h3><a name="files">Files</a></h3>
  100. <p>The Ant wrapper script for Unix will source (read and evaluate) the
  101. file <code>~/.antrc</code> before it does anything - the Windows batch
  102. file invokes <code>%HOME%\antrc_pre.bat</code> at the start and
  103. <code>%HOME%\antrc_post.bat</code> at the end. You can use these
  104. files to set/unset environment variables that should only be visible
  105. during the execution of Ant. See the next section for example.</p>
  106. <h3><a name="envvars">Environment Variables</a></h3>
  107. <p>The wrapper scripts use the following environment variables (if
  108. set):</p>
  109. <ul>
  110. <li><code>JAVACMD</code> - full path of the Java executable. Use this
  111. to invoke a different JVM than <code>JAVA_HOME/bin/java(.exe)</code>.</li>
  112. <li><code>ANT_OPTS</code> - command-line arguments that should be
  113. passed to the JVM. For example, you can define properties or set
  114. the maximum Java heap size here.</li>
  115. <li><code>ANT_ARGS</code> - Ant command-line arguments. For example,
  116. set <code>ANT_ARGS</code> to point to a different logger and to
  117. include the <code>-find</code> flag.</li>
  118. </ul>
  119. <h2><a name="viajava">Running Ant via Java</a></h2>
  120. <p>If you have installed Ant in the do-it-yourself way, Ant can be started
  121. with:</p>
  122. <blockquote>
  123. <pre>java -Dant.home=c:\ant org.apache.tools.ant.Main [options] [target]</pre>
  124. </blockquote>
  125. <p>These instructions actually do exactly the same as the <code>ant</code>
  126. command. The options and target are the same as when running Ant with the <code>ant</code>
  127. command. This example assumes you have set your classpath to include:</p>
  128. <ul>
  129. <li><code>ant.jar</code></li>
  130. <li>jars/classes for your XML parser</li>
  131. <li>the JDK's required jar/zip files</li>
  132. </ul>
  133. <br>
  134. <hr>
  135. <p align="center">Copyright &copy; 2001 Apache Software Foundation. All rights
  136. Reserved.</p>
  137. </body>
  138. </html>