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.

javac.html 10 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Ant User Manual</title>
  5. </head>
  6. <body>
  7. <h2><a name="javac">Javac</a></h2>
  8. <h3>Description</h3>
  9. <p>Compiles a source tree within the running (Ant) VM.</p>
  10. <p>The source and destination directory will be recursively scanned for Java
  11. source files to compile. Only Java files that have no corresponding class file
  12. or where the class file is older than the java file will be compiled.</p>
  13. <p>Note: Ant uses only the names of the source and class files to find
  14. the classes that need a rebuild. It will not scan the source and therefor
  15. will have no knowledge about nested classes, classes that are named different
  16. from the source file and so on.</p>
  17. <p>The directory structure of the source tree should follow the package
  18. hierarchy.</p>
  19. <p>It is possible to refine the set of files that are being compiled/copied.
  20. This can be done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
  21. attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
  22. have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
  23. the files you want to have excluded. This is also done with patterns. And
  24. finally with the <i>defaultexcludes</i> attribute, you can specify whether you
  25. want to use default exclusions or not. See the section on <a
  26. href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
  27. inclusion/exclusion of files works, and how to write patterns.</p>
  28. <p>It is possible to use different compilers. This can be selected with the
  29. &quot;build.compiler&quot; property. There are four choices:</p>
  30. <ul>
  31. <li>classic (the standard compiler of JDK 1.1/1.2)</li>
  32. <li>modern (the new compiler of JDK 1.3)</li>
  33. <li>jikes (the <a
  34. href="http://oss.software.ibm.com/developerworks/opensource/jikes/project" target="_top">Jikes</a>
  35. compiler)</li>
  36. <li>jvc (the Command-Line Compiler from Microsoft's SDK for Java /
  37. Visual J++)</li>
  38. </ul>
  39. <p>For JDK 1.1/1.2, classic is the default. For JDK 1.3, modern is the default.
  40. If you wish to use a different compiler interface than one of the four
  41. supplied, write a class that implements the CompilerAdapter interface
  42. (package org.apache.tools.ant.taskdefs.compilers). Supply the full
  43. classname in the &quot;build.compiler&quot; property.
  44. </p>
  45. <h3>Parameters</h3>
  46. <table border="1" cellpadding="2" cellspacing="0">
  47. <tr>
  48. <td valign="top"><b>Attribute</b></td>
  49. <td valign="top"><b>Description</b></td>
  50. <td align="center" valign="top"><b>Required</b></td>
  51. </tr>
  52. <tr>
  53. <td valign="top">srcdir</td>
  54. <td valign="top">location of the java files. (See Notes at the end)</td>
  55. <td align="center" valign="top">Yes, unless nested <code>&lt;src&gt;</code> elements are present.</td>
  56. </tr>
  57. <tr>
  58. <td valign="top">destdir</td>
  59. <td valign="top">location to store the class files.</td>
  60. <td align="center" valign="top">No</td>
  61. </tr>
  62. <tr>
  63. <td valign="top">includes</td>
  64. <td valign="top">comma-separated list of patterns of files that must be
  65. included; all files are included when omitted.</td>
  66. <td valign="top" align="center">No</td>
  67. </tr>
  68. <tr>
  69. <td valign="top">includesfile</td>
  70. <td valign="top">the name of a file that contains
  71. include patterns.</td>
  72. <td valign="top" align="center">No</td>
  73. </tr>
  74. <tr>
  75. <td valign="top">excludes</td>
  76. <td valign="top">comma-separated list of patterns of files that must be
  77. excluded; no files (except default excludes) are excluded when omitted.</td>
  78. <td valign="top" align="center">No</td>
  79. </tr>
  80. <tr>
  81. <td valign="top">excludesfile</td>
  82. <td valign="top">the name of a file that contains
  83. exclude patterns.</td>
  84. <td valign="top" align="center">No</td>
  85. </tr>
  86. <tr>
  87. <td valign="top">defaultexcludes</td>
  88. <td valign="top">indicates whether default excludes should be used
  89. (<code>yes</code> | <code>no</code>); default excludes are used when omitted.</td>
  90. <td valign="top" align="center">No</td>
  91. </tr>
  92. <tr>
  93. <td valign="top">classpath</td>
  94. <td valign="top">the classpath to use.</td>
  95. <td align="center" valign="top">No</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">bootclasspath</td>
  99. <td valign="top">location of bootstrap class files.</td>
  100. <td align="center" valign="top">No</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">classpathref</td>
  104. <td valign="top">the classpath to use, given as a
  105. <a href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
  106. <td align="center" valign="top">No</td>
  107. </tr>
  108. <tr>
  109. <td valign="top">bootclasspathref</td>
  110. <td valign="top">location of bootstrap class files, given as a
  111. <a href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
  112. <td align="center" valign="top">No</td>
  113. </tr>
  114. <tr>
  115. <td valign="top">extdirs</td>
  116. <td valign="top">location of installed extensions.</td>
  117. <td align="center" valign="top">No</td>
  118. </tr>
  119. <tr>
  120. <td valign="top">encoding</td>
  121. <td valign="top">encoding of source files.</td>
  122. <td align="center" valign="top">No</td>
  123. </tr>
  124. <tr>
  125. <td valign="top">debug</td>
  126. <td valign="top">indicates whether source should be compiled with debug
  127. information; defaults to <code>off</code>.</td>
  128. <td align="center" valign="top">No</td>
  129. </tr>
  130. <tr>
  131. <td valign="top">optimize</td>
  132. <td valign="top">indicates whether source should be compiled with
  133. optimization; defaults to <code>off</code>.</td>
  134. <td align="center" valign="top">No</td>
  135. </tr>
  136. <tr>
  137. <td valign="top">deprecation</td>
  138. <td valign="top">indicates whether source should be compiled with
  139. deprecation information; defaults to <code>off</code>.</td>
  140. <td align="center" valign="top">No</td>
  141. </tr>
  142. <tr>
  143. <td valign="top">target</td>
  144. <td valign="top">generate class files for specific VM version (e.g.,
  145. <code>1.1</code> or <code>1.2</code>).</td>
  146. <td align="center" valign="top">No</td>
  147. </tr>
  148. <tr>
  149. <td valign="top">verbose</td>
  150. <td valign="top">asks the compiler for verbose output.</td>
  151. <td align="center" valign="top">No</td>
  152. </tr>
  153. <tr>
  154. <td valign="top">depend</td> <td valign="top">enables dependency-tracking
  155. for compilers that support this (jikes and classic)</td>
  156. <td align="center" valign="top">No</td>
  157. </tr>
  158. <tr>
  159. <td valign="top">includeAntRuntime</td>
  160. <td valign="top">whether to include the Ant run-time libraries;
  161. defaults to <code>yes</code>.</td>
  162. <td align="center" valign="top">No</td>
  163. </tr>
  164. <tr>
  165. <td valign="top">includeJavaRuntime</td>
  166. <td valign="top">whether to include the default run-time
  167. libraries from the executing VM; defaults to <code>no</code>.</td>
  168. <td align="center" valign="top">No</td>
  169. </tr>
  170. <tr>
  171. <td valign="top">failonerror</td> <td valign="top">
  172. indicates whether the build will continue even if there are compilation errors; defaults to <code>true</code>.
  173. </td>
  174. <td align="center" valign="top">No</td>
  175. </tr>
  176. </table>
  177. <h3>Parameters specified as nested elements</h3>
  178. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
  179. supports all attributes of <code>&lt;fileset&gt;</code>
  180. (<code>dir</code> becomes <code>srcdir</code>) as well as the nested
  181. <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  182. <code>&lt;patternset&gt;</code> elements.</p>
  183. <h4><code>src</code>, <code>classpath</code>, <code>bootclasspath</code> and <code>extdirs</code></h4>
  184. <p><code>Javac</code>'s <i>srcdir</i>, <i>classpath</i>,
  185. <i>bootclasspath</i> and <i>extdirs</i> attributes are <a
  186. href="../using.html#path">path-like structures</a> and can also be set via nested
  187. <code>&lt;src&gt</code>,
  188. <code>&lt;classpath&gt</code>,
  189. <code>&lt;bootclasspath&gt</code> and
  190. <code>&lt;extdirs&gt</code> elements, respectively.</p>
  191. <h3>Examples</h3>
  192. <pre> &lt;javac srcdir=&quot;${src}&quot;
  193. destdir=&quot;${build}&quot;
  194. classpath=&quot;xyz.jar&quot;
  195. debug=&quot;on&quot;
  196. /&gt;</pre>
  197. <p>compiles all <code>.java</code> files under the <code>${src}</code>
  198. directory, and stores
  199. the <code>.class</code> files in the <code>${build}</code> directory.
  200. The classpath used contains <code>xyz.jar</code>, and debug information is on.</p>
  201. <pre> &lt;javac srcdir=&quot;${src}&quot;
  202. destdir=&quot;${build}&quot;
  203. includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
  204. excludes=&quot;mypackage/p1/testpackage/**&quot;
  205. classpath=&quot;xyz.jar&quot;
  206. debug=&quot;on&quot;
  207. /&gt;</pre>
  208. <p>compiles <code>.java</code> files under the <code>${src}</code>
  209. directory, and stores the
  210. <code>.class</code> files in the <code>${build}</code> directory.
  211. The classpath used contains <code>xyz.jar</code>, and debug information is on.
  212. Only files under <code>mypackage/p1</code> and <code>mypackage/p2</code> are
  213. used. Files in the <code>mypackage/p1/testpackage</code> directory are excluded
  214. from compilation.</p>
  215. <pre> &lt;javac srcdir=&quot;${src}:${src2}&quot;
  216. destdir=&quot;${build}&quot;
  217. includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
  218. excludes=&quot;mypackage/p1/testpackage/**&quot;
  219. classpath=&quot;xyz.jar&quot;
  220. debug=&quot;on&quot;
  221. /&gt;</pre>
  222. <p>is the same as the previous example, with the addition of a second
  223. source path, defined by
  224. the property <code>src2</code>. This can also be represented using nested
  225. <code>&lt;src&gt;</code> elements as follows:</p>
  226. <pre> &lt;javac destdir=&quot;${build}&quot;
  227. classpath=&quot;xyz.jar&quot;
  228. debug=&quot;on&quot;&gt;
  229. &lt;src path=&quot;${src}&quot;/&gt;
  230. &lt;src path=&quot;${src2}&quot;/&gt;
  231. &lt;include name=&quot;mypackage/p1/**&quot;/&gt;
  232. &lt;include name=&quot;mypackage/p2/**&quot;/&gt;
  233. &lt;exclude name=&quot;mypackage/p1/testpackage/**&quot;/&gt;
  234. &lt;/javac&gt;</pre>
  235. <p><b>Note:</b> If you are using Ant on Windows and a new DOS window pops up
  236. for every use of an external compiler, this may be a problem of the JDK you are using.
  237. This problem may occur with all JDKs &lt; 1.2.</p>
  238. <p><b>Note:</b> If you wish to compile only source-files located in some packages below a
  239. common root you should not include these packages in the srcdir-attribute. Use include/exclude-attributes
  240. or elements to filter for these packages. If you include part of your package-structure inside the srcdir-attribute
  241. (or nested src-elements) Ant will start to recompile your sources everytime you call it.</p>
  242. <hr>
  243. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  244. Reserved.</p>
  245. </body>
  246. </html>