source: other-projects/trunk/realistic-books/packages/AntInstaller/web/manual/manual/CoreTasks/javac.html@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

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