~ubuntu-branches/ubuntu/jaunty/ant/jaunty-proposed

« back to all changes in this revision

Viewing changes to docs/manual/CoreTasks/javac.html

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Gybas
  • Date: 2002-02-14 14:28:48 UTC
  • Revision ID: james.westby@ubuntu.com-20020214142848-2ww7ynmqkj31vlmn
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
 
 
3
<head>
 
4
<meta http-equiv="Content-Language" content="en-us">
 
5
<title>Ant User Manual</title>
 
6
</head>
 
7
 
 
8
<body>
 
9
 
 
10
<h2><a name="javac">Javac</a></h2>
 
11
<h3>Description</h3>
 
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
 
21
hierarchy.</p>
 
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
&quot;build.compiler&quot; property. Here are the choices:-</p>
 
33
<ul>
 
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>
 
38
  <li>jikes (the <a
 
39
    href="http://oss.software.ibm.com/developerworks/opensource/jikes/project" target="_top">Jikes</a>
 
40
    compiler)</li>
 
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>
 
44
    compiler)</li>
 
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>
 
48
</ul>
 
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 &quot;build.compiler&quot; property.
 
54
</p>
 
55
<p>The fork attribute overrides the build.compiler setting and expects
 
56
a JDK1.1 or higher to be set in java.home.
 
57
</p>
 
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>
 
60
<h3>Parameters</h3>
 
61
<table border="1" cellpadding="2" cellspacing="0">
 
62
  <tr>
 
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>
 
66
  </tr>
 
67
  <tr>
 
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>&lt;src&gt;</code> elements are present.</td>
 
71
  </tr>
 
72
  <tr>
 
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>
 
76
  </tr>
 
77
  <tr>
 
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>
 
82
  </tr>
 
83
  <tr>
 
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>
 
88
  </tr>
 
89
  <tr>
 
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>
 
94
  </tr>
 
95
  <tr>
 
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>
 
100
  </tr>
 
101
  <tr>
 
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>
 
106
  </tr>
 
107
  <tr>
 
108
    <td valign="top">classpath</td>
 
109
    <td valign="top">the classpath to use.</td>
 
110
    <td align="center" valign="top">No</td>
 
111
  </tr>
 
112
  <tr>
 
113
    <td valign="top">bootclasspath</td>
 
114
    <td valign="top">location of bootstrap class files.</td>
 
115
    <td align="center" valign="top">No</td>
 
116
  </tr>
 
117
  <tr>
 
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>
 
122
  </tr>
 
123
  <tr>
 
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>
 
128
  </tr>
 
129
  <tr>
 
130
    <td valign="top">extdirs</td>
 
131
    <td valign="top">location of installed extensions.</td>
 
132
    <td align="center" valign="top">No</td>
 
133
  </tr>
 
134
  <tr>
 
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>
 
139
  </tr>
 
140
  <tr>
 
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>
 
145
  </tr>
 
146
  <tr>
 
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>
 
151
  </tr>
 
152
  <tr>
 
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>
 
157
  </tr>
 
158
  <tr>
 
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>
 
163
  </tr>
 
164
  <tr>
 
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>
 
169
  </tr>
 
170
  <tr>
 
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>
 
174
  </tr>
 
175
  <tr>
 
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>
 
179
  </tr>
 
180
  <tr>
 
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>
 
185
  </tr>
 
186
  <tr>
 
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>
 
191
  </tr>
 
192
  <tr>
 
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>
 
197
  </tr>  
 
198
  <tr>
 
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>
 
204
  </tr>  
 
205
  <tr>
 
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>
 
211
  </tr>  
 
212
  <tr>
 
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>.
 
215
    </td>
 
216
    <td align="center" valign="top">No</td>
 
217
  </tr>
 
218
  <tr>
 
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 &quot;1.3&quot; and
 
223
    &quot;1.4&quot; - by default, no <code>-source</code> argument
 
224
    will be used at all.</td>
 
225
    <td align="center" valign="top">No</td>
 
226
  </tr>  
 
227
</table>
 
228
 
 
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>&lt;fileset&gt;</code>
 
