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

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