5865
|
1 |
." Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
|
2
|
2 |
." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
3 |
."
|
|
4 |
." This code is free software; you can redistribute it and/or modify it
|
|
5 |
." under the terms of the GNU General Public License version 2 only, as
|
|
6 |
." published by the Free Software Foundation.
|
|
7 |
."
|
|
8 |
." This code is distributed in the hope that it will be useful, but WITHOUT
|
|
9 |
." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
10 |
." FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
11 |
." version 2 for more details (a copy is included in the LICENSE file that
|
|
12 |
." accompanied this code).
|
|
13 |
."
|
|
14 |
." You should have received a copy of the GNU General Public License version
|
|
15 |
." 2 along with this work; if not, write to the Free Software Foundation,
|
|
16 |
." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
17 |
."
|
5506
|
18 |
." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
19 |
." or visit www.oracle.com if you need additional information or have any
|
|
20 |
." questions.
|
2692
|
21 |
."
|
5865
|
22 |
.TH javac 1 "02 Jun 2010"
|
2
|
23 |
|
|
24 |
.LP
|
2692
|
25 |
.SH "Name"
|
2
|
26 |
javac \- Java programming language compiler
|
|
27 |
.LP
|
|
28 |
.SH "SYNOPSIS"
|
|
29 |
.LP
|
|
30 |
|
|
31 |
.LP
|
|
32 |
.nf
|
|
33 |
\f3
|
|
34 |
.fl
|
2692
|
35 |
\fP\f3javac\fP [ options ] [ sourcefiles ] [ classes ] [ @argfiles ]
|
|
36 |
.fl
|
|
37 |
|
2
|
38 |
.fl
|
|
39 |
.fi
|
|
40 |
|
|
41 |
.LP
|
|
42 |
.LP
|
|
43 |
Arguments may be in any order.
|
|
44 |
.LP
|
|
45 |
.RS 3
|
|
46 |
|
|
47 |
.LP
|
|
48 |
.RS 3
|
|
49 |
.TP 3
|
|
50 |
options
|
|
51 |
Command\-line options.
|
|
52 |
.TP 3
|
|
53 |
sourcefiles
|
|
54 |
One or more source files to be compiled (such as MyClass.java).
|
|
55 |
.TP 3
|
2692
|
56 |
classes
|
|
57 |
One or more classes to be processed for annotations (such as MyPackage.MyClass).
|
|
58 |
.TP 3
|
2
|
59 |
@argfiles
|
|
60 |
One or more files that lists options and source files. The \f2\-J\fP options are not allowed in these files.
|
|
61 |
.RE
|
|
62 |
|
|
63 |
.LP
|
|
64 |
.RE
|
|
65 |
.SH "DESCRIPTION"
|
|
66 |
.LP
|
|
67 |
|
|
68 |
.LP
|
|
69 |
.LP
|
2692
|
70 |
The \f3javac\fP tool reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files. It can also process annotations in Java source files and classes.
|
2
|
71 |
.LP
|
|
72 |
.LP
|
2692
|
73 |
There are two ways to pass source code file names to \f3javac\fP:
|
2
|
74 |
.LP
|
|
75 |
.RS 3
|
|
76 |
.TP 2
|
|
77 |
o
|
|
78 |
For a small number of source files, simply list the file names on the command line.
|
|
79 |
.TP 2
|
|
80 |
o
|
|
81 |
For a large number of source files, list the file names in a file, separated by blanks or line breaks. Then use the list file name on the \f3javac\fP command line, preceded by an \f3@\fP character.
|
|
82 |
.RE
|
|
83 |
|
|
84 |
.LP
|
|
85 |
.LP
|
|
86 |
Source code file names must have \f2.java\fP suffixes, class file names must have \f2.class\fP suffixes, and both source and class files must have root names that identify the class. For example, a class called \f2MyClass\fP would be written in a source file called \f2MyClass.java\fP and compiled into a bytecode class file called \f2MyClass.class\fP.
|
|
87 |
.LP
|
|
88 |
.LP
|
|
89 |
Inner class definitions produce additional class files. These class files have names combining the inner and outer class names, such as \f2MyClass$MyInnerClass.class\fP.
|
|
90 |
.LP
|
|
91 |
.LP
|
|
92 |
You should arrange source files in a directory tree that reflects their package tree. For example, if you keep all your source files in \f3/workspace\fP, the source code for \f2com.mysoft.mypack.MyClass\fP should be in \f3/workspace/com/mysoft/mypack/MyClass.java\fP.
|
|
93 |
.LP
|
|
94 |
.LP
|
|
95 |
By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with \f3\-d\fP (see Options, below).
|
|
96 |
.LP
|
|
97 |
.SH "OPTIONS"
|
|
98 |
.LP
|
|
99 |
|
|
100 |
.LP
|
|
101 |
.LP
|
|
102 |
The compiler has a set of standard options that are supported on the current development environment and will be supported in future releases. An additional set of non\-standard options are specific to the current virtual machine and compiler implementations and are subject to change in the future. Non\-standard options begin with \f3\-X\fP.
|
|
103 |
.LP
|
|
104 |
.SS
|
|
105 |
Standard Options
|
|
106 |
.LP
|
|
107 |
.RS 3
|
|
108 |
|
|
109 |
.LP
|
|
110 |
.RS 3
|
|
111 |
.TP 3
|
2692
|
112 |
\-Akey[=value]
|
|
113 |
Options to pass to annotation processors. These are not interpreted by javac directly, but are made available for use by individual processors. \f2key\fP should be one or more identifiers separated by ".".
|
|
114 |
.TP 3
|
|
115 |
\-cp path or \-classpath path
|
|
116 |
Specify where to find user class files, and (optionally) annotation processors and source files. This classpath overrides the user class path in the \f3CLASSPATH\fP environment variable. If neither \f3CLASSPATH\fP, \f3\-cp\fP nor \f3\-classpath\fP is specified, the user class path consists of the current directory. See
|
|
117 |
.na
|
|
118 |
\f2Setting the Class Path\fP @
|
|
119 |
.fi
|
|
120 |
http://java.sun.com/javase/6/docs/technotes/tools/index.html#classpath for more details.
|
2
|
121 |
.LP
|
2692
|
122 |
If the \f3\-sourcepath\fP option is not specified, the user class path is also searched for source files.
|
2
|
123 |
.LP
|
2692
|
124 |
If the \f3\-processorpath\fP option is not specified, the classpath is also searched for annotation processors.
|
|
125 |
.LP
|
|
126 |
As a special convenience, a class path element containing a basename of \f2*\fP is considered equivalent to specifying a list of all the files in the directory with the extension \f2.jar\fP or \f2.JAR\fP.
|
2
|
127 |
.br
|
|
128 |
.br
|
2692
|
129 |
For example, if directory \f2foo\fP contains \f2a.jar\fP and \f2b.JAR\fP, then the class path element \f2foo/*\fP is expanded to \f2A.jar:b.JAR\fP, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of \f2*\fP expands to a list of all the jar files in the current directory. The \f2CLASSPATH\fP environment variable, where defined, will be similarly expanded. \f3Note:\fP \ Depending of the configuration of your command line environment, you may have to quote the wild card character, for example, \f2javac \-cp "*.jar" MyClass.java\fP.
|
2
|
130 |
.TP 3
|
|
131 |
\-Djava.ext.dirs=directories
|
|
132 |
Override the location of installed extensions.
|
|
133 |
.TP 3
|
|
134 |
\-Djava.endorsed.dirs=directories
|
|
135 |
Override the location of endorsed standards path.
|
|
136 |
.TP 3
|
|
137 |
\-d directory
|
2692
|
138 |
Set the destination directory for class files. The directory must already exist; \f3javac\fP will not create it. If a class is part of a package, \f3javac\fP puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify \f3\-d /home/myclasses\fP and the class is called \f2com.mypackage.MyClass\fP, then the class file is called \f2/home/myclasses/com/mypackage/MyClass.class\fP.
|
2
|
139 |
.LP
|
2692
|
140 |
If \f3\-d\fP is not specified, \f3javac\fP puts each class files in the same directory as the source file from which it was generated.
|
2
|
141 |
.LP
|
|
142 |
\f3Note:\fP \ The directory specified by \f3\-d\fP is not automatically added to your user class path.
|
|
143 |
.TP 3
|
|
144 |
\-deprecation
|
2692
|
145 |
Show a description of each use or override of a deprecated member or class. Without \f3\-deprecation\fP, \f3javac\fP shows a summary of the source files that use or override deprecated members or classes. \f3\-deprecation\fP is shorthand for \f3\-Xlint:deprecation\fP.
|
2
|
146 |
.TP 3
|
|
147 |
\-encoding encoding
|
2692
|
148 |
Set the source file encoding name, such as \f2EUC\-JP and UTF\-8\fP. If \f3\-encoding\fP is not specified, the platform default converter is used.
|
2
|
149 |
.TP 3
|
|
150 |
\-g
|
|
151 |
Generate all debugging information, including local variables. By default, only line number and source file information is generated.
|
|
152 |
.TP 3
|
|
153 |
\-g:none
|
|
154 |
Do not generate any debugging information.
|
|
155 |
.TP 3
|
|
156 |
\-g:{keyword list}
|
|
157 |
Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
|
|
158 |
.RS 3
|
|
159 |
.TP 3
|
|
160 |
source
|
|
161 |
Source file debugging information
|
|
162 |
.TP 3
|
|
163 |
lines
|
|
164 |
Line number debugging information
|
|
165 |
.TP 3
|
|
166 |
vars
|
|
167 |
Local variable debugging information
|
|
168 |
.RE
|
|
169 |
.TP 3
|
|
170 |
\-help
|
|
171 |
Print a synopsis of standard options.
|
|
172 |
.TP 3
|
2692
|
173 |
\-implicit:{class,none}
|
|
174 |
Controls the generation of class files for implicitly loaded source files. To automatically generate class files, use \f3\-implicit:class\fP. To suppress class file generation, use \f3\-implicit:none\fP. If this option is not specified, the default is to automatically generate class files. In this case, the compiler will issue a warning if any such class files are generated when also doing annotation processing. The warning will not be issued if this option is set explicitly. See Searching For Types.
|
|
175 |
.TP 3
|
2
|
176 |
\-nowarn
|
|
177 |
Disable warning messages. This has the same meaning as \f3\-Xlint:none\fP.
|
2692
|
178 |
.TP 3
|
|
179 |
\-proc: {none,only}
|
|
180 |
Controls whether annotation processing and/or compilation is done. \f3\-proc:none\fP means that compilation takes place without annotation processing. \f3\-proc:only\fP means that only annotation processing is done, without any subsequent compilation.
|
|
181 |
.TP 3
|
|
182 |
\-processor class1[,class2,class3...]
|
|
183 |
Names of the annotation processors to run. This bypasses the default discovery process.
|
|
184 |
.TP 3
|
|
185 |
\-processorpath path
|
|
186 |
Specify where to find annotation processors; if this option is not used, the classpath will be searched for processors.
|
|
187 |
.TP 3
|
|
188 |
\-s dir
|
|
189 |
Specify the directory where to place generated source files. The directory must already exist; \f3javac\fP will not create it. If a class is part of a package, the compiler puts the source file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify \f3\-s /home/mysrc\fP and the class is called \f2com.mypackage.MyClass\fP, then the source file will be placed in \f2/home/mysrc/com/mypackage/MyClass.java\fP.
|
2
|
190 |
.TP 3
|
|
191 |
\-source release
|
|
192 |
Specifies the version of source code accepted. The following values for \f2release\fP are allowed:
|
|
193 |
.RS 3
|
|
194 |
.TP 3
|
|
195 |
1.3
|
|
196 |
The compiler does \f2not\fP support assertions, generics, or other language features introduced after JDK 1.3.
|
|
197 |
.TP 3
|
|
198 |
1.4
|
|
199 |
The compiler accepts code containing assertions, which were introduced in JDK 1.4.
|
|
200 |
.TP 3
|
|
201 |
1.5
|
2692
|
202 |
The compiler accepts code containing generics and other language features introduced in JDK 5.
|
2
|
203 |
.TP 3
|
|
204 |
5
|
2692
|
205 |
Synonym for 1.5.
|
|
206 |
.TP 3
|
|
207 |
1.6
|
|
208 |
This is the default value. No language changes were introduced in Java SE 6. However, encoding errors in source files are now reported as errors, instead of warnings, as previously.
|
|
209 |
.TP 3
|
|
210 |
6
|
|
211 |
Synonym for 1.6.
|
|
212 |
.TP 3
|
|
213 |
1.7
|
|
214 |
The compiler accepts code with features introduced in JDK 7.
|
|
215 |
.TP 3
|
|
216 |
7
|
|
217 |
Synonym for 1.7.
|
2
|
218 |
.RE
|
|
219 |
.TP 3
|
|
220 |
\-sourcepath sourcepath
|
|
221 |
Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by colons (\f3:\fP) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.
|
|
222 |
.LP
|
2692
|
223 |
\f3Note:\fP \ Classes found through the classpath may be subject to automatic recompilation if their sources are also found. See Searching For Types.
|
2
|
224 |
.TP 3
|
|
225 |
\-verbose
|
2692
|
226 |
Verbose output. This includes information about each class loaded and each source file compiled.
|
|
227 |
.TP 3
|
|
228 |
\-version
|
|
229 |
Print version information.
|
2
|
230 |
.TP 3
|
|
231 |
\-X
|
|
232 |
Display information about non\-standard options and exit.
|
|
233 |
.RE
|
|
234 |
|
|
235 |
.LP
|
|
236 |
.RE
|
|
237 |
.SS
|
|
238 |
Cross\-Compilation Options
|
|
239 |
.LP
|
|
240 |
.RS 3
|
|
241 |
|
|
242 |
.LP
|
|
243 |
.LP
|
|
244 |
By default, classes are compiled against the bootstrap and extension classes of the platform that \f3javac\fP shipped with. But \f3javac\fP also supports \f2cross\-compiling\fP, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is important to use \f3\-bootclasspath\fP and \f3\-extdirs\fP when cross\-compiling; see Cross\-Compilation Example below.
|
|
245 |
.LP
|
|
246 |
.RS 3
|
|
247 |
.TP 3
|
|
248 |
\-target version
|
2692
|
249 |
Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM. Valid targets are \f31.1\fP \f31.2\fP \f31.3\fP \f31.4\fP \f31.5\fP (also \f35\fP) \f31.6\fP (also \f36\fP) and \f31.7\fP (also \f37\fP).
|
2
|
250 |
.LP
|
|
251 |
The default for \f3\-target\fP depends on the value of \f3\-source\fP:
|
|
252 |
.RS 3
|
|
253 |
.TP 2
|
|
254 |
o
|
|
255 |
If \-source is \f3not specified\fP, the value of \-target is \f31.6\fP
|
|
256 |
.TP 2
|
|
257 |
o
|
2692
|
258 |
If \-source is \f31.2\fP, the value of \-target is \f31.4\fP
|
|
259 |
.TP 2
|
|
260 |
o
|
|
261 |
If \-source is \f31.3\fP, the value of \-target is \f31.4\fP
|
2
|
262 |
.TP 2
|
|
263 |
o
|
|
264 |
For \f3all other values\fP of \-source, the value of \-target is the value of \f3\-source\fP.
|
|
265 |
.RE
|
|
266 |
.TP 3
|
|
267 |
\-bootclasspath bootclasspath
|
|
268 |
Cross\-compile against the specified set of boot classes. As with the user class path, boot class path entries are separated by colons (\f3:\fP) and can be directories, JAR archives, or ZIP archives.
|
|
269 |
.TP 3
|
|
270 |
\-extdirs directories
|
|
271 |
Cross\-compile against the specified extension directories. \f2Directories\fP is a colon\-separated list of directories. Each JAR archive in the specified directories is searched for class files.
|
|
272 |
.RE
|
|
273 |
|
|
274 |
.LP
|
|
275 |
.RE
|
|
276 |
.SS
|
|
277 |
Non\-Standard Options
|
|
278 |
.LP
|
|
279 |
.RS 3
|
|
280 |
|
|
281 |
.LP
|
|
282 |
.RS 3
|
|
283 |
.TP 3
|
|
284 |
\-Xbootclasspath/p:path
|
|
285 |
Prepend to the bootstrap class path.
|
|
286 |
.TP 3
|
|
287 |
\-Xbootclasspath/a:path
|
|
288 |
Append to the bootstrap class path.
|
|
289 |
.TP 3
|
|
290 |
\-Xbootclasspath/:path
|
|
291 |
Override location of bootstrap class files.
|
|
292 |
.TP 3
|
|
293 |
\-Xlint
|
|
294 |
Enable all recommended warnings. In this release, all available warnings are recommended.
|
|
295 |
.TP 3
|
|
296 |
\-Xlint:none
|
|
297 |
Disable all warnings not mandated by the Java Language Specification.
|
|
298 |
.TP 3
|
2692
|
299 |
\-Xlint:\-name
|
|
300 |
Disable warning \f2name\fP, where \f2name\fP is one of the warning names supported for \f3\-Xlint:\fP\f2name\fP, below.
|
2
|
301 |
.TP 3
|
|
302 |
\-Xlint:unchecked
|
|
303 |
Give more detail for unchecked conversion warnings that are mandated by the Java Language Specification.
|
|
304 |
.TP 3
|
|
305 |
\-Xlint:path
|
|
306 |
Warn about nonexistent path (classpath, sourcepath, etc) directories.
|
|
307 |
.TP 3
|
|
308 |
\-Xlint:serial
|
|
309 |
Warn about missing \f2serialVersionUID\fP definitions on serializable classes.
|
|
310 |
.TP 3
|
|
311 |
\-Xlint:finally
|
|
312 |
Warn about \f2finally\fP clauses that cannot complete normally.
|
|
313 |
.TP 3
|
|
314 |
\-Xlint:fallthrough
|
2692
|
315 |
Check \f2switch\fP blocks for fall\-through cases and provide a warning message for any that are found. Fall\-through cases are cases in a \f2switch\fP block, other than the last case in the block, whose code does not include a \f2break\fP statement, allowing code execution to "fall through" from that case to the next case. For example, the code following the \f2case 1\fP label in this \f2switch\fP block does not end with a \f2break\fP statement:
|
2
|
316 |
.RS 3
|
|
317 |
|
|
318 |
.LP
|
|
319 |
.nf
|
|
320 |
\f3
|
|
321 |
.fl
|
|
322 |
switch (x) {
|
|
323 |
.fl
|
|
324 |
case 1:
|
|
325 |
.fl
|
|
326 |
System.out.println("1");
|
|
327 |
.fl
|
|
328 |
// No break; statement here.
|
|
329 |
.fl
|
|
330 |
case 2:
|
|
331 |
.fl
|
|
332 |
System.out.println("2");
|
|
333 |
.fl
|
|
334 |
}
|
|
335 |
.fl
|
2692
|
336 |
|
|
337 |
.fl
|
2
|
338 |
\fP
|
|
339 |
.fi
|
|
340 |
.RE
|
|
341 |
If the \f2\-Xlint:fallthrough\fP flag were used when compiling this code, the compiler would emit a warning about "possible fall\-through into case," along with the line number of the case in question.
|
|
342 |
.TP 3
|
2692
|
343 |
\-Xmaxerrs number
|
2
|
344 |
Set the maximum number of errors to print.
|
|
345 |
.TP 3
|
|
346 |
\-Xmaxwarns number
|
|
347 |
Set the maximum number of warnings to print.
|
|
348 |
.TP 3
|
|
349 |
\-Xstdout filename
|
|
350 |
Send compiler messages to the named file. By default, compiler messages go to \f2System.err\fP.
|
2692
|
351 |
.TP 3
|
|
352 |
\-Xprefer:{newer,source}
|
|
353 |
Specify which file to read when both a source file and class file are found for a type. (See Searching For Types). If \f2\-Xprefer:newer\fP is used, it reads the newer of the source or class file for a type (default). If the \f2\-Xprefer:source\fP option is used, it reads source file. Use \f2\-Xprefer:source\fP when you want to be sure that any annotation processors can access annotations declared with a retention policy of \f2SOURCE\fP.
|
|
354 |
.TP 3
|
|
355 |
\-Xprint
|
|
356 |
Print out textual representation of specified types for debugging purposes; perform neither annotation processing nor compilation. The format of the output may change.
|
|
357 |
.TP 3
|
|
358 |
\-XprintProcessorInfo
|
|
359 |
Print information about which annotations a processor is asked to process.
|
|
360 |
.TP 3
|
|
361 |
\-XprintRounds
|
|
362 |
Print information about initial and subsequent annotation processing rounds.
|
2
|
363 |
.RE
|
|
364 |
|
|
365 |
.LP
|
|
366 |
.RE
|
|
367 |
.SS
|
|
368 |
The \-J Option
|
|
369 |
.LP
|
|
370 |
.RS 3
|
|
371 |
|
|
372 |
.LP
|
|
373 |
.RS 3
|
|
374 |
.TP 3
|
|
375 |
\-Joption
|
|
376 |
Pass \f2option\fP to the \f3java\fP launcher called by \f3javac\fP. For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. Although it does not begin with \f3\-X\fP, it is not a `standard option' of \f3javac\fP. It is a common convention for \f3\-J\fP to pass options to the underlying VM executing applications written in Java.
|
|
377 |
.LP
|
|
378 |
\f3Note:\fP \ \f3CLASSPATH\fP, \f3\-classpath\fP, \f3\-bootclasspath\fP, and \f3\-extdirs\fP do \f2not\fP specify the classes used to run \f3javac\fP. Fiddling with the implementation of the compiler in this way is usually pointless and always risky. If you do need to do this, use the \f3\-J\fP option to pass through options to the underlying \f3java\fP launcher.
|
|
379 |
.RE
|
|
380 |
|
|
381 |
.LP
|
|
382 |
.RE
|
|
383 |
.SH "COMMAND LINE ARGUMENT FILES"
|
|
384 |
.LP
|
|
385 |
|
|
386 |
.LP
|
|
387 |
.LP
|
|
388 |
To shorten or simplify the javac command line, you can specify one or more files that themselves contain arguments to the \f2javac\fP command (except \f2\-J\fP options). This enables you to create javac commands of any length on any operating system.
|
|
389 |
.LP
|
|
390 |
.LP
|
|
391 |
An argument file can include javac options and source filenames in any combination. The arguments within a file can be space\-separated or newline\-separated. If a filename contains embedded spaces, put the whole filename in double quotes.
|
|
392 |
.LP
|
|
393 |
.LP
|
|
394 |
Filenames within an argument file are relative to the current directory, not the location of the argument file. Wildcards (*) are not allowed in these lists (such as for specifying \f2*.java\fP). Use of the '\f2@\fP' character to recursively interpret files is not supported. The \f2\-J\fP options are not supported because they are passed to the launcher, which does not support argument files.
|
|
395 |
.LP
|
|
396 |
.LP
|
|
397 |
When executing javac, pass in the path and name of each argument file with the '\f2@\fP' leading character. When javac encounters an argument beginning with the character `\f2@\fP', it expands the contents of that file into the argument list.
|
|
398 |
.LP
|
|
399 |
.SS
|
|
400 |
Example \- Single Arg File
|
|
401 |
.LP
|
|
402 |
.LP
|
|
403 |
You could use a single argument file named "\f2argfile\fP" to hold all javac arguments:
|
|
404 |
.LP
|
|
405 |
.nf
|
|
406 |
\f3
|
|
407 |
.fl
|
2692
|
408 |
% \fP\f3javac @argfile\fP
|
|
409 |
.fl
|
|
410 |
|
2
|
411 |
.fl
|
|
412 |
.fi
|
|
413 |
|
|
414 |
.LP
|
|
415 |
.LP
|
|
416 |
This argument file could contain the contents of both files shown in the next example.
|
|
417 |
.LP
|
|
418 |
.SS
|
|
419 |
Example \- Two Arg Files
|
|
420 |
.LP
|
|
421 |
.LP
|
|
422 |
You can create two argument files \-\- one for the javac options and the other for the source filenames: (Notice the following lists have no line\-continuation characters.)
|
|
423 |
.LP
|
|
424 |
.LP
|
|
425 |
Create a file named "\f2options\fP" containing:
|
|
426 |
.LP
|
|
427 |
.nf
|
|
428 |
\f3
|
|
429 |
.fl
|
|
430 |
\-d classes
|
|
431 |
.fl
|
|
432 |
\-g
|
|
433 |
.fl
|
2692
|
434 |
\-sourcepath /java/pubs/ws/1.3/src/share/classes
|
|
435 |
.fl
|
|
436 |
|
2
|
437 |
.fl
|
|
438 |
\fP
|
|
439 |
.fi
|
|
440 |
|
|
441 |
.LP
|
|
442 |
.LP
|
|
443 |
Create a file named "\f2classes\fP" containing:
|
|
444 |
.LP
|
|
445 |
.nf
|
|
446 |
\f3
|
|
447 |
.fl
|
|
448 |
MyClass1.java
|
|
449 |
.fl
|
|
450 |
MyClass2.java
|
|
451 |
.fl
|
|
452 |
MyClass3.java
|
|
453 |
.fl
|
2692
|
454 |
|
|
455 |
.fl
|
2
|
456 |
\fP
|
|
457 |
.fi
|
|
458 |
|
|
459 |
.LP
|
|
460 |
.LP
|
2692
|
461 |
You would then run \f3javac\fP with:
|
2
|
462 |
.LP
|
|
463 |
.nf
|
|
464 |
\f3
|
|
465 |
.fl
|
|
466 |
% \fP\f3javac @options @classes\fP
|
|
467 |
.fl
|
2692
|
468 |
|
|
469 |
.fl
|
2
|
470 |
.fi
|
|
471 |
|
|
472 |
.LP
|
|
473 |
.SS
|
|
474 |
Example \- Arg Files with Paths
|
|
475 |
.LP
|
|
476 |
.LP
|
|
477 |
The argument files can have paths, but any filenames inside the files are relative to the current working directory (not \f2path1\fP or \f2path2\fP):
|
|
478 |
.LP
|
|
479 |
.nf
|
|
480 |
\f3
|
|
481 |
.fl
|
|
482 |
% \fP\f3javac @path1/options @path2/classes\fP
|
|
483 |
.fl
|
2692
|
484 |
|
|
485 |
.fl
|
2
|
486 |
.fi
|
|
487 |
|
|
488 |
.LP
|
2692
|
489 |
.SH "ANNOTATION PROCESSING"
|
|
490 |
.LP
|
|
491 |
|
|
492 |
.LP
|
|
493 |
.LP
|
|
494 |
\f3javac\fP provides direct support for annotation processing, superseding the need for the separate annotation processing tool, \f3apt\fP.
|
|
495 |
.LP
|
|
496 |
.LP
|
|
497 |
The API for annotation processors is defined in the \f2javax.annotation.processing\fP and \f2javax.lang.model\fP packages and subpackages.
|
|
498 |
.LP
|
|
499 |
.SS
|
|
500 |
Overview of annotation processing
|
|
501 |
.LP
|
|
502 |
.LP
|
|
503 |
Unless annotation processing is disabled with the \f3\-proc:none\fP option, the compiler searches for any annotation processors that are available. The search path can be specified with the \f3\-processorpath\fP option; if it is not given, the user class path is used. Processors are located by means of service provider\-configuration files named
|
|
504 |
.br
|
|
505 |
\f2\ META\-INF/services/javax.annotation.processing.Processor\fP
|
|
506 |
.br
|
|
507 |
on the search path. Such files should contain the names of any annotation processors to be used, listed one per line. Alternatively, processors can be specified explicitly, using the \f3\-processor\fP option.
|
|
508 |
.LP
|
|
509 |
.LP
|
|
510 |
After scanning the source files and classes on the command line to determine what annotations are present, the compiler queries the processors to determine what annotations they process. When a match is found, the processor will be invoked. A processor may "claim" the annotations it processes, in which case no further attempt is made to find any processors for those annotations. Once all annotations have been claimed, the compiler does not look for additional processors.
|
|
511 |
.LP
|
|
512 |
.LP
|
|
513 |
If any processors generate any new source files, another round of annotation processing will occur: any newly generated source files will be scanned, and the annotations processed as before. Any processors invoked on previous rounds will also be invoked on all subsequent rounds. This continues until no new source files are generated.
|
|
514 |
.LP
|
|
515 |
.LP
|
|
516 |
After a round occurs where no new source files are generated, the annotation processors will be invoked one last time, to give them a chance to complete any work they may need to do. Finally, unless the \f3\-proc:only\fP option is used, the compiler will compile the original and all the generated source files.
|
|
517 |
.LP
|
|
518 |
.SS
|
|
519 |
Implicitly loaded source files
|
|
520 |
.LP
|
|
521 |
.LP
|
|
522 |
To compile a set of source files, the compiler may need to implicitly load additional source files. (See Searching For Types). Such files are currently not subject to annotation processing. By default, the compiler will give a warning if annotation processing has occurred and any implicitly loaded source files are compiled. See the \-implicit option for ways to suppress the warning.
|
|
523 |
.LP
|
|
524 |
.SH "SEARCHING FOR TYPES"
|
|
525 |
.LP
|
|
526 |
|
|
527 |
.LP
|
|
528 |
.LP
|
|
529 |
When compiling a source file, the compiler often needs information about a type whose definition did not appear in the source files given on the command line. The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance.
|
|
530 |
.LP
|
|
531 |
.LP
|
|
532 |
For example, when you subclass \f3java.applet.Applet\fP, you are also using \f3Applet's\fP ancestor classes: \f3java.awt.Panel\fP, \f3java.awt.Container\fP, \f3java.awt.Component\fP, and \f3java.lang.Object\fP.
|
|
533 |
.LP
|
|
534 |
.LP
|
|
535 |
When the compiler needs type information, it looks for a source file or class file which defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the \f3CLASSPATH\fP environment variable or by using the \f3\-classpath\fP command line option. (For details, see
|
|
536 |
.na
|
|
537 |
\f2Setting the Class Path\fP @
|
|
538 |
.fi
|
|
539 |
http://java.sun.com/javase/6/docs/technotes/tools/index.html#classpath).
|
|
540 |
.LP
|
|
541 |
.LP
|
|
542 |
If you set the \-sourcepath option, the compiler searches the indicated path for source files; otherwise the compiler searches the user class path for both class files and source files.
|
|
543 |
.LP
|
|
544 |
.LP
|
|
545 |
You can specify different bootstrap or extension classes with the \f3\-bootclasspath\fP and \f3\-extdirs\fP options; see Cross\-Compilation Options below.
|
|
546 |
.LP
|
|
547 |
.LP
|
|
548 |
A successful type search may produce a class file, a source file, or both. If both are found, you can use the \-Xprefer option to instruct the compiler which to use. If \f3newer\fP is given, the compiler will use the newer of the two files. If \f3source\fP is given, it will use the source file. The default is \f3newer\fP.
|
|
549 |
.LP
|
|
550 |
.LP
|
|
551 |
If a type search finds a source file for a required type, either by itself, or as a result of the setting for \f3\-Xprefer\fP, the compiler will read the source file to get the information it needs. In addition, it will by default compile the source file as well. You can use the \-implicit option to specify the behavior. If \f3none\fP is given, no class files will be generated for the source file. If \f3class\fP is given, class files will be generated for the source file.
|
|
552 |
.LP
|
|
553 |
.LP
|
|
554 |
The compiler may not discover the need for some type information until after annotation processing is complete. If the type information is found in a source file and no \f3\-implicit\fP option is given, the compiler will give a warning that the file is being compiled without being subject to annotation processing. To disable the warning, either specify the file on the command line (so that it will be subject to annotation processing) or use the \f3\-implicit\fP option to specify whether or not class files should be generated for such source files.
|
|
555 |
.LP
|
2
|
556 |
.SH "PROGRAMMATIC INTERFACE"
|
|
557 |
.LP
|
2692
|
558 |
|
|
559 |
.LP
|
|
560 |
.LP
|
|
561 |
\f3javac\fP supports the new Java Compiler API defined by the classes and interfaces in the \f2javax.tools\fP package.
|
|
562 |
.LP
|
|
563 |
.SS
|
|
564 |
Example
|
|
565 |
.LP
|
|
566 |
.LP
|
|
567 |
To perform a compilation using arguments as you would give on the command line, you can use the following:
|
|
568 |
.LP
|
|
569 |
.nf
|
|
570 |
\f3
|
|
571 |
.fl
|
|
572 |
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
|
|
573 |
.fl
|
|
574 |
int rc = javac.run(null, null, null, args);
|
|
575 |
.fl
|
|
576 |
|
|
577 |
.fl
|
|
578 |
\fP
|
|
579 |
.fi
|
|
580 |
|
|
581 |
.LP
|
|
582 |
.LP
|
|
583 |
This will write any diagnostics to the standard output stream, and return the exit code that \f3javac\fP would give when invoked from the command line.
|
|
584 |
.LP
|
|
585 |
.LP
|
|
586 |
You can use other methods on the \f2javax.tools.JavaCompiler\fP interface to handle diagnostics, control where files are read from and written to, and so on.
|
|
587 |
.LP
|
|
588 |
.SS
|
|
589 |
Old Interface
|
|
590 |
.LP
|
|
591 |
.RS 3
|
|
592 |
|
|
593 |
.LP
|
|
594 |
.LP
|
|
595 |
\f3Note:\fP \ This API is retained for backwards compatibility only; all new code should use the Java Compiler API, described above.
|
|
596 |
.LP
|
2
|
597 |
.LP
|
|
598 |
The \f2com.sun.tools.javac.Main\fP class provides two static methods to invoke the compiler from a program:
|
|
599 |
.LP
|
|
600 |
.nf
|
|
601 |
\f3
|
|
602 |
.fl
|
|
603 |
public static int compile(String[] args);
|
|
604 |
.fl
|
|
605 |
public static int compile(String[] args, PrintWriter out);
|
|
606 |
.fl
|
2692
|
607 |
|
|
608 |
.fl
|
2
|
609 |
\fP
|
|
610 |
.fi
|
|
611 |
|
|
612 |
.LP
|
|
613 |
.LP
|
|
614 |
The \f2args\fP parameter represents any of the command line arguments that would normally be passed to the javac program and are outlined in the above Synopsis section.
|
|
615 |
.LP
|
|
616 |
.LP
|
|
617 |
The \f2out\fP parameter indicates where the compiler's diagnostic output is directed.
|
|
618 |
.LP
|
|
619 |
.LP
|
2692
|
620 |
The return value is equivalent to the exit value from \f3javac\fP.
|
2
|
621 |
.LP
|
|
622 |
.LP
|
|
623 |
Note that all \f3other\fP classes and methods found in a package whose name starts with \f2com.sun.tools.javac\fP (informally known as sub\-packages of \f2com.sun.tools.javac\fP) are strictly internal and subject to change at any time.
|
|
624 |
.LP
|
2692
|
625 |
.RE
|
2
|
626 |
.SH "EXAMPLES"
|
|
627 |
.LP
|
|
628 |
.SS
|
|
629 |
Compiling a Simple Program
|
|
630 |
.LP
|
|
631 |
.RS 3
|
|
632 |
|
|
633 |
.LP
|
|
634 |
.LP
|
|
635 |
One source file, \f2Hello.java\fP, defines a class called \f3greetings.Hello\fP. The \f2greetings\fP directory is the package directory both for the source file and the class file and is off the current directory. This allows us to use the default user class path. It also makes it unnecessary to specify a separate destination directory with \f3\-d\fP.
|
|
636 |
.LP
|
|
637 |
.RS 3
|
|
638 |
|
|
639 |
.LP
|
|
640 |
.nf
|
|
641 |
\f3
|
|
642 |
.fl
|
|
643 |
% \fP\f3ls\fP
|
|
644 |
.fl
|
|
645 |
greetings/
|
|
646 |
.fl
|
|
647 |
% \f3ls greetings\fP
|
|
648 |
.fl
|
|
649 |
Hello.java
|
|
650 |
.fl
|
|
651 |
% \f3cat greetings/Hello.java\fP
|
|
652 |
.fl
|
|
653 |
package greetings;
|
|
654 |
.fl
|
|
655 |
|
|
656 |
.fl
|
|
657 |
public class Hello {
|
|
658 |
.fl
|
|
659 |
public static void main(String[] args) {
|
|
660 |
.fl
|
|
661 |
for (int i=0; i < args.length; i++) {
|
|
662 |
.fl
|
|
663 |
System.out.println("Hello " + args[i]);
|
|
664 |
.fl
|
|
665 |
}
|
|
666 |
.fl
|
|
667 |
}
|
|
668 |
.fl
|
|
669 |
}
|
|
670 |
.fl
|
|
671 |
% \f3javac greetings/Hello.java\fP
|
|
672 |
.fl
|
|
673 |
% \f3ls greetings\fP
|
|
674 |
.fl
|
|
675 |
Hello.class Hello.java
|
|
676 |
.fl
|
|
677 |
% \f3java greetings.Hello World Universe Everyone\fP
|
|
678 |
.fl
|
|
679 |
Hello World
|
|
680 |
.fl
|
|
681 |
Hello Universe
|
|
682 |
.fl
|
|
683 |
Hello Everyone
|
|
684 |
.fl
|
2692
|
685 |
|
|
686 |
.fl
|
2
|
687 |
.fi
|
|
688 |
.RE
|
|
689 |
|
|
690 |
.LP
|
|
691 |
.RE
|
|
692 |
.SS
|
|
693 |
Compiling Multiple Source Files
|
|
694 |
.LP
|
|
695 |
.RS 3
|
|
696 |
|
|
697 |
.LP
|
|
698 |
.LP
|
|
699 |
This example compiles all the source files in the package \f2greetings\fP.
|
|
700 |
.LP
|
|
701 |
.RS 3
|
|
702 |
|
|
703 |
.LP
|
|
704 |
.nf
|
|
705 |
\f3
|
|
706 |
.fl
|
|
707 |
% \fP\f3ls\fP
|
|
708 |
.fl
|
|
709 |
greetings/
|
|
710 |
.fl
|
|
711 |
% \f3ls greetings\fP
|
|
712 |
.fl
|
|
713 |
Aloha.java GutenTag.java Hello.java Hi.java
|
|
714 |
.fl
|
|
715 |
% \f3javac greetings/*.java\fP
|
|
716 |
.fl
|
|
717 |
% \f3ls greetings\fP
|
|
718 |
.fl
|
|
719 |
Aloha.class GutenTag.class Hello.class Hi.class
|
|
720 |
.fl
|
|
721 |
Aloha.java GutenTag.java Hello.java Hi.java
|
|
722 |
.fl
|
|
723 |
|
|
724 |
.fl
|
2692
|
725 |
|
|
726 |
.fl
|
2
|
727 |
.fi
|
|
728 |
.RE
|
|
729 |
|
|
730 |
.LP
|
|
731 |
.RE
|
|
732 |
.SS
|
|
733 |
Specifying a User Class Path
|
|
734 |
.LP
|
|
735 |
.RS 3
|
|
736 |
|
|
737 |
.LP
|
|
738 |
.LP
|
|
739 |
Having changed one of the source files in the previous example, we recompile it:
|
|
740 |
.LP
|
|
741 |
.RS 3
|
|
742 |
|
|
743 |
.LP
|
|
744 |
.nf
|
|
745 |
\f3
|
|
746 |
.fl
|
|
747 |
% \fP\f3pwd\fP
|
|
748 |
.fl
|
|
749 |
/examples
|
|
750 |
.fl
|
|
751 |
% \f3javac greetings/Hi.java\fP
|
|
752 |
.fl
|
2692
|
753 |
|
|
754 |
.fl
|
2
|
755 |
.fi
|
|
756 |
.RE
|
|
757 |
|
|
758 |
.LP
|
|
759 |
.LP
|
|
760 |
Since \f2greetings.Hi\fP refers to other classes in the \f2greetings\fP package, the compiler needs to find these other classes. The example above works, because our default user class path happens to be the directory containing the package directory. But suppose we want to recompile this file and not worry about which directory we're in? Then we need to add \f2/examples\fP to the user class path. We can do this by setting \f3CLASSPATH\fP, but here we'll use the \f3\-classpath\fP option.
|
|
761 |
.LP
|
|
762 |
.RS 3
|
|
763 |
|
|
764 |
.LP
|
|
765 |
.nf
|
|
766 |
\f3
|
|
767 |
.fl
|
|
768 |
% \fP\f3javac \-classpath /examples /examples/greetings/Hi.java\fP
|
|
769 |
.fl
|
2692
|
770 |
|
|
771 |
.fl
|
2
|
772 |
.fi
|
|
773 |
.RE
|
|
774 |
|
|
775 |
.LP
|
|
776 |
.LP
|
|
777 |
If we change \f2greetings.Hi\fP again, to use a banner utility, that utility also needs to be accessible through the user class path.
|
|
778 |
.LP
|
|
779 |
.RS 3
|
|
780 |
|
|
781 |
.LP
|
|
782 |
.nf
|
|
783 |
\f3
|
|
784 |
.fl
|
2692
|
785 |
% \fP\f3javac \-classpath /examples:/lib/Banners.jar \\
|
2
|
786 |
.fl
|
2692
|
787 |
/examples/greetings/Hi.java\fP
|
|
788 |
.fl
|
|
789 |
|
2
|
790 |
.fl
|
|
791 |
.fi
|
|
792 |
.RE
|
|
793 |
|
|
794 |
.LP
|
|
795 |
.LP
|
|
796 |
To execute a class in \f2greetings\fP, we need access both to \f2greetings\fP and to the classes it uses.
|
|
797 |
.LP
|
|
798 |
.RS 3
|
|
799 |
|
|
800 |
.LP
|
|
801 |
.nf
|
|
802 |
\f3
|
|
803 |
.fl
|
|
804 |
% \fP\f3java \-classpath /examples:/lib/Banners.jar greetings.Hi\fP
|
|
805 |
.fl
|
2692
|
806 |
|
|
807 |
.fl
|
2
|
808 |
.fi
|
|
809 |
.RE
|
|
810 |
|
|
811 |
.LP
|
|
812 |
.RE
|
|
813 |
.SS
|
|
814 |
Separating Source Files and Class Files
|
|
815 |
.LP
|
|
816 |
.RS 3
|
|
817 |
|
|
818 |
.LP
|
|
819 |
.LP
|
|
820 |
It often makes sense to keep source files and class files in separate directories, especially on large projects. We use \f3\-d\fP to indicate the separate class file destination. Since the source files are not in the user class path, we use \f3\-sourcepath\fP to help the compiler find them.
|
|
821 |
.LP
|
|
822 |
.RS 3
|
|
823 |
|
|
824 |
.LP
|
|
825 |
.nf
|
|
826 |
\f3
|
|
827 |
.fl
|
|
828 |
% \fP\f3ls\fP
|
|
829 |
.fl
|
|
830 |
classes/ lib/ src/
|
|
831 |
.fl
|
|
832 |
% \f3ls src\fP
|
|
833 |
.fl
|
|
834 |
farewells/
|
|
835 |
.fl
|
|
836 |
% \f3ls src/farewells\fP
|
|
837 |
.fl
|
|
838 |
Base.java GoodBye.java
|
|
839 |
.fl
|
|
840 |
% \f3ls lib\fP
|
|
841 |
.fl
|
|
842 |
Banners.jar
|
|
843 |
.fl
|
|
844 |
% \f3ls classes\fP
|
|
845 |
.fl
|
2692
|
846 |
% \f3javac \-sourcepath src \-classpath classes:lib/Banners.jar \\
|
2
|
847 |
.fl
|
2692
|
848 |
src/farewells/GoodBye.java \-d classes\fP
|
2
|
849 |
.fl
|
|
850 |
% \f3ls classes\fP
|
|
851 |
.fl
|
|
852 |
farewells/
|
|
853 |
.fl
|
|
854 |
% \f3ls classes/farewells\fP
|
|
855 |
.fl
|
|
856 |
Base.class GoodBye.class
|
|
857 |
.fl
|
|
858 |
|
|
859 |
.fl
|
2692
|
860 |
|
|
861 |
.fl
|
2
|
862 |
.fi
|
|
863 |
.RE
|
|
864 |
|
|
865 |
.LP
|
|
866 |
.LP
|
|
867 |
\f3Note:\fP \ The compiler compiled \f2src/farewells/Base.java\fP, even though we didn't specify it on the command line. To trace automatic compiles, use the \f3\-verbose\fP option.
|
|
868 |
.LP
|
|
869 |
.RE
|
|
870 |
.SS
|
|
871 |
Cross\-Compilation Example
|
|
872 |
.LP
|
|
873 |
.RS 3
|
|
874 |
|
|
875 |
.LP
|
|
876 |
.LP
|
2692
|
877 |
Here we use \f3javac\fP to compile code that will run on a 1.7 VM.
|
2
|
878 |
.LP
|
|
879 |
.RS 3
|
|
880 |
|
|
881 |
.LP
|
|
882 |
.nf
|
|
883 |
\f3
|
|
884 |
.fl
|
2692
|
885 |
% \fP\f3javac \-target 1.7 \-bootclasspath jdk1.7.0/lib/rt.jar \\
|
2
|
886 |
.fl
|
2692
|
887 |
\-extdirs "" OldCode.java\fP
|
|
888 |
.fl
|
|
889 |
|
2
|
890 |
.fl
|
|
891 |
.fi
|
|
892 |
.RE
|
|
893 |
|
|
894 |
.LP
|
|
895 |
.LP
|
2692
|
896 |
The \f3\-target 1.7\fP option ensures that the generated class files will be compatible with 1.7 VMs. By default, \f3javac\fP compiles for JDK 6.
|
2
|
897 |
.LP
|
|
898 |
.LP
|
2692
|
899 |
The Java Platform JDK's \f3javac\fP would also by default compile against its own bootstrap classes, so we need to tell \f3javac\fP to compile against JDK 1.7 bootstrap classes instead. We do this with \f3\-bootclasspath\fP and \f3\-extdirs\fP. Failing to do this might allow compilation against a Java Platform API that would not be present on a 1.7 VM and would fail at runtime.
|
2
|
900 |
.LP
|
|
901 |
.RE
|
|
902 |
.SH "SEE ALSO"
|
|
903 |
.LP
|
|
904 |
|
|
905 |
.LP
|
|
906 |
.RS 3
|
|
907 |
.TP 2
|
|
908 |
o
|
2692
|
909 |
.na
|
|
910 |
\f2The javac Guide\fP @
|
|
911 |
.fi
|
|
912 |
http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html
|
2
|
913 |
.TP 2
|
|
914 |
o
|
2692
|
915 |
java(1) \- the Java Application Launcher
|
2
|
916 |
.TP 2
|
|
917 |
o
|
2692
|
918 |
jdb(1) \- Java Application Debugger
|
|
919 |
.TP 2
|
|
920 |
o
|
|
921 |
javah(1) \- C Header and Stub File Generator
|
2
|
922 |
.TP 2
|
|
923 |
o
|
2692
|
924 |
javap(1) \- Class File Disassembler
|
2
|
925 |
.TP 2
|
|
926 |
o
|
2692
|
927 |
javadoc(1) \- API Documentation Generator
|
2
|
928 |
.TP 2
|
|
929 |
o
|
2692
|
930 |
jar(1) \- JAR Archive Tool
|
2
|
931 |
.TP 2
|
|
932 |
o
|
|
933 |
.na
|
|
934 |
\f2The Java Extensions Framework\fP @
|
|
935 |
.fi
|
|
936 |
http://java.sun.com/javase/6/docs/technotes/guides/extensions/index.html
|
|
937 |
.RE
|
|
938 |
|
|
939 |
.LP
|
|
940 |
|