2
|
1 |
." Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
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 |
."
|
|
22 |
.TH javac 1 "04 May 2009"
|
|
23 |
." Generated from HTML by html2man (author: Eric Armstrong)
|
2
|
24 |
|
|
25 |
.LP
|
2692
|
26 |
.SH "Name"
|
2
|
27 |
javac \- Java programming language compiler
|
|
28 |
.LP
|
|
29 |
.SH "SYNOPSIS"
|
|
30 |
.LP
|
|
31 |
|
|
32 |
.LP
|
|
33 |
.nf
|
|
34 |
\f3
|
|
35 |
.fl
|
2692
|
36 |
\fP\f3javac\fP [ options ] [ sourcefiles ] [ classes ] [ @argfiles ]
|
|
37 |
.fl
|
|
38 |
|
2
|
39 |
.fl
|
|
40 |
.fi
|
|
41 |
|
|
42 |
.LP
|
|
43 |
.LP
|
|
44 |
Arguments may be in any order.
|
|
45 |
.LP
|
|
46 |
.RS 3
|
|
47 |
|
|
48 |
.LP
|
|
49 |
.RS 3
|
|
50 |
.TP 3
|
|
51 |
options
|
|
52 |
Command\-line options.
|
|
53 |
.TP 3
|
|
54 |
sourcefiles
|
|
55 |
One or more source files to be compiled (such as MyClass.java).
|
|
56 |
.TP 3
|
2692
|
57 |
classes
|
|
58 |
One or more classes to be processed for annotations (such as MyPackage.MyClass).
|
|
59 |
.TP 3
|
2
|
60 |
@argfiles
|
|
61 |
One or more files that lists options and source files. The \f2\-J\fP options are not allowed in these files.
|
|
62 |
.RE
|
|
63 |
|
|
64 |
.LP
|
|
65 |
.RE
|
|
66 |
.SH "DESCRIPTION"
|
|
67 |
.LP
|
|
68 |
|
|
69 |
.LP
|
|
70 |
.LP
|
2692
|
71 |
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
|
72 |
.LP
|
|
73 |
.LP
|
2692
|
74 |
There are two ways to pass source code file names to \f3javac\fP:
|
2
|
75 |
.LP
|
|
76 |
.RS 3
|
|
77 |
.TP 2
|
|
78 |
o
|
|
79 |
For a small number of source files, simply list the file names on the command line.
|
|
80 |
.TP 2
|
|
81 |
o
|
|
82 |
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.
|
|
83 |
.RE
|
|
84 |
|
|
85 |
.LP
|
|
86 |
.LP
|
|
87 |
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.
|
|
88 |
.LP
|
|
89 |
.LP
|
|
90 |
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.
|
|
91 |
.LP
|
|
92 |
.LP
|
|
93 |
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.
|
|
94 |
.LP
|
|
95 |
.LP
|
|
96 |
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).
|
|
97 |
.LP
|
|
98 |
.SH "OPTIONS"
|
|
99 |
.LP
|
|
100 |
|
|
101 |
.LP
|
|
102 |
.LP
|
|
103 |
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.
|
|
104 |
.LP
|
|
105 |
.SS
|
|
106 |
Standard Options
|
|
107 |
.LP
|
|
108 |
.RS 3
|
|
109 |
|
|
110 |
.LP
|
|
111 |
.RS 3
|
|
112 |
.TP 3
|
2692
|
113 |
\-Akey[=value]
|
|
114 |
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 ".".
|
|
115 |
.TP 3
|
|
116 |
\-cp path or \-classpath path
|
|
117 |
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
|
|
118 |
.na
|
|
119 |
\f2Setting the Class Path\fP @
|
|
120 |
.fi
|
|
121 |
http://java.sun.com/javase/6/docs/technotes/tools/index.html#classpath for more details.
|
2
|
122 |
.LP
|
2692
|
123 |
If the \f3\-sourcepath\fP option is not specified, the user class path is also searched for source files.
|
2
|
124 |
.LP
|
2692
|
125 |
If the \f3\-processorpath\fP option is not specified, the classpath is also searched for annotation processors.
|
|
126 |
.LP
|
|
127 |
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
|
128 |
.br
|
|
129 |
.br
|
2692
|
130 |
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
|
131 |
.TP 3
|
|
132 |
\-Djava.ext.dirs=directories
|
|
133 |
Override the location of installed extensions.
|
|
134 |
.TP 3
|
|
135 |
\-Djava.endorsed.dirs=directories
|
|
136 |
Override the location of endorsed standards path.
|
|
137 |
.TP 3
|
|
138 |
\-d directory
|
2692
|
139 |
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
|
140 |
.LP
|
2692
|
141 |
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
|
142 |
.LP
|
|
143 |
\f3Note:\fP \ The directory specified by \f3\-d\fP is not automatically added to your user class path.
|
|
144 |
.TP 3
|
|
145 |
\-deprecation
|
2692
|
146 |
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
|
147 |
.TP 3
|
|
148 |
\-encoding encoding
|
2692
|
149 |
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
|
150 |
.TP 3
|
|
151 |
\-g
|
|
152 |
Generate all debugging information, including local variables. By default, only line number and source file information is generated.
|
|
153 |
.TP 3
|
|
154 |
\-g:none
|
|
155 |
Do not generate any debugging information.
|
|
156 |
.TP 3
|
|
157 |
\-g:{keyword list}
|
|
158 |
Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
|
|
159 |
.RS 3
|
|
160 |
.TP 3
|
|
161 |
source
|
|
162 |
Source file debugging information
|
|
163 |
.TP 3
|
|
164 |
lines
|
|
165 |
Line number debugging information
|
|
166 |
.TP 3
|
|
167 |
vars
|
|
168 |
Local variable debugging information
|
|
169 |
.RE
|
|
170 |
.TP 3
|
|
171 |
\-help
|
|
172 |
Print a synopsis of standard options.
|
|
173 |
.TP 3
|
2692
|
174 |
\-implicit:{class,none}
|
|
175 |
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.
|
|
176 |
.TP 3
|
2
|
177 |
\-nowarn
|
|
178 |
Disable warning messages. This has the same meaning as \f3\-Xlint:none\fP.
|
2692
|
179 |
.TP 3
|
|
180 |
\-proc: {none,only}
|
|
181 |
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.
|
|
182 |
.TP 3
|
|
183 |
\-processor class1[,class2,class3...]
|
|
184 |
Names of the annotation processors to run. This bypasses the default discovery process.
|
|
185 |
.TP 3
|
|
186 |
\-processorpath path
|
|
187 |
Specify where to find annotation processors; if this option is not used, the classpath will be searched for processors.
|
|
188 |
.TP 3
|
|
189 |
\-s dir
|
|
190 |
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
|
191 |
.TP 3
|
|
192 |
\-source release
|
|
193 |
Specifies the version of source code accepted. The following values for \f2release\fP are allowed:
|
|
194 |
.RS 3
|
|
195 |
.TP 3
|
|
196 |
1.3
|
|
197 |
The compiler does \f2not\fP support assertions, generics, or other language features introduced after JDK 1.3.
|
|
198 |
.TP 3
|
|
199 |
1.4
|
|
200 |
The compiler accepts code containing assertions, which were introduced in JDK 1.4.
|
|
201 |
.TP 3
|
|
202 |
1.5
|
2692
|
203 |
The compiler accepts code containing generics and other language features introduced in JDK 5.
|
2
|
204 |
.TP 3
|
|
205 |
5
|
2692
|
206 |
Synonym for 1.5.
|
|
207 |
.TP 3
|
|
208 |
1.6
|
|
209 |
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.
|
|
210 |
.TP 3
|
|
211 |
6
|
|
212 |
Synonym for 1.6.
|
|
213 |
.TP 3
|
|
214 |
1.7
|
|
215 |
The compiler accepts code with features introduced in JDK 7.
|
|
216 |
.TP 3
|
|
217 |
7
|
|
218 |
Synonym for 1.7.
|
2
|
219 |
.RE
|
|
220 |
.TP 3
|
|
221 |
\-sourcepath sourcepath
|
|
222 |
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.
|
|
223 |
.LP
|
2692
|
224 |
\f3Note:\fP \ Classes found through the classpath may be subject to automatic recompilation if their sources are also found. See Searching For Types.
|
2
|
225 |
.TP 3
|
|
226 |
\-verbose
|
2692
|
227 |
Verbose output. This includes information about each class loaded and each source file compiled.
|
|
228 |
.TP 3
|
|
229 |
\-version
|
|
230 |
Print version information.
|
2
|
231 |
.TP 3
|
|
232 |
\-X
|
|
233 |
Display information about non\-standard options and exit.
|
|
234 |
.RE
|
|
235 |
|
|
236 |
.LP
|
|
237 |
.RE
|
|
238 |
.SS
|
|
239 |
Cross\-Compilation Options
|
|
240 |
.LP
|
|
241 |
.RS 3
|
|
242 |
|
|
243 |
.LP
|
|
244 |
.LP
|
|
245 |
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.
|
|
246 |
.LP
|
|
247 |
.RS 3
|
|
248 |
.TP 3
|
|
249 |
\-target version
|
2692
|
250 |
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
|
251 |
.LP
|
|
252 |
The default for \f3\-target\fP depends on the value of \f3\-source\fP:
|
|
253 |
.RS 3
|
|
254 |
.TP 2
|
|
255 |
o
|
|
256 |
If \-source is \f3not specified\fP, the value of \-target is \f31.6\fP
|
|
257 |
.TP 2
|
|
258 |
o
|
2692
|
259 |
If \-source is \f31.2\fP, the value of \-target is \f31.4\fP
|
|
260 |
.TP 2
|
|
261 |
o
|
|
262 |
If \-source is \f31.3\fP, the value of \-target is \f31.4\fP
|
2
|
263 |
.TP 2
|
|
264 |
o
|
|
265 |
For \f3all other values\fP of \-source, the value of \-target is the value of \f3\-source\fP.
|
|
266 |
.RE
|
|
267 |
.TP 3
|
|
268 |
\-bootclasspath bootclasspath
|
|
269 |
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.
|
|
270 |
.TP 3
|
|
271 |
\-extdirs directories
|
|
272 |
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.
|
|
273 |
.RE
|
|
274 |
|
|
275 |
.LP
|
|
276 |
.RE
|
|
277 |
.SS
|
|
278 |
Non\-Standard Options
|
|
279 |
.LP
|
|
280 |
.RS 3
|
|
281 |
|
|
282 |
.LP
|
|
283 |
.RS 3
|
|
284 |
.TP 3
|
|
285 |
\-Xbootclasspath/p:path
|
|
286 |
Prepend to the bootstrap class path.
|
|
287 |
.TP 3
|
|
288 |
\-Xbootclasspath/a:path
|
|
289 |
Append to the bootstrap class path.
|
|
290 |
.TP 3
|
|
291 |
\-Xbootclasspath/:path
|
|
292 |
Override location of bootstrap class files.
|
|
293 |
.TP 3
|
|
294 |
\-Xlint
|
|
295 |
Enable all recommended warnings. In this release, all available warnings are recommended.
|
|
296 |
.TP 3
|
|
297 |
\-Xlint:none
|
|
298 |
Disable all warnings not mandated by the Java Language Specification.
|
|
299 |
.TP 3
|
2692
|
300 |
\-Xlint:\-name
|
|
301 |
Disable warning \f2name\fP, where \f2name\fP is one of the warning names supported for \f3\-Xlint:\fP\f2name\fP, below.
|
2
|
302 |
.TP 3
|
|
303 |
\-Xlint:unchecked
|
|
304 |
Give more detail for unchecked conversion warnings that are mandated by the Java Language Specification.
|
|
305 |
.TP 3
|
|
306 |
\-Xlint:path
|
|
307 |
Warn about nonexistent path (classpath, sourcepath, etc) directories.
|
|
308 |
.TP 3
|
|
309 |
\-Xlint:serial
|
|
310 |
Warn about missing \f2serialVersionUID\fP definitions on serializable classes.
|
|
311 |
.TP 3
|
|
312 |
\-Xlint:finally
|
|
313 |
Warn about \f2finally\fP clauses that cannot complete normally.
|
|
314 |
.TP 3
|
|
315 |
\-Xlint:fallthrough
|
2692
|
316 |
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
|
317 |
.RS 3
|
|
318 |
|
|
319 |
.LP
|
|
320 |
.nf
|
|
321 |
\f3
|
|
322 |
.fl
|
|
323 |
switch (x) {
|
|
324 |
.fl
|
|
325 |
case 1:
|
|
326 |
.fl
|
|
327 |
System.out.println("1");
|
|
328 |
.fl
|
|
329 |
// No break; statement here.
|
|
330 |
.fl
|
|
331 |
case 2:
|
|
332 |
.fl
|
|
333 |
System.out.println("2");
|
|
334 |
.fl
|
|
335 |
}
|
|
336 |
.fl
|
2692
|
337 |
|
|
338 |
.fl
|
2
|
339 |
\fP
|
|
340 |
.fi
|
|
341 |
.RE
|
|
342 |
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.
|
|
343 |
.TP 3
|
2692
|
344 |
\-Xmaxerrs number
|
2
|
345 |
Set the maximum number of errors to print.
|
|
346 |
.TP 3
|
|
347 |
\-Xmaxwarns number
|
|
348 |
Set the maximum number of warnings to print.
|
|
349 |
.TP 3
|
|
350 |
\-Xstdout filename
|
|
351 |
Send compiler messages to the named file. By default, compiler messages go to \f2System.err\fP.
|
2692
|
352 |
.TP 3
|
|
353 |
\-Xprefer:{newer,source}
|
|
354 |
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.
|
|
355 |
.TP 3
|
|
356 |
\-Xprint
|
|
357 |
Print out textual representation of specified types for debugging purposes; perform neither annotation processing nor compilation. The format of the output may change.
|
|
358 |
.TP 3
|
|
359 |
\-XprintProcessorInfo
|
|
360 |
Print information about which annotations a processor is asked to process.
|
|
361 |
.TP 3
|
|
362 |
\-XprintRounds
|
|
363 |
Print information about initial and subsequent annotation processing rounds.
|
2
|
364 |
.RE
|
|
365 |
|
|
366 |
.LP
|
|
367 |
.RE
|
|
368 |
.SS
|
|
369 |
The \-J Option
|
|
370 |
.LP
|
|
371 |
.RS 3
|
|
372 |
|
|
373 |
.LP
|
|
374 |
.RS 3
|
|
375 |
.TP 3
|
|
376 |
\-Joption
|
|
377 |
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.
|
|
378 |
.LP
|
|
379 |
\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.
|
|
380 |
.RE
|
|
381 |
|
|
382 |
.LP
|
|
383 |
.RE
|
|
384 |
.SH "COMMAND LINE ARGUMENT FILES"
|
|
385 |
.LP
|
|
386 |
|
|
387 |
.LP
|
|
388 |
.LP
|
|
389 |
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.
|
|
390 |
.LP
|
|
391 |
.LP
|
|
392 |
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.
|
|
393 |
.LP
|
|
394 |
.LP
|
|
395 |
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.
|
|
396 |
.LP
|
|
397 |
.LP
|
|
398 |
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.
|
|
399 |
.LP
|
|
400 |
.SS
|
|
401 |
Example \- Single Arg File
|
|
402 |
.LP
|
|
403 |
.LP
|
|
404 |
You could use a single argument file named "\f2argfile\fP" to hold all javac arguments:
|
|
405 |
.LP
|
|
406 |
.nf
|
|
407 |
\f3
|
|
408 |
.fl
|
2692
|
409 |
% \fP\f3javac @argfile\fP
|
|
410 |
.fl
|
|
411 |
|
2
|
412 |
.fl
|
|
413 |
.fi
|
|
414 |
|
|
415 |
.LP
|
|
416 |
.LP
|
|
417 |
This argument file could contain the contents of both files shown in the next example.
|
|
418 |
.LP
|
|
419 |
.SS
|
|
420 |
Example \- Two Arg Files
|
|
421 |
.LP
|
|
422 |
.LP
|
|
423 |
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.)
|
|
424 |
.LP
|
|
425 |
.LP
|
|
426 |
Create a file named "\f2options\fP" containing:
|
|
427 |
.LP
|
|
428 |
.nf
|
|
429 |
\f3
|
|
430 |
.fl
|
|
431 |
\-d classes
|
|
432 |
.fl
|
|
433 |
\-g
|
|
434 |
.fl
|
2692
|
435 |
\-sourcepath /java/pubs/ws/1.3/src/share/classes
|
|
436 |
.fl
|
|
437 |
|
2
|
438 |
.fl
|
|
439 |
\fP
|
|
440 |
.fi
|
|
441 |
|
|
442 |
.LP
|
|
443 |
.LP
|
|
444 |
Create a file named "\f2classes\fP" containing:
|
|
445 |
.LP
|
|
446 |
.nf
|
|
447 |
\f3
|
|
448 |
.fl
|
|
449 |
MyClass1.java
|
|
450 |
.fl
|
|
451 |
MyClass2.java
|
|
452 |
.fl
|
|
453 |
MyClass3.java
|
|
454 |
.fl
|
2692
|
455 |
|
|
456 |
.fl
|
2
|
457 |
\fP
|
|
458 |
.fi
|
|
459 |
|
|
460 |
.LP
|
|
461 |
.LP
|
2692
|
462 |
You would then run \f3javac\fP with:
|
2
|
463 |
.LP
|
|
464 |
.nf
|
|
465 |
\f3
|
|
466 |
.fl
|
|
467 |
% \fP\f3javac @options @classes\fP
|
|
468 |
.fl
|
2692
|
469 |
|
|
470 |
.fl
|
2
|
471 |
.fi
|
|
472 |
|
|
473 |
.LP
|
|
474 |
.SS
|
|
475 |
Example \- Arg Files with Paths
|
|
476 |
.LP
|
|
477 |
.LP
|
|
478 |
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):
|
|
479 |
.LP
|
|
480 |
.nf
|
|
481 |
\f3
|
|
482 |
.fl
|
|
483 |
% \fP\f3javac @path1/options @path2/classes\fP
|
|
484 |
.fl
|
2692
|
485 |
|
|
486 |
.fl
|
2
|
487 |
.fi
|
|
488 |
|
|
489 |
.LP
|
2692
|
490 |
.SH "ANNOTATION PROCESSING"
|
|
491 |
.LP
|
|
492 |
|
|
493 |
.LP
|
|
494 |
.LP
|
|
495 |
\f3javac\fP provides direct support for annotation processing, superseding the need for the separate annotation processing tool, \f3apt\fP.
|
|
496 |
.LP
|
|
497 |
.LP
|
|
498 |
The API for annotation processors is defined in the \f2javax.annotation.processing\fP and \f2javax.lang.model\fP packages and subpackages.
|
|
499 |
.LP
|
|
500 |
.SS
|
|
501 |
Overview of annotation processing
|
|
502 |
.LP
|
|
503 |
.LP
|
|
504 |
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
|
|
505 |
.br
|
|
506 |
\f2\ META\-INF/services/javax.annotation.processing.Processor\fP
|
|
507 |
.br
|
|
508 |
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.
|
|
509 |
.LP
|
|
510 |
.LP
|
|
511 |
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.
|
|
512 |
.LP
|
|
513 |
.LP
|
|
514 |
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.
|
|
515 |
.LP
|
|
516 |
.LP
|
|
517 |
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.
|
|
518 |
.LP
|
|
519 |
.SS
|
|
520 |
Implicitly loaded source files
|
|
521 |
.LP
|
|
522 |
.LP
|
|
523 |
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.
|
|
524 |
.LP
|
|
525 |
.SH "SEARCHING FOR TYPES"
|
|
526 |
.LP
|
|
527 |
|
|
528 |
.LP
|
|
529 |
.LP
|
|
530 |
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.
|
|
531 |
.LP
|
|
532 |
.LP
|
|
533 |
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.
|
|
534 |
.LP
|
|
535 |
.LP
|
|
536 |
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
|
|
537 |
.na
|
|
538 |
\f2Setting the Class Path\fP @
|
|
539 |
.fi
|
|
540 |
http://java.sun.com/javase/6/docs/technotes/tools/index.html#classpath).
|
|
541 |
.LP
|
|
542 |
.LP
|
|
543 |
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.
|
|
544 |
.LP
|
|
545 |
.LP
|
|
546 |
You can specify different bootstrap or extension classes with the \f3\-bootclasspath\fP and \f3\-extdirs\fP options; see Cross\-Compilation Options below.
|
|
547 |
.LP
|
|
548 |
.LP
|
|
549 |
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.
|
|
550 |
.LP
|
|
551 |
.LP
|
|
552 |
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.
|
|
553 |
.LP
|
|
554 |
.LP
|
|
555 |
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.
|
|
556 |
.LP
|
2
|
557 |
.SH "PROGRAMMATIC INTERFACE"
|
|
558 |
.LP
|
2692
|
559 |
|
|
560 |
.LP
|
|
561 |
.LP
|
|
562 |
\f3javac\fP supports the new Java Compiler API defined by the classes and interfaces in the \f2javax.tools\fP package.
|
|
563 |
.LP
|
|
564 |
.SS
|
|
565 |
Example
|
|
566 |
.LP
|
|
567 |
.LP
|
|
568 |
To perform a compilation using arguments as you would give on the command line, you can use the following:
|
|
569 |
.LP
|
|
570 |
.nf
|
|
571 |
\f3
|
|
572 |
.fl
|
|
573 |
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
|
|
574 |
.fl
|
|
575 |
int rc = javac.run(null, null, null, args);
|
|
576 |
.fl
|
|
577 |
|
|
578 |
.fl
|
|
579 |
\fP
|
|
580 |
.fi
|
|
581 |
|
|
582 |
.LP
|
|
583 |
.LP
|
|
584 |
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.
|
|
585 |
.LP
|
|
586 |
.LP
|
|
587 |
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.
|
|
588 |
.LP
|
|
589 |
.SS
|
|
590 |
Old Interface
|
|
591 |
.LP
|
|
592 |
.RS 3
|
|
593 |
|
|
594 |
.LP
|
|
595 |
.LP
|
|
596 |
\f3Note:\fP \ This API is retained for backwards compatibility only; all new code should use the Java Compiler API, described above.
|
|
597 |
.LP
|
2
|
598 |
.LP
|
|
599 |
The \f2com.sun.tools.javac.Main\fP class provides two static methods to invoke the compiler from a program:
|
|
600 |
.LP
|
|
601 |
.nf
|
|
602 |
\f3
|
|
603 |
.fl
|
|
604 |
public static int compile(String[] args);
|
|
605 |
.fl
|
|
606 |
public static int compile(String[] args, PrintWriter out);
|
|
607 |
.fl
|
2692
|
608 |
|
|
609 |
.fl
|
2
|
610 |
\fP
|
|
611 |
.fi
|
|
612 |
|
|
613 |
.LP
|
|
614 |
.LP
|
|
615 |
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.
|
|
616 |
.LP
|
|
617 |
.LP
|
|
618 |
The \f2out\fP parameter indicates where the compiler's diagnostic output is directed.
|
|
619 |
.LP
|
|
620 |
.LP
|
2692
|
621 |
The return value is equivalent to the exit value from \f3javac\fP.
|
2
|
622 |
.LP
|
|
623 |
.LP
|
|
624 |
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.
|
|
625 |
.LP
|
2692
|
626 |
.RE
|
2
|
627 |
.SH "EXAMPLES"
|
|
628 |
.LP
|
|
629 |
.SS
|
|
630 |
Compiling a Simple Program
|
|
631 |
.LP
|
|
632 |
.RS 3
|
|
633 |
|
|
634 |
.LP
|
|
635 |
.LP
|
|
636 |
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.
|
|
637 |
.LP
|
|
638 |
.RS 3
|
|
639 |
|
|
640 |
.LP
|
|
641 |
.nf
|
|
642 |
\f3
|
|
643 |
.fl
|
|
644 |
% \fP\f3ls\fP
|
|
645 |
.fl
|
|
646 |
greetings/
|
|
647 |
.fl
|
|
648 |
% \f3ls greetings\fP
|
|
649 |
.fl
|
|
650 |
Hello.java
|
|
651 |
.fl
|
|
652 |
% \f3cat greetings/Hello.java\fP
|
|
653 |
.fl
|
|
654 |
package greetings;
|
|
655 |
.fl
|
|
656 |
|
|
657 |
.fl
|
|
658 |
public class Hello {
|
|
659 |
.fl
|
|
660 |
public static void main(String[] args) {
|
|
661 |
.fl
|
|
662 |
for (int i=0; i < args.length; i++) {
|
|
663 |
.fl
|
|
664 |
System.out.println("Hello " + args[i]);
|
|
665 |
.fl
|
|
666 |
}
|
|
667 |
.fl
|
|
668 |
}
|
|
669 |
.fl
|
|
670 |
}
|
|
671 |
.fl
|
|
672 |
% \f3javac greetings/Hello.java\fP
|
|
673 |
.fl
|
|
674 |
% \f3ls greetings\fP
|
|
675 |
.fl
|
|
676 |
Hello.class Hello.java
|
|
677 |
.fl
|
|
678 |
% \f3java greetings.Hello World Universe Everyone\fP
|
|
679 |
.fl
|
|
680 |
Hello World
|
|
681 |
.fl
|
|
682 |
Hello Universe
|
|
683 |
.fl
|
|
684 |
Hello Everyone
|
|
685 |
.fl
|
2692
|
686 |
|
|
687 |
.fl
|
2
|
688 |
.fi
|
|
689 |
.RE
|
|
690 |
|
|
691 |
.LP
|
|
692 |
.RE
|
|
693 |
.SS
|
|
694 |
Compiling Multiple Source Files
|
|
695 |
.LP
|
|
696 |
.RS 3
|
|
697 |
|
|
698 |
.LP
|
|
699 |
.LP
|
|
700 |
This example compiles all the source files in the package \f2greetings\fP.
|
|
701 |
.LP
|
|
702 |
.RS 3
|
|
703 |
|
|
704 |
.LP
|
|
705 |
.nf
|
|
706 |
\f3
|
|
707 |
.fl
|
|
708 |
% \fP\f3ls\fP
|
|
709 |
.fl
|
|
710 |
greetings/
|
|
711 |
.fl
|
|
712 |
% \f3ls greetings\fP
|
|
713 |
.fl
|
|
714 |
Aloha.java GutenTag.java Hello.java Hi.java
|
|
715 |
.fl
|
|
716 |
% \f3javac greetings/*.java\fP
|
|
717 |
.fl
|
|
718 |
% \f3ls greetings\fP
|
|
719 |
.fl
|
|
720 |
Aloha.class GutenTag.class Hello.class Hi.class
|
|
721 |
.fl
|
|
722 |
Aloha.java GutenTag.java Hello.java Hi.java
|
|
723 |
.fl
|
|
724 |
|
|
725 |
.fl
|
2692
|
726 |
|
|
727 |
.fl
|
2
|
728 |
.fi
|
|
729 |
.RE
|
|
730 |
|
|
731 |
.LP
|
|
732 |
.RE
|
|
733 |
.SS
|
|
734 |
Specifying a User Class Path
|
|
735 |
.LP
|
|
736 |
.RS 3
|
|
737 |
|
|
738 |
.LP
|
|
739 |
.LP
|
|
740 |
Having changed one of the source files in the previous example, we recompile it:
|
|
741 |
.LP
|
|
742 |
.RS 3
|
|
743 |
|
|
744 |
.LP
|
|
745 |
.nf
|
|
746 |
\f3
|
|
747 |
.fl
|
|
748 |
% \fP\f3pwd\fP
|
|
749 |
.fl
|
|
750 |
/examples
|
|
751 |
.fl
|
|
752 |
% \f3javac greetings/Hi.java\fP
|
|
753 |
.fl
|
2692
|
754 |
|
|
755 |
.fl
|
2
|
756 |
.fi
|
|
757 |
.RE
|
|
758 |
|
|
759 |
.LP
|
|
760 |
.LP
|
|
761 |
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.
|
|
762 |
.LP
|
|
763 |
.RS 3
|
|
764 |
|
|
765 |
.LP
|
|
766 |
.nf
|
|
767 |
\f3
|
|
768 |
.fl
|
|
769 |
% \fP\f3javac \-classpath /examples /examples/greetings/Hi.java\fP
|
|
770 |
.fl
|
2692
|
771 |
|
|
772 |
.fl
|
2
|
773 |
.fi
|
|
774 |
.RE
|
|
775 |
|
|
776 |
.LP
|
|
777 |
.LP
|
|
778 |
If we change \f2greetings.Hi\fP again, to use a banner utility, that utility also needs to be accessible through the user class path.
|
|
779 |
.LP
|
|
780 |
.RS 3
|
|
781 |
|
|
782 |
.LP
|
|
783 |
.nf
|
|
784 |
\f3
|
|
785 |
.fl
|
2692
|
786 |
% \fP\f3javac \-classpath /examples:/lib/Banners.jar \\
|
2
|
787 |
.fl
|
2692
|
788 |
/examples/greetings/Hi.java\fP
|
|
789 |
.fl
|
|
790 |
|
2
|
791 |
.fl
|
|
792 |
.fi
|
|
793 |
.RE
|
|
794 |
|
|
795 |
.LP
|
|
796 |
.LP
|
|
797 |
To execute a class in \f2greetings\fP, we need access both to \f2greetings\fP and to the classes it uses.
|
|
798 |
.LP
|
|
799 |
.RS 3
|
|
800 |
|
|
801 |
.LP
|
|
802 |
.nf
|
|
803 |
\f3
|
|
804 |
.fl
|
|
805 |
% \fP\f3java \-classpath /examples:/lib/Banners.jar greetings.Hi\fP
|
|
806 |
.fl
|
2692
|
807 |
|
|
808 |
.fl
|
2
|
809 |
.fi
|
|
810 |
.RE
|
|
811 |
|
|
812 |
.LP
|
|
813 |
.RE
|
|
814 |
.SS
|
|
815 |
Separating Source Files and Class Files
|
|
816 |
.LP
|
|
817 |
.RS 3
|
|
818 |
|
|
819 |
.LP
|
|
820 |
.LP
|
|
821 |
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.
|
|
822 |
.LP
|
|
823 |
.RS 3
|
|
824 |
|
|
825 |
.LP
|
|
826 |
.nf
|
|
827 |
\f3
|
|
828 |
.fl
|
|
829 |
% \fP\f3ls\fP
|
|
830 |
.fl
|
|
831 |
classes/ lib/ src/
|
|
832 |
.fl
|
|
833 |
% \f3ls src\fP
|
|
834 |
.fl
|
|
835 |
farewells/
|
|
836 |
.fl
|
|
837 |
% \f3ls src/farewells\fP
|
|
838 |
.fl
|
|
839 |
Base.java GoodBye.java
|
|
840 |
.fl
|
|
841 |
% \f3ls lib\fP
|
|
842 |
.fl
|
|
843 |
Banners.jar
|
|
844 |
.fl
|
|
845 |
% \f3ls classes\fP
|
|
846 |
.fl
|
2692
|
847 |
% \f3javac \-sourcepath src \-classpath classes:lib/Banners.jar \\
|
2
|
848 |
.fl
|
2692
|
849 |
src/farewells/GoodBye.java \-d classes\fP
|
2
|
850 |
.fl
|
|
851 |
% \f3ls classes\fP
|
|
852 |
.fl
|
|
853 |
farewells/
|
|
854 |
.fl
|
|
855 |
% \f3ls classes/farewells\fP
|
|
856 |
.fl
|
|
857 |
Base.class GoodBye.class
|
|
858 |
.fl
|
|
859 |
|
|
860 |
.fl
|
2692
|
861 |
|
|
862 |
.fl
|
2
|
863 |
.fi
|
|
864 |
.RE
|
|
865 |
|
|
866 |
.LP
|
|
867 |
.LP
|
|
868 |
\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.
|
|
869 |
.LP
|
|
870 |
.RE
|
|
871 |
.SS
|
|
872 |
Cross\-Compilation Example
|
|
873 |
.LP
|
|
874 |
.RS 3
|
|
875 |
|
|
876 |
.LP
|
|
877 |
.LP
|
2692
|
878 |
Here we use \f3javac\fP to compile code that will run on a 1.7 VM.
|
2
|
879 |
.LP
|
|
880 |
.RS 3
|
|
881 |
|
|
882 |
.LP
|
|
883 |
.nf
|
|
884 |
\f3
|
|
885 |
.fl
|
2692
|
886 |
% \fP\f3javac \-target 1.7 \-bootclasspath jdk1.7.0/lib/rt.jar \\
|
2
|
887 |
.fl
|
2692
|
888 |
\-extdirs "" OldCode.java\fP
|
|
889 |
.fl
|
|
890 |
|
2
|
891 |
.fl
|
|
892 |
.fi
|
|
893 |
.RE
|
|
894 |
|
|
895 |
.LP
|
|
896 |
.LP
|
2692
|
897 |
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
|
898 |
.LP
|
|
899 |
.LP
|
2692
|
900 |
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
|
901 |
.LP
|
|
902 |
.RE
|
|
903 |
.SH "SEE ALSO"
|
|
904 |
.LP
|
|
905 |
|
|
906 |
.LP
|
|
907 |
.RS 3
|
|
908 |
.TP 2
|
|
909 |
o
|
2692
|
910 |
.na
|
|
911 |
\f2The javac Guide\fP @
|
|
912 |
.fi
|
|
913 |
http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html
|
2
|
914 |
.TP 2
|
|
915 |
o
|
2692
|
916 |
java(1) \- the Java Application Launcher
|
2
|
917 |
.TP 2
|
|
918 |
o
|
2692
|
919 |
jdb(1) \- Java Application Debugger
|
|
920 |
.TP 2
|
|
921 |
o
|
|
922 |
javah(1) \- C Header and Stub File Generator
|
2
|
923 |
.TP 2
|
|
924 |
o
|
2692
|
925 |
javap(1) \- Class File Disassembler
|
2
|
926 |
.TP 2
|
|
927 |
o
|
2692
|
928 |
javadoc(1) \- API Documentation Generator
|
2
|
929 |
.TP 2
|
|
930 |
o
|
2692
|
931 |
jar(1) \- JAR Archive Tool
|
2
|
932 |
.TP 2
|
|
933 |
o
|
|
934 |
.na
|
|
935 |
\f2The Java Extensions Framework\fP @
|
|
936 |
.fi
|
|
937 |
http://java.sun.com/javase/6/docs/technotes/guides/extensions/index.html
|
|
938 |
.RE
|
|
939 |
|
|
940 |
.LP
|
|
941 |
|
|
942 |
.LP
|
|
943 |
|