4
<meta http-equiv="Content-Language" content="en-us">
5
<title>Ant User Manual</title>
10
<h2><a name="javac">Javac</a></h2>
12
<p>Compiles a Java source tree.</p>
13
<p>The source and destination directory will be recursively scanned for Java
14
source files to compile. Only Java files that have no corresponding class file
15
or where the class file is older than the java 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 therefor
18
will have no knowledge about nested classes, classes that are named different
19
from the source file and so on.</p>
20
<p>The directory structure of the source tree should follow the package
22
<p>It is possible to refine the set of files that are being compiled/copied.
23
This can be done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
24
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
25
have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
26
the files you want to have excluded. This is also done with patterns. And
27
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
28
want to use default exclusions or not. See the section on <a
29
href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
30
inclusion/exclusion of files works, and how to write patterns.</p>
31
<p>It is possible to use different compilers. This can be selected with the
32
"build.compiler" property. Here are the choices:-</p>
34
<li>classic (the standard compiler of JDK 1.1/1.2) - javac1.1 and
35
javac1.2 can be used as aliases</li>
36
<li>modern (the standard compiler of JDK 1.3/1.4) - javac1.3 and
37
javac1.4 can be used as aliases</li>
39
href="http://oss.software.ibm.com/developerworks/opensource/jikes/project" target="_top">Jikes</a>
41
<li>jvc (the Command-Line Compiler from Microsoft's SDK for Java /
42
Visual J++) - microsoft can be used as an alias</li>
43
<li>kjc (the <a href="http://www.dms.at/kopi/" target="_top">kopi</a>
45
<li>gcj (the gcj compiler from gcc)</li>
46
<li>sj (Symantec java compiler) - symantec can be used as an alias</li>
47
<li>extJavac (run either modern or classic in a JVM of its own)</li>
49
<p>For JDK 1.1/1.2, classic is the default. For JDK 1.3/1.4, modern is the default.
50
If you wish to use a different compiler interface than those
51
supplied, write a class that implements the CompilerAdapter interface
52
(package org.apache.tools.ant.taskdefs.compilers). Supply the full
53
classname in the "build.compiler" property.
55
<p>The fork attribute overrides the build.compiler setting and expects
56
a JDK1.1 or higher to be set in java.home.
58
<p>This task will drop all entries that point to non-existant
59
files/directories from the CLASSPATH it passes to the compiler.</p>
61
<table border="1" cellpadding="2" cellspacing="0">
63
<td valign="top"><b>Attribute</b></td>
64
<td valign="top"><b>Description</b></td>
65
<td align="center" valign="top"><b>Required</b></td>
68
<td valign="top">srcdir</td>
69
<td valign="top">location of the java files. (See Notes at the end)</td>
70
<td align="center" valign="top">Yes, unless nested <code><src></code> elements are present.</td>
73
<td valign="top">destdir</td>
74
<td valign="top">location to store the class files.</td>
75
<td align="center" valign="top">No</td>
78
<td valign="top">includes</td>
79
<td valign="top">comma-separated list of patterns of files that must be
80
included; all files are included when omitted.</td>
81
<td valign="top" align="center">No</td>
84
<td valign="top">includesfile</td>
85
<td valign="top">the name of a file that contains
86
include patterns.</td>
87
<td valign="top" align="center">No</td>
90
<td valign="top">excludes</td>
91
<td valign="top">comma-separated list of patterns of files that must be
92
excluded; no files (except default excludes) are excluded when omitted.</td>
93
<td valign="top" align="center">No</td>
96
<td valign="top">excludesfile</td>
97
<td valign="top">the name of a file that contains
98
exclude patterns.</td>
99
<td valign="top" align="center">No</td>
102
<td valign="top">defaultexcludes</td>
103
<td valign="top">indicates whether default excludes should be used
104
(<code>yes</code> | <code>no</code>); default excludes are used when omitted.</td>
105
<td valign="top" align="center">No</td>
108
<td valign="top">classpath</td>
109
<td valign="top">the classpath to use.</td>
110
<td align="center" valign="top">No</td>
113
<td valign="top">bootclasspath</td>
114
<td valign="top">location of bootstrap class files.</td>
115
<td align="center" valign="top">No</td>
118
<td valign="top">classpathref</td>
119
<td valign="top">the classpath to use, given as a
120
<a href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
121
<td align="center" valign="top">No</td>
124
<td valign="top">bootclasspathref</td>
125
<td valign="top">location of bootstrap class files, given as a
126
<a href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
127
<td align="center" valign="top">No</td>
130
<td valign="top">extdirs</td>
131
<td valign="top">location of installed extensions.</td>
132
<td align="center" valign="top">No</td>
135
<td valign="top">encoding</td>
136
<td valign="top">encoding of source files. (gcj doesn't support
137
this option yet)</td>
138
<td align="center" valign="top">No</td>
141
<td valign="top">nowarn</td>
142
<td valign="top">indicates whether -nowarn switch should be passed
143
to the compiler; defaults to <code>off</code>.</td>
144
<td align="center" valign="top">No</td>
147
<td valign="top">debug</td>
148
<td valign="top">indicates whether source should be compiled with debug
149
information; defaults to <code>off</code>.</td>
150
<td align="center" valign="top">No</td>
153
<td valign="top">optimize</td>
154
<td valign="top">indicates whether source should be compiled with
155
optimization; defaults to <code>off</code>.</td>
156
<td align="center" valign="top">No</td>
159
<td valign="top">deprecation</td>
160
<td valign="top">indicates whether source should be compiled with
161
deprecation information; defaults to <code>off</code>.</td>
162
<td align="center" valign="top">No</td>
165
<td valign="top">target</td>
166
<td valign="top">generate class files for specific VM version (e.g.,
167
<code>1.1</code> or <code>1.2</code>).</td>
168
<td align="center" valign="top">No</td>
171
<td valign="top">verbose</td>
172
<td valign="top">asks the compiler for verbose output.</td>
173
<td align="center" valign="top">No</td>
176
<td valign="top">depend</td> <td valign="top">enables dependency-tracking
177
for compilers that support this (jikes and classic)</td>
178
<td align="center" valign="top">No</td>
181
<td valign="top">includeAntRuntime</td>
182
<td valign="top">whether to include the Ant run-time libraries;
183
defaults to <code>yes</code>.</td>
184
<td align="center" valign="top">No</td>
187
<td valign="top">includeJavaRuntime</td>
188
<td valign="top">whether to include the default run-time
189
libraries from the executing VM; defaults to <code>no</code>.</td>
190
<td align="center" valign="top">No</td>
193
<td valign="top">fork</td>
194
<td valign="top">whether to execute Javac using the JDK compiler externally;
195
defaults to <code>no</code>.</td>
196
<td align="center" valign="top">No</td>
199
<td valign="top">memoryInitialSize</td>
200
<td valign="top">the initial size of the memory for the underlying VM, if javac is run
201
externally, ignored otherwise; defaults to the standard VM memory setting.
202
(examples: <code>83886080</code>, <code>81920k</code>, or <code>80m</code>)</td>
203
<td align="center" valign="top">No</td>
206
<td valign="top">memoryMaximumSize</td>
207
<td valign="top">the maximum size of the memory for the underlying VM, if javac is run
208
externally, ignored otherwise; defaults to the standard VM memory setting.
209
(examples: <code>83886080</code>, <code>81920k</code>, or <code>80m</code>)</td>
210
<td align="center" valign="top">No</td>
213
<td valign="top">failonerror</td> <td valign="top">
214
indicates whether the build will continue even if there are compilation errors; defaults to <code>true</code>.
216
<td align="center" valign="top">No</td>
219
<td valign="top">source</td>
220
<td valign="top">Value of the <code>-source</code> command line
221
switch, will be ignored by all implementations except
222
<code>modern</code>, legal values are "1.3" and
223
"1.4" - by default, no <code>-source</code> argument
224
will be used at all.</td>
225
<td align="center" valign="top">No</td>
229
<h3>Parameters specified as nested elements</h3>
230
<p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
231
supports all attributes of <code><fileset></code>
232
(<code>dir</code> becomes <code>srcdir</code>) as well as the nested
233
<code><include></code>, <code><exclude></code> and
234
<code><patternset></code> elements.</p>
235
<h4><code>src</code>, <code>classpath</code>, <code>bootclasspath</code> and <code>extdirs</code></h4>
236
<p><code>Javac</code>'s <i>srcdir</i>, <i>classpath</i>,
237
<i>bootclasspath</i> and <i>extdirs</i> attributes are <a
238
href="../using.html#path">path-like structures</a> and can also be set via nested
239
<code><src></code>,
240
<code><classpath></code>,
241
<code><bootclasspath></code> and
242
<code><extdirs></code> elements, respectively.</p>
245
<pre> <javac srcdir="${src}"
246
destdir="${build}"
247
classpath="xyz.jar"
250
<p>compiles all <code>.java</code> files under the <code>${src}</code>
251
directory, and stores
252
the <code>.class</code> files in the <code>${build}</code> directory.
253
The classpath used contains <code>xyz.jar</code>, and debug information is on.</p>
254
<pre> <javac srcdir="${src}"
255
destdir="${build}"
256
includes="mypackage/p1/**,mypackage/p2/**"
257
excludes="mypackage/p1/testpackage/**"
258
classpath="xyz.jar"
261
<p>compiles <code>.java</code> files under the <code>${src}</code>
262
directory, and stores the
263
<code>.class</code> files in the <code>${build}</code> directory.
264
The classpath used contains <code>xyz.jar</code>, and debug information is on.
265
Only files under <code>mypackage/p1</code> and <code>mypackage/p2</code> are
266
used. Files in the <code>mypackage/p1/testpackage</code> directory are excluded
267
from compilation.</p>
269
<pre> <javac srcdir="${src}:${src2}"
270
destdir="${build}"
271
includes="mypackage/p1/**,mypackage/p2/**"
272
excludes="mypackage/p1/testpackage/**"
273
classpath="xyz.jar"
277
<p>is the same as the previous example, with the addition of a second
278
source path, defined by
279
the property <code>src2</code>. This can also be represented using nested
280
<code><src></code> elements as follows:</p>
282
<pre> <javac destdir="${build}"
283
classpath="xyz.jar"
284
debug="on">
285
<src path="${src}"/>
286
<src path="${src2}"/>
287
<include name="mypackage/p1/**"/>
288
<include name="mypackage/p2/**"/>
289
<exclude name="mypackage/p1/testpackage/**"/>
292
<p><b>Note:</b> If you are using Ant on Windows and a new DOS window pops up
293
for every use of an external compiler, this may be a problem of the JDK you are using.
294
This problem may occur with all JDKs < 1.2.</p>
296
<p><b>Note:</b> If you wish to compile only source-files located in some packages below a
297
common root you should not include these packages in the srcdir-attribute. Use include/exclude-attributes
298
or elements to filter for these packages. If you include part of your package-structure inside the srcdir-attribute
299
(or nested src-elements) Ant will start to recompile your sources every time you call it.</p>
303
Jikes supports some extra options, which can be set be defining
304
properties prior to invoking the task. The ant developers are aware that
305
this is ugly and inflexible -expect a better solution in the future. All
306
the options are boolean, and must be set to "true" or "yes" to be
307
interpreted as anything other than false; by default
308
build.compiler.warnings is "true" while all others are "false"
310
<table border="1" cellpadding="2" cellspacing="0">
316
Enable emacs compatible error messages
321
build.compiler.warnings<br>
322
<b>This property has been deprecated, use the nowarn attribute
326
don't disable warning messages
331
build.compiler.pedantic
334
enable pedantic warnings
339
build.compiler.fulldepend
342
enable full dependency checking,<br>
343
"+F" in the jikes manual.
348
<p align="center">Copyright © 2000,2001 Apache Software Foundation. All rights