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
|
---|
31 | source files to compile. Only Java files that have no corresponding
|
---|
32 | <code>.class</code> file
|
---|
33 | or 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
|
---|
36 | the classes that need a rebuild. It will not scan the source and therefore
|
---|
37 | will have no knowledge about nested classes, classes that are named different
|
---|
38 | from the source file, and so on. See the
|
---|
39 | <a href="../OptionalTasks/depend.html"><code><depend></code></a> task
|
---|
40 | for dependency checking based on other than just
|
---|
41 | existence/modification times.</p>
|
---|
42 | <p>When the source files are part of a package, the directory structure of
|
---|
43 | the source tree should follow the package
|
---|
44 | hierarchy.</p>
|
---|
45 | <p>It is possible to refine the set of files that are being compiled.
|
---|
46 | This can be done with the <code>includes</code>, <code>includesfile</code>,
|
---|
47 | <code>excludes</code>, and <code>excludesfile</code>
|
---|
48 | attributes. With the <code>includes</code> or
|
---|
49 | <code>includesfile</code> attribute, you specify the files you want to
|
---|
50 | have included.
|
---|
51 | The <code>exclude</code> or <code>excludesfile</code> attribute is used
|
---|
52 | to specify
|
---|
53 | the files you want to have excluded. In both cases, the list of files
|
---|
54 | can be specified by either the filename, relative to the directory(s) specified
|
---|
55 | in the <code>srcdir</code> attribute or nested <code><src></code>
|
---|
56 | element(s), or by using wildcard patterns. See the section on
|
---|
57 | <a href="../dirtasks.html#directorybasedtasks">directory-based tasks</a>,
|
---|
58 | for information on how the
|
---|
59 | inclusion/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
|
---|
61 | either setting the global <code>build.compiler</code> property, which will
|
---|
62 | affect all <code><javac></code> tasks throughout the build, or by
|
---|
63 | setting the <code>compiler</code> attribute, specific to the current
|
---|
64 | <code><javac></code> task.
|
---|
65 | <a name="compilervalues">Valid values for either the
|
---|
66 | <code>build.compiler</code> property or the <code>compiler</code>
|
---|
67 | attribute are:</a></p>
|
---|
68 | <ul>
|
---|
69 | <li><code>classic</code> (the standard compiler of JDK 1.1/1.2) –
|
---|
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) –
|
---|
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++) – <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) –
|
---|
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
|
---|
92 | on the JDK version you use while you are running Ant.
|
---|
93 | If you wish to use a different compiler interface than those
|
---|
94 | supplied, you can write a class that implements the CompilerAdapter interface
|
---|
95 | (<code>package org.apache.tools.ant.taskdefs.compilers</code>). Supply the full
|
---|
96 | classname 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
|
---|
100 | or <code>compiler</code> attribute setting and
|
---|
101 | expects 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
|
---|
104 | which JDK version it shall assume when it puts together the command
|
---|
105 | line switches - even if you set <code>fork="true"</code>.
|
---|
106 | This is useful if you want to run the compiler of JDK 1.1 while you
|
---|
107 | current JDK is 1.2+. If you use
|
---|
108 | <code>compiler="javac1.1"</code> and (for example)
|
---|
109 | <code>depend="true"</code> Ant will use the command line
|
---|
110 | switch <code>-depend</code> instead of <code>-Xdepend</code>.</p>
|
---|
111 | <p>This task will drop all entries that point to non-existent
|
---|
112 | files/directories from the classpath it passes to the compiler.</p>
|
---|
113 | <p><strong>Windows Note:</strong>When the modern compiler is used
|
---|
114 | in unforked mode on Windows, it locks up the files present in the
|
---|
115 | classpath of the <code><javac></code> task, and does not release them.
|
---|
116 | The side effect of this is that you will not be able to delete or move
|
---|
117 | those files later on in the build. The workaround is to fork when
|
---|
118 | invoking 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><src></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><src></code> elements).
|
---|
171 | To suppress the sourcepath switch, use <code>sourcepath=""</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 >= 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="yes"</code>.
|
---|
307 | Defaults to the compiler of the Java version that is currently
|
---|
308 | running Ant. Ignored if <code>fork="no"</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
|
---|
388 | supports all attributes of <code><fileset></code>
|
---|
389 | (<code>dir</code> becomes <code>srcdir</code>) as well as the nested
|
---|
390 | <code><include></code>, <code><exclude></code> and
|
---|
391 | <code><patternset></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><javac></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>
|
---|
398 | and can also be set via nested
|
---|
399 | <code><src></code>,
|
---|
400 | <code><classpath></code>,
|
---|
401 | <code><sourcepath></code>,
|
---|
402 | <code><bootclasspath></code> and
|
---|
403 | <code><extdirs></code> elements, respectively.</p>
|
---|
404 |
|
---|
405 | <h4>compilerarg</h4>
|
---|
406 |
|
---|
407 | <p>You can specify additional command line arguments for the compiler
|
---|
408 | with nested <code><compilerarg></code> elements. These elements
|
---|
409 | are specified like <a href="../using.html#arg">Command-line
|
---|
410 | Arguments</a> but have an additional attribute that can be used to
|
---|
411 | enable arguments only if a given compiler implementation will be
|
---|
412 | used.</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> <javac srcdir="${src}"
|
---|
447 | destdir="${build}"
|
---|
448 | classpath="xyz.jar"
|
---|
449 | debug="on"
|
---|
450 | source="1.4"
|
---|
451 | /></pre>
|
---|
452 | <p>compiles all <code>.java</code> files under the <code>${src}</code>
|
---|
453 | directory, and stores
|
---|
454 | the <code>.class</code> files in the <code>${build}</code> directory.
|
---|
455 | The classpath used includes <code>xyz.jar</code>, and compiling with
|
---|
456 | debug information is on. The source level is 1.4,
|
---|
457 | so you can use <code>assert</code> statements.</p>
|
---|
458 |
|
---|
459 | <pre> <javac srcdir="${src}"
|
---|
460 | destdir="${build}"
|
---|
461 | fork="true"
|
---|
462 | source="1.2"
|
---|
463 | target="1.2"
|
---|
464 | /></pre>
|
---|
465 | <p>compiles all <code>.java</code> files under the <code>${src}</code>
|
---|
466 | directory, and stores the <code>.class</code> files in the
|
---|
467 | <code>${build}</code> directory. This will fork off the javac
|
---|
468 | compiler using the default <code>javac</code> executable.
|
---|
469 | The source level is 1.2 (similar to 1.1 or 1.3) and
|
---|
470 | the class files should be runnable under JDK 1.2+ as well.</p>
|
---|
471 |
|
---|
472 | <pre> <javac srcdir="${src}"
|
---|
473 | destdir="${build}"
|
---|
474 | fork="java$$javac.exe"
|
---|
475 | source="1.5"
|
---|
476 | /></pre>
|
---|
477 | <p>compiles all <code>.java</code> files under the <code>${src}</code>
|
---|
478 | directory, and stores the <code>.class</code> files in the
|
---|
479 | <code>${build}</code> directory. This will fork off the javac
|
---|
480 | compiler, using the executable named <code>java$javac.exe</code>. Note
|
---|
481 | that the <code>$</code> sign needs to be escaped by a second one.
|
---|
482 | The source level is 1.5, so you can use generics.</p>
|
---|
483 |
|
---|
484 | <pre> <javac srcdir="${src}"
|
---|
485 | destdir="${build}"
|
---|
486 | includes="mypackage/p1/**,mypackage/p2/**"
|
---|
487 | excludes="mypackage/p1/testpackage/**"
|
---|
488 | classpath="xyz.jar"
|
---|
489 | debug="on"
|
---|
490 | /></pre>
|
---|
491 | <p>compiles <code>.java</code> files under the <code>${src}</code>
|
---|
492 | directory, and stores the
|
---|
493 | <code>.class</code> files in the <code>${build}</code> directory.
|
---|
494 | The classpath used includes <code>xyz.jar</code>, and debug information is on.
|
---|
495 | Only files under <code>mypackage/p1</code> and <code>mypackage/p2</code> are
|
---|
496 | used. All files in and below the <code>mypackage/p1/testpackage</code>
|
---|
497 | directory are excluded from compilation.
|
---|
498 | You didn't specify a source or target level,
|
---|
499 | so the actual values used will depend on which JDK you ran Ant with.</p>
|
---|
500 |
|
---|
501 | <pre> <javac srcdir="${src}:${src2}"
|
---|
502 | destdir="${build}"
|
---|
503 | includes="mypackage/p1/**,mypackage/p2/**"
|
---|
504 | excludes="mypackage/p1/testpackage/**"
|
---|
505 | classpath="xyz.jar"
|
---|
506 | debug="on"
|
---|
507 | /></pre>
|
---|
508 |
|
---|
509 | <p>is the same as the previous example, with the addition of a second
|
---|
510 | source path, defined by
|
---|
511 | the property <code>src2</code>. This can also be represented using nested
|
---|
512 | <code><src></code> elements as follows:</p>
|
---|
513 |
|
---|
514 | <pre> <javac destdir="${build}"
|
---|
515 | classpath="xyz.jar"
|
---|
516 | debug="on">
|
---|
517 | <src path="${src}"/>
|
---|
518 | <src path="${src2}"/>
|
---|
519 | <include name="mypackage/p1/**"/>
|
---|
520 | <include name="mypackage/p2/**"/>
|
---|
521 | <exclude name="mypackage/p1/testpackage/**"/>
|
---|
522 | </javac></pre>
|
---|
523 |
|
---|
524 | <p>If you want to run the javac compiler of a different JDK, you
|
---|
525 | should tell Ant, where to find the compiler and which version of JDK
|
---|
526 | you will be using so it can choose the correct command line switches.
|
---|
527 | The following example executes a JDK 1.1 javac in a new process and
|
---|
528 | uses the correct command line switches even when Ant is running in a
|
---|
529 | Java VM of a different version:</p>
|
---|
530 |
|
---|
531 | <pre> <javac srcdir="${src}"
|
---|
532 | destdir="${build}"
|
---|
533 | fork="yes"
|
---|
534 | executable="/opt/java/jdk1.1/bin/javac"
|
---|
535 | compiler="javac1.1"
|
---|
536 | /></pre>
|
---|
537 |
|
---|
538 | <p><a name="srcdirnote"><b>Note:</b></a>
|
---|
539 | If you wish to compile only source files located in certain packages below a
|
---|
540 | common root, use the <code>include</code>/<code>exclude</code> attributes
|
---|
541 | or <code><include></code>/<code><exclude></code> nested elements
|
---|
542 | to filter for these packages. Do not include part of your package structure
|
---|
543 | in the <code>srcdir</code> attribute
|
---|
544 | (or nested <code><src></code> elements), or Ant will recompile your
|
---|
545 | source files every time you run your compile target. See the
|
---|
546 | <a href="http://ant.apache.org/faq.html#always-recompiles">Ant FAQ</a>
|
---|
547 | for additional information.</p>
|
---|
548 |
|
---|
549 | <p>
|
---|
550 | If you wish to compile only files explicitly specified and disable
|
---|
551 | javac's default searching mechanism then you can unset the sourcepath
|
---|
552 | attribute:
|
---|
553 | <pre> <javac sourcepath="" srcdir="${src}"
|
---|
554 | destdir="${build}" >
|
---|
555 | <include name="**/*.java"/>
|
---|
556 | <exclude name="**/Example.java"/>
|
---|
557 | </javac></pre>
|
---|
558 | That way the javac will compile all java source files under "${src}"
|
---|
559 | directory but skip the examples. The compiler will even produce errors if some of
|
---|
560 | the non-example files refers to them.
|
---|
561 | </p>
|
---|
562 |
|
---|
563 | <p>
|
---|
564 | If you wish to compile with a special JDK (another than the one Ant is currently using),
|
---|
565 | set the <code>executable</code> and <code>fork</code> attribute. Using <code>taskname</code>
|
---|
566 | could show in the log, that these settings are fix.
|
---|
567 | <pre> <javac srcdir="."
|
---|
568 | destdir="."
|
---|
569 | executable="path-to-java14-home/bin/javac"
|
---|
570 | fork="true"
|
---|
571 | taskname="javac1.4" /></pre>
|
---|
572 | </p>
|
---|
573 |
|
---|
574 |
|
---|
575 | <p><b>Note:</b> If you are using Ant on Windows and a new DOS window pops up
|
---|
576 | for every use of an external compiler, this may be a problem of the JDK you are
|
---|
577 | using. This problem may occur with all JDKs < 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
|
---|
584 | the properties shown below prior to invoking the task. The setting
|
---|
585 | for each property will be in affect for all <code><javac></code>
|
---|
586 | tasks throughout the build.
|
---|
587 | The Ant developers are aware that
|
---|
588 | this is ugly and inflexible – expect a better solution in the future.
|
---|
589 | All the options are boolean, and must be set to <code>true</code> or
|
---|
590 | <code>yes</code> to be
|
---|
591 | interpreted as anything other than false. By default,
|
---|
592 | <code>build.compiler.warnings</code> is <code>true</code>,
|
---|
593 | while 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><javac></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><javac></code>.</p>
|
---|
656 |
|
---|
657 |
|
---|
658 |
|
---|
659 | </body>
|
---|
660 | </html>
|
---|