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 25 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <html lang="en-us">
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  5. <title>Javac Task</title>
  6. </head>
  7. <body>
  8. <h2><a name="javac">Javac</a></h2>
  9. <h3>Description</h3>
  10. <p>Compiles a Java source tree.</p>
  11. <p>The source and destination directory will be recursively scanned for Java
  12. source files to compile. Only Java files that have no corresponding
  13. <code>.class</code> file
  14. or where the class file is older than the
  15. <code>.java</code> file will be compiled.</p>
  16. <p>Note: Ant uses only the names of the source and class files to find
  17. the classes that need a rebuild. It will not scan the source and therefore
  18. will have no knowledge about nested classes, classes that are named different
  19. from the source file, and so on. See the
  20. <a href="../OptionalTasks/depend.html"><code>&lt;depend&gt;</code></a> task
  21. for dependency checking based on other than just
  22. existence/modification times.</p>
  23. <p>When the source files are part of a package, the directory structure of
  24. the source tree should follow the package
  25. hierarchy.</p>
  26. <p>It is possible to refine the set of files that are being compiled.
  27. This can be done with the <code>includes</code>, <code>includesfile</code>,
  28. <code>excludes</code>, and <code>excludesfile</code>
  29. attributes. With the <code>includes</code> or
  30. <code>includesfile</code> attribute, you specify the files you want to
  31. have included.
  32. The <code>exclude</code> or <code>excludesfile</code> attribute is used
  33. to specify
  34. the files you want to have excluded. In both cases, the list of files
  35. can be specified by either the filename, relative to the directory(s) specified
  36. in the <code>srcdir</code> attribute or nested <code>&lt;src&gt;</code>
  37. element(s), or by using wildcard patterns. See the section on
  38. <a href="../dirtasks.html#directorybasedtasks">directory-based tasks</a>,
  39. for information on how the
  40. inclusion/exclusion of files works, and how to write wildcard patterns.</p>
  41. <p>It is possible to use different compilers. This can be specified by
  42. either setting the global <code>build.compiler</code> property, which will
  43. affect all <code>&lt;javac&gt;</code> tasks throughout the build, or by
  44. setting the <code>compiler</code> attribute, specific to the current
  45. <code>&lt;javac&gt;</code> task.
  46. <a name="compilervalues">Valid values for either the
  47. <code>build.compiler</code> property or the <code>compiler</code>
  48. attribute are:</a></p>
  49. <ul>
  50. <li><code>classic</code> (the standard compiler of JDK 1.1/1.2) &ndash;
  51. <code>javac1.1</code> and
  52. <code>javac1.2</code> can be used as aliases.</li>
  53. <li><code>modern</code> (the standard compiler of JDK 1.3/1.4/1.5/1.6) &ndash;
  54. <code>javac1.3</code> and
  55. <code>javac1.4</code> and
  56. <code>javac1.5</code> and
  57. <code>javac1.6</code> can be used as aliases.</li>
  58. <li><code>jikes</code> (the <a
  59. href="http://jikes.sourceforge.net/" target="_top">Jikes</a>
  60. compiler).</li>
  61. <li><code>jvc</code> (the Command-Line Compiler from Microsoft's SDK
  62. for Java / Visual J++) &ndash; <code>microsoft</code> can be used
  63. as an alias.</li>
  64. <li><code>kjc</code> (the <a href="http://www.dms.at/kopi/" target="_top">kopi</a>
  65. compiler).</li>
  66. <li><code>gcj</code> (the gcj compiler from gcc).</li>
  67. <li><code>sj</code> (Symantec java compiler) &ndash;
  68. <code>symantec</code> can be used as an alias.</li>
  69. <li><code>extJavac</code> (run either modern or classic in a JVM of
  70. its own).</li>
  71. </ul>
  72. <p>The default is <code>javac1.x</code> with <code>x</code> depending
  73. on the JDK version you use while you are running Ant.
  74. If you wish to use a different compiler interface than those
  75. supplied, you can write a class that implements the CompilerAdapter interface
  76. (<code>package org.apache.tools.ant.taskdefs.compilers</code>). Supply the full
  77. classname in the <code>build.compiler</code> property or the
  78. <code>compiler</code> attribute.
  79. </p>
  80. <p>The fork attribute overrides the <code>build.compiler</code> property
  81. or <code>compiler</code> attribute setting and
  82. expects a JDK1.1 or higher to be set in <code>JAVA_HOME</code>.
  83. </p>
  84. <p>You can also use the <code>compiler</code> attribute to tell Ant
  85. which JDK version it shall assume when it puts together the command
  86. line switches - even if you set <code>fork=&quot;true&quot;</code>.
  87. This is useful if you want to run the compiler of JDK 1.1 while you
  88. current JDK is 1.2+. If you use
  89. <code>compiler=&quot;javac1.1&quot;</code> and (for example)
  90. <code>depend=&quot;true&quot;</code> Ant will use the command line
  91. switch <code>-depend</code> instead of <code>-Xdepend</code>.</p>
  92. <p>This task will drop all entries that point to non-existent
  93. files/directories from the classpath it passes to the compiler.</p>
  94. <p><strong>Windows Note:</strong>When the modern compiler is used
  95. in unforked mode on Windows, it locks up the files present in the
  96. classpath of the <code>&lt;javac&gt;</code> task, and does not release them.
  97. The side effect of this is that you will not be able to delete or move
  98. those files later on in the build. The workaround is to fork when
  99. invoking the compiler.</p>
  100. <h3>Parameters</h3>
  101. <table border="1" cellpadding="2" cellspacing="0">
  102. <tr>
  103. <td valign="top"><b>Attribute</b></td>
  104. <td valign="top"><b>Description</b></td>
  105. <td align="center" valign="top"><b>Required</b></td>
  106. </tr>
  107. <tr>
  108. <td valign="top">srcdir</td>
  109. <td valign="top">Location of the java files. (See the
  110. <a href="#srcdirnote">note</a> below.)</td>
  111. <td align="center" valign="top">Yes, unless nested <code>&lt;src&gt;</code> elements are present.</td>
  112. </tr>
  113. <tr>
  114. <td valign="top">destdir</td>
  115. <td valign="top">Location to store the class files.</td>
  116. <td align="center" valign="top">No</td>
  117. </tr>
  118. <tr>
  119. <td valign="top">includes</td>
  120. <td valign="top">Comma- or space-separated list of files (may be specified using
  121. wildcard patterns) that must be
  122. included; all <code>.java</code> files are included when omitted.</td>
  123. <td valign="top" align="center">No</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">includesfile</td>
  127. <td valign="top">The name of a file that contains a list of files to
  128. include (may be specified using wildcard patterns).</td>
  129. <td valign="top" align="center">No</td>
  130. </tr>
  131. <tr>
  132. <td valign="top">excludes</td>
  133. <td valign="top">Comma- or space-separated list of files (may be specified using
  134. wildcard patterns) that must be excluded; no files (except default
  135. excludes) are excluded when omitted.</td>
  136. <td valign="top" align="center">No</td>
  137. </tr>
  138. <tr>
  139. <td valign="top">excludesfile</td>
  140. <td valign="top">The name of a file that contains a list of files to
  141. exclude (may be specified using wildcard patterns).</td>
  142. <td valign="top" align="center">No</td>
  143. </tr>
  144. <tr>
  145. <td valign="top">classpath</td>
  146. <td valign="top">The classpath to use.</td>
  147. <td align="center" valign="top">No</td>
  148. </tr>
  149. <tr>
  150. <td valign="top">sourcepath</td>
  151. <td valign="top">The sourcepath to use; defaults to the value of the srcdir attribute (or nested <code>&lt;src&gt;</code> elements).
  152. To suppress the sourcepath switch, use <code>sourcepath=&quot;&quot;</code>.</td>
  153. <td align="center" valign="top">No</td>
  154. </tr>
  155. <tr>
  156. <td valign="top">bootclasspath</td>
  157. <td valign="top">Location of bootstrap class files.</td>
  158. <td align="center" valign="top">No</td>
  159. </tr>
  160. <tr>
  161. <td valign="top">classpathref</td>
  162. <td valign="top">The classpath to use, given as a
  163. <a href="../using.html#references">reference</a> to a path defined elsewhere.</td>
  164. <td align="center" valign="top">No</td>
  165. </tr>
  166. <tr>
  167. <td valign="top">sourcepathref</td>
  168. <td valign="top">The sourcepath to use, given as a
  169. <a href="../using.html#references">reference</a> to a path defined elsewhere.</td>
  170. <td align="center" valign="top">No</td>
  171. </tr>
  172. <tr>
  173. <td valign="top">bootclasspathref</td>
  174. <td valign="top">Location of bootstrap class files, given as a
  175. <a href="../using.html#references">reference</a> to a path defined elsewhere.</td>
  176. <td align="center" valign="top">No</td>
  177. </tr>
  178. <tr>
  179. <td valign="top">extdirs</td>
  180. <td valign="top">Location of installed extensions.</td>
  181. <td align="center" valign="top">No</td>
  182. </tr>
  183. <tr>
  184. <td valign="top">encoding</td>
  185. <td valign="top">Encoding of source files. (Note: gcj doesn't support
  186. this option yet.)</td>
  187. <td align="center" valign="top">No</td>
  188. </tr>
  189. <tr>
  190. <td valign="top">nowarn</td>
  191. <td valign="top">Indicates whether the <code>-nowarn</code> switch
  192. should be passed to the compiler; defaults to <code>off</code>.</td>
  193. <td align="center" valign="top">No</td>
  194. </tr>
  195. <tr>
  196. <td valign="top">debug</td>
  197. <td valign="top">Indicates whether source should be compiled with
  198. debug information; defaults to <code>off</code>. If set to
  199. <code>off</code>, <code>-g:none</code> will be passed on the
  200. command line for compilers that support it (for other compilers, no
  201. command line argument will be used). If set to <code>true</code>,
  202. the value of the <code>debuglevel</code> attribute determines the
  203. command line argument.</td>
  204. <td align="center" valign="top">No</td>
  205. </tr>
  206. <tr>
  207. <td valign="top">debuglevel</td>
  208. <td valign="top">Keyword list to be appended to the <code>-g</code>
  209. command-line switch. This will be ignored by all implementations except
  210. <code>modern</code>, <code>classic(ver &gt;= 1.2)</code> and <code>jikes</code>.
  211. Legal values are <code>none</code> or a comma-separated list of the
  212. following keywords:
  213. <code>lines</code>, <code>vars</code>, and <code>source</code>.
  214. If <code>debuglevel</code> is not specified, by default,
  215. nothing will be
  216. appended to <code>-g</code>. If <code>debug</code> is not turned on,
  217. this attribute will be ignored.
  218. </td>
  219. <td align="center" valign="top">No</td>
  220. </tr>
  221. <tr>
  222. <td valign="top">optimize</td>
  223. <td valign="top">Indicates whether source should be compiled with
  224. optimization; defaults to <code>off</code>.</td>
  225. <td align="center" valign="top">No</td>
  226. </tr>
  227. <tr>
  228. <td valign="top">deprecation</td>
  229. <td valign="top">Indicates whether source should be compiled with
  230. deprecation information; defaults to <code>off</code>.</td>
  231. <td align="center" valign="top">No</td>
  232. </tr>
  233. <tr>
  234. <td valign="top">target</td>
  235. <td valign="top">Generate class files for specific VM version
  236. (e.g., <code>1.1</code> or <code>1.2</code>). <b>Note that the
  237. default value depends on the JVM that is running Ant. In
  238. particular, if you use JDK 1.4+ the generated classes will not be
  239. usable for a 1.1 Java VM unless you explicitly set this attribute
  240. to the value 1.1 (which is the default value for JDK 1.1 to
  241. 1.3). We highly recommend to always specify this
  242. attribute.</b><br>
  243. A default value for this attribute can be provided using the magic
  244. <a
  245. href="../javacprops.html#target"><code>ant.build.javac.target</code></a>
  246. property.</td>
  247. <td align="center" valign="top">No</td>
  248. </tr>
  249. <tr>
  250. <td valign="top">verbose</td>
  251. <td valign="top">Asks the compiler for verbose output; defaults to
  252. <code>no</code>.</td>
  253. <td align="center" valign="top">No</td>
  254. </tr>
  255. <tr>
  256. <td valign="top">depend</td> <td valign="top">Enables dependency-tracking
  257. for compilers that support this (<code>jikes</code> and
  258. <code>classic</code>).</td>
  259. <td align="center" valign="top">No</td>
  260. </tr>
  261. <tr>
  262. <td valign="top">includeAntRuntime</td>
  263. <td valign="top">Whether to include the Ant run-time libraries in the
  264. classpath; defaults to <code>yes</code>.</td>
  265. <td align="center" valign="top">No</td>
  266. </tr>
  267. <tr>
  268. <td valign="top">includeJavaRuntime</td>
  269. <td valign="top">Whether to include the default run-time
  270. libraries from the executing VM in the classpath;
  271. defaults to <code>no</code>.</td>
  272. <td align="center" valign="top">No</td>
  273. </tr>
  274. <tr>
  275. <td valign="top">fork</td>
  276. <td valign="top">Whether to execute <code>javac</code> using the
  277. JDK compiler externally; defaults to <code>no</code>.</td>
  278. <td align="center" valign="top">No</td>
  279. </tr>
  280. <tr>
  281. <td valign="top">executable</td>
  282. <td valign="top">Complete path to the <code>javac</code>
  283. executable to use in case of <code>fork=&quot;yes&quot;</code>.
  284. Defaults to the compiler of the Java version that is currently
  285. running Ant. Ignored if <code>fork=&quot;no&quot;</code>.<br>
  286. Since Ant 1.6 this attribute can also be used to specify the
  287. path to the executable when using jikes, jvc, gcj or sj.</td>
  288. <td align="center" valign="top">No</td>
  289. </tr>
  290. <tr>
  291. <td valign="top">memoryInitialSize</td>
  292. <td valign="top">The initial size of the memory for the underlying VM,
  293. if <code>javac</code> is run externally; ignored otherwise. Defaults
  294. to the standard VM memory setting.
  295. (Examples: <code>83886080</code>, <code>81920k</code>, or
  296. <code>80m</code>)</td>
  297. <td align="center" valign="top">No</td>
  298. </tr>
  299. <tr>
  300. <td valign="top">memoryMaximumSize</td>
  301. <td valign="top">The maximum size of the memory for the underlying VM,
  302. if <code>javac</code> is run externally; ignored otherwise. Defaults
  303. to the standard VM memory setting.
  304. (Examples: <code>83886080</code>, <code>81920k</code>, or
  305. <code>80m</code>)</td>
  306. <td align="center" valign="top">No</td>
  307. </tr>
  308. <tr>
  309. <td valign="top">failonerror</td>
  310. <td valign="top">Indicates whether compilation errors
  311. will fail the build; defaults to <code>true</code>.</td>
  312. <td align="center" valign="top">No</td>
  313. </tr>
  314. <tr>
  315. <td valign="top">source</td>
  316. <td valign="top">Value of the <code>-source</code> command-line
  317. switch; will be ignored by all implementations prior to
  318. <code>javac1.4</code> (or <code>modern</code> when Ant is not
  319. running in a 1.3 VM) and <code>jikes</code>.<br> If you use this
  320. attribute together with <code>jikes</code>, you must make sure
  321. that your version of jikes supports the <code>-source</code>
  322. switch. By default, no <code>-source</code> argument will be used
  323. at all.<br>
  324. <b>Note that the default value depends on the JVM that is running
  325. Ant. We highly recommend to always specify this
  326. attribute.</b><br>
  327. A default value for this attribute can be provided using the magic
  328. <a
  329. href="../javacprops.html#source"><code>ant.build.javac.source</code></a>
  330. property.</td>
  331. <td align="center" valign="top">No</td>
  332. </tr>
  333. <tr>
  334. <td valign="top">compiler</td>
  335. <td valign="top">The compiler implementation to use.
  336. If this attribute is not set, the value of the
  337. <code>build.compiler</code> property, if set, will be used.
  338. Otherwise, the default compiler for the current VM will be used.
  339. (See the above <a href="#compilervalues">list</a> of valid
  340. compilers.)</td>
  341. <td align="center" valign="top">No</td>
  342. </tr>
  343. <tr>
  344. <td valign="top">listfiles</td>
  345. <td valign="top">Indicates whether the source files to be compiled will
  346. be listed; defaults to <code>no</code>.</td>
  347. <td align="center" valign="top">No</td>
  348. </tr>
  349. <tr>
  350. <td valign="top">tempdir</td>
  351. <td valign="top">Where Ant should place temporary files.
  352. This is only used if the task is forked and the
  353. command line args length exceeds 4k.
  354. <em>Since Ant 1.6</em>.</td>
  355. <td align="center" valign="top">
  356. No; default is <i>java.io.tmpdir</i>.
  357. </td>
  358. </tr>
  359. </table>
  360. <h3>Parameters specified as nested elements</h3>
  361. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
  362. supports all attributes of <code>&lt;fileset&gt;</code>
  363. (<code>dir</code> becomes <code>srcdir</code>) as well as the nested
  364. <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  365. <code>&lt;patternset&gt;</code> elements.</p>
  366. <h4><code>src</code>, <code>classpath</code>, <code>sourcepath</code>,
  367. <code>bootclasspath</code> and <code>extdirs</code></h4>
  368. <p><code>&lt;javac&gt;</code>'s <code>srcdir</code>, <code>classpath</code>,
  369. <code>sourcepath</code>, <code>bootclasspath</code>, and
  370. <code>extdirs</code> attributes are
  371. <a href="../using.html#path">path-like structures</a>
  372. and can also be set via nested
  373. <code>&lt;src&gt;</code>,
  374. <code>&lt;classpath&gt;</code>,
  375. <code>&lt;sourcepath&gt;</code>,
  376. <code>&lt;bootclasspath&gt;</code> and
  377. <code>&lt;extdirs&gt;</code> elements, respectively.</p>
  378. <h4>compilerarg</h4>
  379. <p>You can specify additional command line arguments for the compiler
  380. with nested <code>&lt;compilerarg&gt;</code> elements. These elements
  381. are specified like <a href="../using.html#arg">Command-line
  382. Arguments</a> but have an additional attribute that can be used to
  383. enable arguments only if a given compiler implementation will be
  384. used.</p>
  385. <table border="1" cellpadding="2" cellspacing="0">
  386. <tr>
  387. <td width="12%" valign="top"><b>Attribute</b></td>
  388. <td width="78%" valign="top"><b>Description</b></td>
  389. <td width="10%" valign="top"><b>Required</b></td>
  390. </tr>
  391. <tr>
  392. <td valign="top">value</td>
  393. <td align="center" rowspan="4">See
  394. <a href="../using.html#arg">Command-line Arguments</a>.</td>
  395. <td align="center" rowspan="4">Exactly one of these.</td>
  396. </tr>
  397. <tr>
  398. <td valign="top">line</td>
  399. </tr>
  400. <tr>
  401. <td valign="top">file</td>
  402. </tr>
  403. <tr>
  404. <td valign="top">path</td>
  405. </tr>
  406. <tr>
  407. <td valign="top">compiler</td>
  408. <td>Only pass the specified argument if the chosen
  409. compiler implementation matches the value of this attribute.
  410. Legal values are the
  411. same as those in the above <a href="#compilervalues">list</a> of valid
  412. compilers.)</td>
  413. <td align="center">No</td>
  414. </tr>
  415. </table>
  416. <h3>Examples</h3>
  417. <pre> &lt;javac srcdir=&quot;${src}&quot;
  418. destdir=&quot;${build}&quot;
  419. classpath=&quot;xyz.jar&quot;
  420. debug=&quot;on&quot;
  421. source=&quot;1.4&quot;
  422. /&gt;</pre>
  423. <p>compiles all <code>.java</code> files under the <code>${src}</code>
  424. directory, and stores
  425. the <code>.class</code> files in the <code>${build}</code> directory.
  426. The classpath used includes <code>xyz.jar</code>, and compiling with
  427. debug information is on. The source level is 1.4,
  428. so you can use <code>assert</code> statements.</p>
  429. <pre> &lt;javac srcdir=&quot;${src}&quot;
  430. destdir=&quot;${build}&quot;
  431. fork=&quot;true&quot;
  432. source=&quot;1.2&quot;
  433. target=&quot;1.2&quot;
  434. /&gt;</pre>
  435. <p>compiles all <code>.java</code> files under the <code>${src}</code>
  436. directory, and stores the <code>.class</code> files in the
  437. <code>${build}</code> directory. This will fork off the javac
  438. compiler using the default <code>javac</code> executable.
  439. The source level is 1.2 (similar to 1.1 or 1.3) and
  440. the class files should be runnable under JDK 1.2+ as well.</p>
  441. <pre> &lt;javac srcdir=&quot;${src}&quot;
  442. destdir=&quot;${build}&quot;
  443. fork=&quot;java$$javac.exe&quot;
  444. source=&quot;1.5&quot;
  445. /&gt;</pre>
  446. <p>compiles all <code>.java</code> files under the <code>${src}</code>
  447. directory, and stores the <code>.class</code> files in the
  448. <code>${build}</code> directory. This will fork off the javac
  449. compiler, using the executable named <code>java$javac.exe</code>. Note
  450. that the <code>$</code> sign needs to be escaped by a second one.
  451. The source level is 1.5, so you can use generics.</p>
  452. <pre> &lt;javac srcdir=&quot;${src}&quot;
  453. destdir=&quot;${build}&quot;
  454. includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
  455. excludes=&quot;mypackage/p1/testpackage/**&quot;
  456. classpath=&quot;xyz.jar&quot;
  457. debug=&quot;on&quot;
  458. /&gt;</pre>
  459. <p>compiles <code>.java</code> files under the <code>${src}</code>
  460. directory, and stores the
  461. <code>.class</code> files in the <code>${build}</code> directory.
  462. The classpath used includes <code>xyz.jar</code>, and debug information is on.
  463. Only files under <code>mypackage/p1</code> and <code>mypackage/p2</code> are
  464. used. All files in and below the <code>mypackage/p1/testpackage</code>
  465. directory are excluded from compilation.
  466. You didn't specify a source or target level,
  467. so the actual values used will depend on which JDK you ran Ant with.</p>
  468. <pre> &lt;javac srcdir=&quot;${src}:${src2}&quot;
  469. destdir=&quot;${build}&quot;
  470. includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
  471. excludes=&quot;mypackage/p1/testpackage/**&quot;
  472. classpath=&quot;xyz.jar&quot;
  473. debug=&quot;on&quot;
  474. /&gt;</pre>
  475. <p>is the same as the previous example, with the addition of a second
  476. source path, defined by
  477. the property <code>src2</code>. This can also be represented using nested
  478. <code>&lt;src&gt;</code> elements as follows:</p>
  479. <pre> &lt;javac destdir=&quot;${build}&quot;
  480. classpath=&quot;xyz.jar&quot;
  481. debug=&quot;on&quot;&gt;
  482. &lt;src path=&quot;${src}&quot;/&gt;
  483. &lt;src path=&quot;${src2}&quot;/&gt;
  484. &lt;include name=&quot;mypackage/p1/**&quot;/&gt;
  485. &lt;include name=&quot;mypackage/p2/**&quot;/&gt;
  486. &lt;exclude name=&quot;mypackage/p1/testpackage/**&quot;/&gt;
  487. &lt;/javac&gt;</pre>
  488. <p>If you want to run the javac compiler of a different JDK, you
  489. should tell Ant, where to find the compiler and which version of JDK
  490. you will be using so it can choose the correct command line switches.
  491. The following example executes a JDK 1.1 javac in a new process and
  492. uses the correct command line switches even when Ant is running in a
  493. Java VM of a different version:</p>
  494. <pre> &lt;javac srcdir=&quot;${src}&quot;
  495. destdir=&quot;${build}&quot;
  496. fork=&quot;yes&quot;
  497. executable=&quot;/opt/java/jdk1.1/bin/javac&quot;
  498. compiler=&quot;javac1.1&quot;
  499. /&gt;</pre>
  500. <p><a name="srcdirnote"><b>Note:</b></a>
  501. If you wish to compile only source files located in certain packages below a
  502. common root, use the <code>include</code>/<code>exclude</code> attributes
  503. or <code>&lt;include&gt;</code>/<code>&lt;exclude&gt;</code> nested elements
  504. to filter for these packages. Do not include part of your package structure
  505. in the <code>srcdir</code> attribute
  506. (or nested <code>&lt;src&gt;</code> elements), or Ant will recompile your
  507. source files every time you run your compile target. See the
  508. <a href="http://ant.apache.org/faq.html#always-recompiles">Ant FAQ</a>
  509. for additional information.</p>
  510. <p>
  511. If you wish to compile only files explicitly specified and disable
  512. javac's default searching mechanism then you can unset the sourcepath
  513. attribute:
  514. <pre> &lt;javac sourcepath=&quot;&quot; srcdir=&quot;${src}&quot;
  515. destdir=&quot;${build}&quot; &gt;
  516. &lt;include name="**/*.java"/&gt;
  517. &lt;exclude name="**/Example.java"/&gt;
  518. &lt;/javac&gt;</pre>
  519. That way the javac will compile all java source files under &quot;${src}&quot;
  520. directory but skip the examples. The compiler will even produce errors if some of
  521. the non-example files refers to them.
  522. </p>
  523. <p><b>Note:</b> If you are using Ant on Windows and a new DOS window pops up
  524. for every use of an external compiler, this may be a problem of the JDK you are
  525. using. This problem may occur with all JDKs &lt; 1.2.</p>
  526. <h3>Jikes Notes</h3>
  527. <p>You need Jikes 1.15 or later.</p>
  528. <p>Jikes supports some extra options, which can be set be defining
  529. the properties shown below prior to invoking the task. The setting
  530. for each property will be in affect for all <code>&lt;javac&gt;</code>
  531. tasks throughout the build.
  532. The Ant developers are aware that
  533. this is ugly and inflexible &ndash; expect a better solution in the future.
  534. All the options are boolean, and must be set to <code>true</code> or
  535. <code>yes</code> to be
  536. interpreted as anything other than false. By default,
  537. <code>build.compiler.warnings</code> is <code>true</code>,
  538. while all others are <code>false</code>.</p>
  539. <table border="1" cellpadding="2" cellspacing="0">
  540. <tr>
  541. <td valign="top"><b>Property</b></td>
  542. <td valign="top"><b>Description</b></td>
  543. <td align="center" valign="top"><b>Default</b></td>
  544. </tr>
  545. <tr>
  546. <td valign="top">
  547. build.compiler.emacs
  548. </td>
  549. <td valign="top">
  550. Enable emacs-compatible error messages.
  551. </td>
  552. <td valign="top">
  553. <code>false</code>
  554. </td>
  555. </tr>
  556. <tr>
  557. <td valign="top">
  558. build.compiler.fulldepend
  559. </td>
  560. <td valign="top">
  561. Enable full dependency checking; see<br>
  562. the <code>+F</code> switch in the Jikes manual.
  563. </td>
  564. <td valign="top">
  565. <code>false</code>
  566. </td>
  567. </tr>
  568. <tr>
  569. <td valign="top">
  570. build.compiler.pedantic
  571. </td>
  572. <td valign="top">
  573. Enable pedantic warnings.
  574. </td>
  575. <td valign="top">
  576. <code>false</code>
  577. </td>
  578. </tr>
  579. <tr>
  580. <td valign="top">
  581. build.compiler.warnings<br>
  582. <strong>Deprecated</strong>. Use
  583. <code>&lt;javac&gt;</code>'s <code>nowarn</code>
  584. attribute instead.
  585. </td>
  586. <td valign="top">
  587. Don't disable warning messages.
  588. </td>
  589. <td valign="top">
  590. <code>true</code>
  591. </td>
  592. </tr>
  593. </table>
  594. <h3>Jvc Notes</h3>
  595. <p>Jvc will enable Microsoft extensions unless you set the property
  596. <code>build.compiler.jvc.extensions</code> to false before invoking
  597. <code>&lt;javac&gt;</code>.</p>
  598. <hr>
  599. <p align="center">Copyright &copy; 2000-2006 The Apache Software Foundation.
  600. All rights Reserved.</p>
  601. </body>
  602. </html>