232
(<code>dir</code> becomes <code>srcdir</code>) as well as the nested
 
233
<code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
 
234
<code>&lt;patternset&gt;</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>&lt;src&gt</code>,
 
240
<code>&lt;classpath&gt</code>,
 
241
<code>&lt;bootclasspath&gt</code> and
 
242
<code>&lt;extdirs&gt</code> elements, respectively.</p>
 
243
 
 
244
<h3>Examples</h3>
 
245
<pre>  &lt;javac srcdir=&quot;${src}&quot;
 
246
         destdir=&quot;${build}&quot;
 
247
         classpath=&quot;xyz.jar&quot;
 
248
         debug=&quot;on&quot;
 
249
  /&gt;</pre>
 
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>  &lt;javac srcdir=&quot;${src}&quot;
 
255
         destdir=&quot;${build}&quot;
 
256
         includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
 
257
         excludes=&quot;mypackage/p1/testpackage/**&quot;
 
258
         classpath=&quot;xyz.jar&quot;
 
259
         debug=&quot;on&quot;
 
260
  /&gt;</pre>
 
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>
 
268
 
 
269
<pre>  &lt;javac srcdir=&quot;${src}:${src2}&quot;
 
270
         destdir=&quot;${build}&quot;
 
271
         includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
 
272
         excludes=&quot;mypackage/p1/testpackage/**&quot;
 
273
         classpath=&quot;xyz.jar&quot;
 
274
         debug=&quot;on&quot;
 
275
  /&gt;</pre>
 
276
 
 
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>&lt;src&gt;</code> elements as follows:</p>
 
281
 
 
282
<pre>  &lt;javac destdir=&quot;${build}&quot;
 
283
         classpath=&quot;xyz.jar&quot;
 
284
         debug=&quot;on&quot;&gt;
 
285
    &lt;src path=&quot;${src}&quot;/&gt;
 
286
    &lt;src path=&quot;${src2}&quot;/&gt;
 
287
    &lt;include name=&quot;mypackage/p1/**&quot;/&gt;
 
288
    &lt;include name=&quot;mypackage/p2/**&quot;/&gt;
 
289
    &lt;exclude name=&quot;mypackage/p1/testpackage/**&quot;/&gt;
 
290
  &lt;/javac&gt;</pre>
 
291
 
 
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 &lt; 1.2.</p>
 
295
 
 
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>
 
300
 
 
301
<h3>Jikes Notes</h3>
 
302
 
 
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 &quot;true&quot; or &quot;yes&quot; to be
 
307
interpreted as anything other than false; by default
 
308
build.compiler.warnings is &quot;true&quot; while all others are &quot;false&quot;
 
309
 
 
310
<table border="1" cellpadding="2" cellspacing="0">
 
311
  <tr>
 
312
    <td valign="top">
 
313
        build.compiler.emacs
 
314
        </td> 
 
315
        <td valign="top">
 
316
        Enable emacs compatible error messages
 
317
    </td>
 
318
  </tr>
 
319
  <tr>
 
320
    <td valign="top">
 
321
        build.compiler.warnings<br>
 
322
        <b>This property has been deprecated, use the nowarn attribute
 
323
          instead</b>
 
324
        </td> 
 
325
        <td valign="top">
 
326
        don't disable warning messages
 
327
    </td>
 
328
  </tr>
 
329
  <tr>
 
330
    <td valign="top">
 
331
        build.compiler.pedantic
 
332
        </td> 
 
333
        <td valign="top">
 
334
        enable pedantic warnings
 
335
    </td>
 
336
  </tr>
 
337
  <tr>
 
338
    <td valign="top">
 
339
        build.compiler.fulldepend
 
340
        </td> 
 
341
        <td valign="top">
 
342
        enable full dependency checking,<br> 
 
343
        &quot;+F&quot; in the jikes manual.
 
344
    </td>
 
345
  </tr>
 
346
</table>
 
347
<hr>
 
348
<p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
 
349
Reserved.</p>
 
350
 
 
351
</body>
 
352
</html>
 
353