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

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