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 14 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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 Java source tree.</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. Here are the choices:-</p>
  30. <ul>
  31. <li>classic (the standard compiler of JDK 1.1/1.2) - javac1.1 and
  32. javac1.2 can be used as aliases</li>
  33. <li>modern (the standard compiler of JDK 1.3/1.4) - javac1.3 and
  34. javac1.4 can be used as aliases</li>
  35. <li>jikes (the <a
  36. href="http://oss.software.ibm.com/developerworks/opensource/jikes/project" target="_top">Jikes</a>
  37. compiler)</li>
  38. <li>jvc (the Command-Line Compiler from Microsoft's SDK for Java /
  39. Visual J++) - microsoft can be used as an alias</li>
  40. <li>kjc (the <a href="http://www.dms.at/kopi/" target="_top">kopi</a>
  41. compiler)</li>
  42. <li>gcj (the gcj compiler from gcc)</li>
  43. <li>sj (Symantec java compiler) - symantec can be used as an alias</li>
  44. <li>extJavac (run either modern or classic in a JVM of its own)</li>
  45. </ul>
  46. <p>For JDK 1.1/1.2, classic is the default. For JDK 1.3/1.4, modern is the default.
  47. If you wish to use a different compiler interface than those
  48. supplied, write a class that implements the CompilerAdapter interface
  49. (package org.apache.tools.ant.taskdefs.compilers). Supply the full
  50. classname in the &quot;build.compiler&quot; property.
  51. </p>
  52. <p>The fork attribute overrides the build.compiler setting and expects
  53. a JDK1.1 or higher to be set in java.home.
  54. </p>
  55. <p>This task will drop all entries that point to non-existant
  56. files/directories from the CLASSPATH it passes to the compiler.</p>
  57. <h3>Parameters</h3>
  58. <table border="1" cellpadding="2" cellspacing="0">
  59. <tr>
  60. <td valign="top"><b>Attribute</b></td>
  61. <td valign="top"><b>Description</b></td>
  62. <td align="center" valign="top"><b>Required</b></td>
  63. </tr>
  64. <tr>
  65. <td valign="top">srcdir</td>
  66. <td valign="top">location of the java files. (See Notes at the end)</td>
  67. <td align="center" valign="top">Yes, unless nested <code>&lt;src&gt;</code> elements are present.</td>
  68. </tr>
  69. <tr>
  70. <td valign="top">destdir</td>
  71. <td valign="top">location to store the class files.</td>
  72. <td align="center" valign="top">No</td>
  73. </tr>
  74. <tr>
  75. <td valign="top">includes</td>
  76. <td valign="top">comma-separated list of patterns of files that must be
  77. included; all files are included when omitted.</td>
  78. <td valign="top" align="center">No</td>
  79. </tr>
  80. <tr>
  81. <td valign="top">includesfile</td>
  82. <td valign="top">the name of a file that contains
  83. include patterns.</td>
  84. <td valign="top" align="center">No</td>
  85. </tr>
  86. <tr>
  87. <td valign="top">excludes</td>
  88. <td valign="top">comma-separated list of patterns of files that must be
  89. excluded; no files (except default excludes) are excluded when omitted.</td>
  90. <td valign="top" align="center">No</td>
  91. </tr>
  92. <tr>
  93. <td valign="top">excludesfile</td>
  94. <td valign="top">the name of a file that contains
  95. exclude patterns.</td>
  96. <td valign="top" align="center">No</td>
  97. </tr>
  98. <tr>
  99. <td valign="top">defaultexcludes</td>
  100. <td valign="top">indicates whether default excludes should be used
  101. (<code>yes</code> | <code>no</code>); default excludes are used when omitted.</td>
  102. <td valign="top" align="center">No</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">classpath</td>
  106. <td valign="top">the classpath to use.</td>
  107. <td align="center" valign="top">No</td>
  108. </tr>
  109. <tr>
  110. <td valign="top">bootclasspath</td>
  111. <td valign="top">location of bootstrap class files.</td>
  112. <td align="center" valign="top">No</td>
  113. </tr>
  114. <tr>
  115. <td valign="top">classpathref</td>
  116. <td valign="top">the classpath to use, given as a
  117. <a href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
  118. <td align="center" valign="top">No</td>
  119. </tr>
  120. <tr>
  121. <td valign="top">bootclasspathref</td>
  122. <td valign="top">location of bootstrap class files, given as a
  123. <a href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
  124. <td align="center" valign="top">No</td>
  125. </tr>
  126. <tr>
  127. <td valign="top">extdirs</td>
  128. <td valign="top">location of installed extensions.</td>
  129. <td align="center" valign="top">No</td>
  130. </tr>
  131. <tr>
  132. <td valign="top">encoding</td>
  133. <td valign="top">encoding of source files. (gcj doesn't support
  134. this option yet)</td>
  135. <td align="center" valign="top">No</td>
  136. </tr>
  137. <tr>
  138. <td valign="top">nowarn</td>
  139. <td valign="top">indicates whether -nowarn switch should be passed
  140. to the compiler; defaults to <code>off</code>.</td>
  141. <td align="center" valign="top">No</td>
  142. </tr>
  143. <tr>
  144. <td valign="top">debug</td>
  145. <td valign="top">indicates whether source should be compiled with debug
  146. information; defaults to <code>off</code>.</td>
  147. <td align="center" valign="top">No</td>
  148. </tr>
  149. <tr>
  150. <td valign="top">optimize</td>
  151. <td valign="top">indicates whether source should be compiled with
  152. optimization; defaults to <code>off</code>.</td>
  153. <td align="center" valign="top">No</td>
  154. </tr>
  155. <tr>
  156. <td valign="top">deprecation</td>
  157. <td valign="top">indicates whether source should be compiled with
  158. deprecation information; defaults to <code>off</code>.</td>
  159. <td align="center" valign="top">No</td>
  160. </tr>
  161. <tr>
  162. <td valign="top">target</td>
  163. <td valign="top">generate class files for specific VM version (e.g.,
  164. <code>1.1</code> or <code>1.2</code>).</td>
  165. <td align="center" valign="top">No</td>
  166. </tr>
  167. <tr>
  168. <td valign="top">verbose</td>
  169. <td valign="top">asks the compiler for verbose output.</td>
  170. <td align="center" valign="top">No</td>
  171. </tr>
  172. <tr>
  173. <td valign="top">depend</td> <td valign="top">enables dependency-tracking
  174. for compilers that support this (jikes and classic)</td>
  175. <td align="center" valign="top">No</td>
  176. </tr>
  177. <tr>
  178. <td valign="top">includeAntRuntime</td>
  179. <td valign="top">whether to include the Ant run-time libraries;
  180. defaults to <code>yes</code>.</td>
  181. <td align="center" valign="top">No</td>
  182. </tr>
  183. <tr>
  184. <td valign="top">includeJavaRuntime</td>
  185. <td valign="top">whether to include the default run-time
  186. libraries from the executing VM; defaults to <code>no</code>.</td>
  187. <td align="center" valign="top">No</td>
  188. </tr>
  189. <tr>
  190. <td valign="top">fork</td>
  191. <td valign="top">whether to execute Javac using the JDK compiler externally;
  192. defaults to <code>no</code>.</td>
  193. <td align="center" valign="top">No</td>
  194. </tr>
  195. <tr>
  196. <td valign="top">memoryInitialSize</td>
  197. <td valign="top">the initial size of the memory for the underlying VM, if javac is run
  198. externally, ignored otherwise; defaults to the standard VM memory setting.
  199. (examples: <code>83886080</code>, <code>81920k</code>, or <code>80m</code>)</td>
  200. <td align="center" valign="top">No</td>
  201. </tr>
  202. <tr>
  203. <td valign="top">memoryMaximumSize</td>
  204. <td valign="top">the maximum size of the memory for the underlying VM, if javac is run
  205. externally, ignored otherwise; defaults to the standard VM memory setting.
  206. (examples: <code>83886080</code>, <code>81920k</code>, or <code>80m</code>)</td>
  207. <td align="center" valign="top">No</td>
  208. </tr>
  209. <tr>
  210. <td valign="top">failonerror</td> <td valign="top">
  211. indicates whether the build will continue even if there are compilation errors; defaults to <code>true</code>.
  212. </td>
  213. <td align="center" valign="top">No</td>
  214. </tr>
  215. </table>
  216. <h3>Parameters specified as nested elements</h3>
  217. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
  218. supports all attributes of <code>&lt;fileset&gt;</code>
  219. (<code>dir</code> becomes <code>srcdir</code>) as well as the nested
  220. <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  221. <code>&lt;patternset&gt;</code> elements.</p>
  222. <h4><code>src</code>, <code>classpath</code>, <code>bootclasspath</code> and <code>extdirs</code></h4>
  223. <p><code>Javac</code>'s <i>srcdir</i>, <i>classpath</i>,
  224. <i>bootclasspath</i> and <i>extdirs</i> attributes are <a
  225. href="../using.html#path">path-like structures</a> and can also be set via nested
  226. <code>&lt;src&gt</code>,
  227. <code>&lt;classpath&gt</code>,
  228. <code>&lt;bootclasspath&gt</code> and
  229. <code>&lt;extdirs&gt</code> elements, respectively.</p>
  230. <h3>Examples</h3>
  231. <pre> &lt;javac srcdir=&quot;${src}&quot;
  232. destdir=&quot;${build}&quot;
  233. classpath=&quot;xyz.jar&quot;
  234. debug=&quot;on&quot;
  235. /&gt;</pre>
  236. <p>compiles all <code>.java</code> files under the <code>${src}</code>
  237. directory, and stores
  238. the <code>.class</code> files in the <code>${build}</code> directory.
  239. The classpath used contains <code>xyz.jar</code>, and debug information is on.</p>
  240. <pre> &lt;javac srcdir=&quot;${src}&quot;
  241. destdir=&quot;${build}&quot;
  242. includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
  243. excludes=&quot;mypackage/p1/testpackage/**&quot;
  244. classpath=&quot;xyz.jar&quot;
  245. debug=&quot;on&quot;
  246. /&gt;</pre>
  247. <p>compiles <code>.java</code> files under the <code>${src}</code>
  248. directory, and stores the
  249. <code>.class</code> files in the <code>${build}</code> directory.
  250. The classpath used contains <code>xyz.jar</code>, and debug information is on.
  251. Only files under <code>mypackage/p1</code> and <code>mypackage/p2</code> are
  252. used. Files in the <code>mypackage/p1/testpackage</code> directory are excluded
  253. from compilation.</p>
  254. <pre> &lt;javac srcdir=&quot;${src}:${src2}&quot;
  255. destdir=&quot;${build}&quot;
  256. includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
  257. excludes=&quot;mypackage/p1/testpackage/**&quot;
  258. classpath=&quot;xyz.jar&quot;
  259. debug=&quot;on&quot;
  260. /&gt;</pre>
  261. <p>is the same as the previous example, with the addition of a second
  262. source path, defined by
  263. the property <code>src2</code>. This can also be represented using nested
  264. <code>&lt;src&gt;</code> elements as follows:</p>
  265. <pre> &lt;javac destdir=&quot;${build}&quot;
  266. classpath=&quot;xyz.jar&quot;
  267. debug=&quot;on&quot;&gt;
  268. &lt;src path=&quot;${src}&quot;/&gt;
  269. &lt;src path=&quot;${src2}&quot;/&gt;
  270. &lt;include name=&quot;mypackage/p1/**&quot;/&gt;
  271. &lt;include name=&quot;mypackage/p2/**&quot;/&gt;
  272. &lt;exclude name=&quot;mypackage/p1/testpackage/**&quot;/&gt;
  273. &lt;/javac&gt;</pre>
  274. <p><b>Note:</b> If you are using Ant on Windows and a new DOS window pops up
  275. for every use of an external compiler, this may be a problem of the JDK you are using.
  276. This problem may occur with all JDKs &lt; 1.2.</p>
  277. <p><b>Note:</b> If you wish to compile only source-files located in some packages below a
  278. common root you should not include these packages in the srcdir-attribute. Use include/exclude-attributes
  279. or elements to filter for these packages. If you include part of your package-structure inside the srcdir-attribute
  280. (or nested src-elements) Ant will start to recompile your sources every time you call it.</p>
  281. <h3>Jikes Notes</h3>
  282. If the environment variable <tt>JIKES_HOME</tt> is set to the location
  283. of the jikes compiler, then the standard Ant invocation scripts
  284. automatically set build.compiler to &quot;jikes&quot;. This enables one to use
  285. jikes when available, without having to commit the build file to a
  286. single choice of compiler.
  287. <p>
  288. Jikes also supports some extra options, which can be set be defining
  289. properties prior to invoking the task. The ant developers are aware that
  290. this is ugly and inflexible -expect a better solution in the future. All
  291. the options are boolean, and must be set to &quot;true&quot; or &quot;yes&quot; to be
  292. interpreted as anything other than false; by default
  293. build.compiler.warnings is &quot;true&quot; while all others are &quot;false&quot;</p>
  294. <table border="1" cellpadding="2" cellspacing="0">
  295. <tr>
  296. <td valign="top">
  297. build.compiler.emacs
  298. </td>
  299. <td valign="top">
  300. Enable emacs compatible error messages
  301. </td>
  302. </tr>
  303. <tr>
  304. <td valign="top">
  305. build.compiler.warnings<br>
  306. <b>This property has been deprecated, use the nowarn attribute
  307. instead</b>
  308. </td>
  309. <td valign="top">
  310. don't disable warning messages
  311. </td>
  312. </tr>
  313. <tr>
  314. <td valign="top">
  315. build.compiler.pedantic
  316. </td>
  317. <td valign="top">
  318. enable pedantic warnings
  319. </td>
  320. </tr>
  321. <tr>
  322. <td valign="top">
  323. build.compiler.fulldepend
  324. </td>
  325. <td valign="top">
  326. enable full dependency checking,<br>
  327. &quot;+F&quot; in the jikes manual.
  328. </td>
  329. </tr>
  330. </table>
  331. <hr>
  332. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  333. Reserved.</p>
  334. </body>
  335. </html>