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