author | egahlin |
Mon, 21 Oct 2019 16:29:38 +0200 | |
branch | JEP-349-branch |
changeset 58714 | 737134732b4a |
parent 55666 | 340d73f42b3c |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
55140 | 1 |
.\" Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved. |
31876
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
2 |
.\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
3 |
.\" |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
4 |
.\" This code is free software; you can redistribute it and/or modify it |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
5 |
.\" under the terms of the GNU General Public License version 2 only, as |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
6 |
.\" published by the Free Software Foundation. |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
7 |
.\" |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
8 |
.\" This code is distributed in the hope that it will be useful, but WITHOUT |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
9 |
.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
10 |
.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
11 |
.\" version 2 for more details (a copy is included in the LICENSE file that |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
12 |
.\" accompanied this code). |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
13 |
.\" |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
14 |
.\" You should have received a copy of the GNU General Public License version |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
15 |
.\" 2 along with this work; if not, write to the Free Software Foundation, |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
16 |
.\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
17 |
.\" |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
18 |
.\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
19 |
.\" or visit www.oracle.com if you need additional information or have any |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
20 |
.\" questions. |
91b22707521a
8131105: Header Template for nroff man pages *.1 files contains errors
mfang
parents:
21743
diff
changeset
|
21 |
.\" |
55140 | 22 |
.\" Automatically generated by Pandoc 2.3.1 |
21743 | 23 |
.\" |
55666 | 24 |
.TH "JAVAC" "1" "2019" "JDK 13" "JDK Commands" |
55140 | 25 |
.hy |
26 |
.SH NAME |
|
27 |
.PP |
|
55666 | 28 |
javac \- read Java declarations and compile them into class files |
55140 | 29 |
.SH SYNOPSIS |
21743 | 30 |
.PP |
55666 | 31 |
\f[CB]javac\f[R] [\f[I]options\f[R]] [\f[I]sourcefiles\-or\-classnames\f[R]] |
21743 | 32 |
.TP |
55140 | 33 |
.B \f[I]options\f[R] |
34 |
Command\-line options. |
|
35 |
.RS |
|
36 |
.RE |
|
21743 | 37 |
.TP |
55666 | 38 |
.B \f[I]sourcefiles\-or\-classnames\f[R] |
39 |
Source files to be compiled (for example, \f[CB]Shape.java\f[R]) or the |
|
40 |
names of previously compiled classes to be processed for annotations |
|
41 |
(for example, \f[CB]geometry.MyShape\f[R]). |
|
55140 | 42 |
.RS |
43 |
.RE |
|
44 |
.SH DESCRIPTION |
|
45 |
.PP |
|
55666 | 46 |
The \f[CB]javac\f[R] command reads \f[I]source files\f[R] that contain |
47 |
module, package and type declarations written in the Java programming |
|
48 |
language, and compiles them into \f[I]class files\f[R] that run on the |
|
49 |
Java Virtual Machine. |
|
50 |
.PP |
|
51 |
The \f[CB]javac\f[R] command can also \f[B]process annotations\f[R] in Java |
|
52 |
source files and classes. |
|
55140 | 53 |
.PP |
55666 | 54 |
Source files must have a file name extension of \f[CB]\&.java\f[R]. |
55 |
Class files have a file name extension of \f[CB]\&.class\f[R]. |
|
56 |
Both source and class files normally have file names that identify the |
|
57 |
contents. |
|
58 |
For example, a class called \f[CB]Shape\f[R] would be declared in a source |
|
59 |
file called \f[CB]Shape.java\f[R], and compiled into a class file called |
|
60 |
\f[CB]Shape.class\f[R]. |
|
55140 | 61 |
.PP |
55666 | 62 |
There are two ways to specify source files to \f[CB]javac\f[R]: |
55140 | 63 |
.IP \[bu] 2 |
55666 | 64 |
For a small number of source files, you can list their file names on the |
55140 | 65 |
command line. |
66 |
.IP \[bu] 2 |
|
67 |
For a large number of source files, you can use the |
|
55666 | 68 |
\f[CB]\@\f[R]\f[I]filename\f[R] option on the command line to specify an |
69 |
\f[I]argument file\f[R] that lists their file names. |
|
55140 | 70 |
See \f[B]Standard Options\f[R] for a description of the option and |
55666 | 71 |
\f[B]Command\-Line Argument Files\f[R] for a description of |
55140 | 72 |
\f[CB]javac\f[R] argument files. |
73 |
.PP |
|
55666 | 74 |
The order of source files specified on the command line or in an |
75 |
argument file is not important. |
|
76 |
\f[CB]javac\f[R] will compile the files together, as a group, and will |
|
77 |
automatically resolve any dependencies between the declarations in the |
|
78 |
various source files. |
|
55140 | 79 |
.PP |
55666 | 80 |
\f[CB]javac\f[R] expects that source files are arranged in one or more |
81 |
directory hierarchies on the file system, described in \f[B]Arrangement |
|
82 |
of Source Code\f[R]. |
|
55140 | 83 |
.PP |
55666 | 84 |
To compile a source file, \f[CB]javac\f[R] needs to find the declaration |
85 |
of every class or interface that is used, extended, or implemented by |
|
86 |
the code in the source file. |
|
87 |
This lets \f[CB]javac\f[R] check that the code has the right to access |
|
88 |
those classes and interfaces. |
|
89 |
Rather than specifying the source files of those classes and interfaces |
|
90 |
explicitly, you can use command\-line options to tell \f[CB]javac\f[R] |
|
91 |
where to search for their source files. |
|
92 |
If you have compiled those source files previously, you can use options |
|
93 |
to tell \f[CB]javac\f[R] where to search for the corresponding class |
|
94 |
files. |
|
95 |
The options, which all have names ending in "path", are described in |
|
96 |
\f[B]Standard Options\f[R], and further described in \f[B]Configuring a |
|
97 |
Compilation\f[R] and \f[B]Searching for Module, Package and Type |
|
98 |
Declarations\f[R]. |
|
55140 | 99 |
.PP |
55666 | 100 |
By default, \f[CB]javac\f[R] compiles each source file to a class file in |
101 |
the same directory as the source file. |
|
102 |
However, it is recommended to specify a separate destination directory |
|
103 |
with the \f[CB]\-d\f[R] option described in \f[B]Standard Options\f[R]. |
|
55140 | 104 |
.PP |
55666 | 105 |
Command\-line \f[B]options\f[R] and \f[B]environment variables\f[R] also |
106 |
control how \f[CB]javac\f[R] performs various tasks: |
|
107 |
.IP \[bu] 2 |
|
108 |
Compiling code to run on earlier releases of the JDK. |
|
109 |
.IP \[bu] 2 |
|
110 |
Compiling code to run under a debugger. |
|
111 |
.IP \[bu] 2 |
|
112 |
Checking for stylistic issues in Java source code. |
|
113 |
.IP \[bu] 2 |
|
114 |
Checking for problems in \f[CB]javadoc\f[R] comments |
|
115 |
(\f[CB]/**\ ...\ */\f[R]). |
|
116 |
.IP \[bu] 2 |
|
117 |
Processing annotations in source files and class files. |
|
118 |
.IP \[bu] 2 |
|
119 |
Upgrading and patching modules in the compile\-time environment. |
|
55140 | 120 |
.PP |
55666 | 121 |
\f[CB]javac\f[R] supports \f[B]Compiling for Earlier Releases Of The |
122 |
Platform\f[R] and can also be invoked from Java code using one of a |
|
123 |
number of \f[B]APIs\f[R] |
|
124 |
.SH OPTIONS |
|
55140 | 125 |
.PP |
55666 | 126 |
\f[CB]javac\f[R] provides \f[B]standard options\f[R], and \f[B]extra |
127 |
options\f[R] that are either non\-standard or are for advanced use. |
|
55140 | 128 |
.PP |
55666 | 129 |
Some options take one or more arguments. |
130 |
If an argument contains spaces or other whitespace characters, the value |
|
131 |
should be quoted according to the conventions of the environment being |
|
132 |
used to invoke javac. |
|
133 |
If the option begins with a single dash (\f[CB]\-\f[R]) the argument |
|
134 |
should either directly follow the option name, or should be separated |
|
135 |
with a colon (\f[CB]:\f[R]) or whitespace, depending on the option. |
|
136 |
If the option begins with a double dash (\f[CB]\-\-\f[R]), the argument |
|
137 |
may be separated either by whitespace or by an equals (\f[CB]=\f[R]) |
|
138 |
character with no additional whitespace. |
|
139 |
For example, |
|
140 |
.IP |
|
141 |
.nf |
|
142 |
\f[CB] |
|
143 |
\-Aname="J.\ Duke" |
|
144 |
\-proc:only |
|
145 |
\-d\ myDirectory |
|
146 |
\-\-module\-version\ 3 |
|
147 |
\-\-module\-version=3 |
|
148 |
\f[R] |
|
149 |
.fi |
|
55140 | 150 |
.PP |
55666 | 151 |
In the following lists of options, an argument of \f[I]path\f[R] |
152 |
represents a search path, composed of a list of file system locations |
|
153 |
separated by the platform path separator character, (semicolon |
|
154 |
\f[CB];\f[R] on Windows, or colon \f[CB]:\f[R] on other systems.) Depending |
|
155 |
on the option, the file system locations may be directories, JAR files |
|
156 |
or JMOD files. |
|
157 |
.SS Standard Options |
|
21743 | 158 |
.TP |
55140 | 159 |
.B \f[CB]\@\f[R]\f[I]filename\f[R] |
160 |
Reads options and file names from a file. |
|
161 |
To shorten or simplify the \f[CB]javac\f[R] command, you can specify one |
|
162 |
or more files that contain arguments to the \f[CB]javac\f[R] command |
|
163 |
(except \f[CB]\-J\f[R] options). |
|
164 |
This lets you to create \f[CB]javac\f[R] commands of any length on any |
|
165 |
operating system. |
|
55666 | 166 |
See \f[B]Command\-Line Argument Files\f[R]. |
55140 | 167 |
.RS |
168 |
.RE |
|
169 |
.TP |
|
170 |
.B \f[CB]\-A\f[R]\f[I]key\f[R][\f[CB]=\f[R]\f[I]value\f[R]] |
|
171 |
Specifies options to pass to annotation processors. |
|
55666 | 172 |
These options are not interpreted by \f[CB]javac\f[R] directly, but are |
55140 | 173 |
made available for use by individual processors. |
174 |
The \f[I]key\f[R] value should be one or more identifiers separated by a |
|
175 |
dot (\f[CB]\&.\f[R]). |
|
176 |
.RS |
|
177 |
.RE |
|
178 |
.TP |
|
179 |
.B \f[CB]\-\-add\-modules\f[R] \f[I]module\f[R]\f[CB],\f[R]\f[I]module\f[R] |
|
180 |
Specifies root modules to resolve in addition to the initial modules, or |
|
181 |
all modules on the module path if \f[I]module\f[R] is |
|
182 |
\f[CB]ALL\-MODULE\-PATH.\f[R] |
|
183 |
.RS |
|
184 |
.RE |
|
21743 | 185 |
.TP |
55140 | 186 |
.B \f[CB]\-\-boot\-class\-path\f[R] \f[I]path\f[R] or \f[CB]\-bootclasspath\f[R] \f[I]path\f[R] |
187 |
Overrides the location of the bootstrap class files. |
|
188 |
.RS |
|
189 |
.PP |
|
55666 | 190 |
\f[B]Note:\f[R] This can only be used when compiling for releases prior |
191 |
to JDK 9. |
|
192 |
As applicable, see the descriptions in \f[CB]\-\-release\f[R], |
|
193 |
\f[CB]\-source\f[R], or \f[CB]\-target\f[R] for details. |
|
194 |
For JDK 9 or later, see \f[CB]\-\-system\f[R]. |
|
55140 | 195 |
.RE |
21743 | 196 |
.TP |
55140 | 197 |
.B \f[CB]\-\-class\-path\f[R] \f[I]path\f[R], \f[CB]\-classpath\f[R] \f[I]path\f[R], or \f[CB]\-cp\f[R] \f[I]path\f[R] |
198 |
Specifies where to find user class files and annotation processors. |
|
199 |
This class path overrides the user class path in the \f[CB]CLASSPATH\f[R] |
|
200 |
environment variable. |
|
201 |
.RS |
|
202 |
.IP \[bu] 2 |
|
55666 | 203 |
If \f[CB]\-\-class\-path\f[R], \f[CB]\-classpath\f[R], or \f[CB]\-cp\f[R] are |
204 |
not specified, then the user class path is the value of the |
|
205 |
\f[CB]CLASSPATH\f[R] environment variable, if that is set, or else the |
|
206 |
current directory. |
|
55140 | 207 |
.IP \[bu] 2 |
55666 | 208 |
If not compiling code for modules, if the \f[CB]\-\-source\-path\f[R] or |
209 |
\-sourcepath` option is not specified, then the user class path is also |
|
210 |
searched for source files. |
|
55140 | 211 |
.IP \[bu] 2 |
55666 | 212 |
If the \f[CB]\-processorpath\f[R] option is not specified, then the class |
213 |
path is also searched for annotation processors. |
|
55140 | 214 |
.RE |
21743 | 215 |
.TP |
55140 | 216 |
.B \f[CB]\-d\f[R] \f[I]directory\f[R] |
55666 | 217 |
Sets the destination directory (or \f[I]class output directory\f[R]) for |
218 |
class files. |
|
55140 | 219 |
If a class is part of a package, then \f[CB]javac\f[R] puts the class file |
55666 | 220 |
in a subdirectory that reflects the module name (if appropriate) and |
221 |
package name. |
|
222 |
The directory, and any necessary subdirectories, will be created if they |
|
223 |
do not already exist. |
|
55140 | 224 |
.RS |
225 |
.PP |
|
55666 | 226 |
If the \f[CB]\-d\f[R] option is not specified, then \f[CB]javac\f[R] puts |
55140 | 227 |
each class file in the same directory as the source file from which it |
228 |
was generated. |
|
229 |
.PP |
|
55666 | 230 |
Except when compiling code for multiple modules, the contents of the |
231 |
class output directory will be organized in a package hierarchy. |
|
232 |
When compiling code for multiple modules, the contents of the output |
|
233 |
directory will be organized in a module hierarchy, with the contents of |
|
234 |
each module in a separate subdirectory, each organized as a package |
|
235 |
hierarchy. |
|
55140 | 236 |
.PP |
55666 | 237 |
\f[B]Note:\f[R] When compiling code for one or more modules, the class |
238 |
output directory will automatically be checked when searching for |
|
239 |
previously compiled classes. |
|
240 |
When not compiling for modules, for backwards compatibility, the |
|
241 |
directory is \f[I]not\f[R] automatically checked for previously compiled |
|
242 |
classes, and so it is recommended to specify the class output directory |
|
243 |
as one of the locations on the user class path, using the |
|
244 |
\f[CB]\-\-class\-path\f[R] option or one of its alternate forms. |
|
55140 | 245 |
.RE |
246 |
.TP |
|
247 |
.B \f[CB]\-deprecation\f[R] |
|
248 |
Shows a description of each use or override of a deprecated member or |
|
249 |
class. |
|
250 |
Without the \f[CB]\-deprecation\f[R] option, \f[CB]javac\f[R] shows a |
|
251 |
summary of the source files that use or override deprecated members or |
|
252 |
classes. |
|
253 |
The \f[CB]\-deprecation\f[R] option is shorthand for |
|
254 |
\f[CB]\-Xlint:deprecation\f[R]. |
|
255 |
.RS |
|
256 |
.RE |
|
21743 | 257 |
.TP |
55140 | 258 |
.B \f[CB]\-\-enable\-preview\f[R] |
259 |
Enables preview language features. |
|
260 |
Used in conjunction with either \f[CB]\-source\f[R] or |
|
261 |
\f[CB]\-\-release\f[R]. |
|
262 |
.RS |
|
263 |
.RE |
|
264 |
.TP |
|
265 |
.B \f[CB]\-encoding\f[R] \f[I]encoding\f[R] |
|
266 |
Specifies character encoding used by source files, such as EUC\-JP and |
|
267 |
UTF\-8. |
|
55666 | 268 |
If the \f[CB]\-encoding\f[R] option is not specified, then the platform |
55140 | 269 |
default converter is used. |
270 |
.RS |
|
271 |
.RE |
|
21743 | 272 |
.TP |
55140 | 273 |
.B \f[CB]\-endorseddirs\f[R] \f[I]directories\f[R] |
274 |
Overrides the location of the endorsed standards path. |
|
275 |
.RS |
|
276 |
.PP |
|
55666 | 277 |
\f[B]Note:\f[R] This can only be used when compiling for releases prior |
278 |
to JDK 9. |
|
279 |
As applicable, see the descriptions in \f[CB]\-\-release\f[R], |
|
280 |
\f[CB]\-source\f[R], or \f[CB]\-target\f[R] for details. |
|
55140 | 281 |
.RE |
21743 | 282 |
.TP |
55140 | 283 |
.B \f[CB]\-extdirs\f[R] \f[I]directories\f[R] |
284 |
Overrides the location of the installed extensions. |
|
55666 | 285 |
\f[CB]directories\f[R] is a list of directories, separated by the platform |
286 |
path separator (\f[CB];\f[R] on Windows, and \f[CB]:\f[R] otherwise). |
|
55140 | 287 |
Each JAR file in the specified directories is searched for class files. |
288 |
All JAR files found become part of the class path. |
|
289 |
.RS |
|
290 |
.PP |
|
55666 | 291 |
If you are compiling for a release of the platform that supports the |
292 |
Extension Mechanism, then this option specifies the directories that |
|
293 |
contain the extension classes. |
|
294 |
See [Compiling for Other Releases of the Platform]. |
|
55140 | 295 |
.PP |
55666 | 296 |
\f[B]Note:\f[R] This can only be used when compiling for releases prior |
297 |
to JDK 9. |
|
298 |
As applicable, see the descriptions in \f[CB]\-\-release\f[R], |
|
299 |
\f[CB]\-source\f[R], or \f[CB]\-target\f[R] for details. |
|
55140 | 300 |
.RE |
21743 | 301 |
.TP |
55140 | 302 |
.B \f[CB]\-g\f[R] |
303 |
Generates all debugging information, including local variables. |
|
304 |
By default, only line number and source file information is generated. |
|
305 |
.RS |
|
306 |
.RE |
|
307 |
.TP |
|
308 |
.B \f[CB]\-g:\f[R][\f[CB]lines\f[R], \f[CB]vars\f[R], \f[CB]source\f[R]] |
|
309 |
Generates only the kinds of debugging information specified by the |
|
310 |
comma\-separated list of keywords. |
|
311 |
Valid keywords are: |
|
312 |
.RS |
|
21743 | 313 |
.TP |
55140 | 314 |
.B \f[CB]lines\f[R] |
315 |
Line number debugging information. |
|
316 |
.RS |
|
317 |
.RE |
|
21743 | 318 |
.TP |
55140 | 319 |
.B \f[CB]vars\f[R] |
320 |
Local variable debugging information. |
|
321 |
.RS |
|
322 |
.RE |
|
323 |
.TP |
|
324 |
.B \f[CB]source\f[R] |
|
325 |
Source file debugging information. |
|
326 |
.RS |
|
327 |
.RE |
|
328 |
.RE |
|
21743 | 329 |
.TP |
55140 | 330 |
.B \f[CB]\-g:none\f[R] |
55666 | 331 |
Does not generate debugging information. |
55140 | 332 |
.RS |
333 |
.RE |
|
21743 | 334 |
.TP |
55140 | 335 |
.B \f[CB]\-h\f[R] \f[I]directory\f[R] |
55666 | 336 |
Specifies where to place generated native header files. |
55140 | 337 |
.RS |
338 |
.PP |
|
339 |
When you specify this option, a native header file is generated for each |
|
340 |
class that contains native methods or that has one or more constants |
|
341 |
annotated with the \f[B]\f[BC]java.lang.annotation.Native\f[B]\f[R] |
|
342 |
annotation. |
|
343 |
If the class is part of a package, then the compiler puts the native |
|
55666 | 344 |
header file in a subdirectory that reflects the module name (if |
345 |
appropriate) and package name. |
|
346 |
The directory, and any necessary subdirectories, will be created if they |
|
347 |
do not already exist. |
|
55140 | 348 |
.RE |
21743 | 349 |
.TP |
55140 | 350 |
.B \f[CB]\-\-help\f[R], \f[CB]\-help\f[R] or \f[CB]\-?\f[R] |
351 |
Prints a synopsis of the standard options. |
|
352 |
.RS |
|
353 |
.RE |
|
354 |
.TP |
|
355 |
.B \f[CB]\-\-help\-extra\f[R] or \f[CB]\-X\f[R] |
|
55666 | 356 |
Prints a synopsis of the set of extra options. |
55140 | 357 |
.RS |
358 |
.RE |
|
21743 | 359 |
.TP |
55140 | 360 |
.B \f[CB]\-implicit:\f[R][\f[CB]none\f[R], \f[CB]class\f[R]] |
361 |
Specifies whether or not to generate class files for implicitly |
|
362 |
referenced files: |
|
363 |
.RS |
|
364 |
.IP \[bu] 2 |
|
365 |
\f[CB]\-implicit:class\f[R] \-\-\- Automatically generates class files. |
|
366 |
.IP \[bu] 2 |
|
367 |
\f[CB]\-implicit:none\f[R] \-\-\- Suppresses class file generation. |
|
368 |
.PP |
|
55666 | 369 |
If this option is not specified, then the default automatically |
55140 | 370 |
generates class files. |
371 |
In this case, the compiler issues a warning if any class files are |
|
372 |
generated when also doing annotation processing. |
|
55666 | 373 |
The warning is not issued when the \f[CB]\-implicit\f[R] option is |
55140 | 374 |
explicitly set. |
55666 | 375 |
See \f[B]Searching for Module, Package and Type Declarations\f[R]. |
55140 | 376 |
.RE |
377 |
.TP |
|
378 |
.B \f[CB]\-J\f[R]\f[I]option\f[R] |
|
379 |
Passes \f[I]option\f[R] to the runtime system, where \f[I]option\f[R] is |
|
380 |
one of the Java options described on \f[B]java\f[R] command. |
|
381 |
For example, \f[CB]\-J\-Xms48m\f[R] sets the startup memory to 48 MB. |
|
382 |
.RS |
|
383 |
.PP |
|
55666 | 384 |
\f[B]Note:\f[R] The \f[CB]CLASSPATH\f[R] environment variable, |
385 |
\f[CB]\-classpath\f[R] option, \f[CB]\-bootclasspath\f[R] option, and |
|
386 |
\f[CB]\-extdirs\f[R] option do not specify the classes used to run |
|
387 |
\f[CB]javac\f[R]. |
|
55140 | 388 |
Trying to customize the compiler implementation with these options and |
55666 | 389 |
variables is risky and often does not accomplish what you want. |
390 |
If you must customize the compiler implementation, then use the |
|
55140 | 391 |
\f[CB]\-J\f[R] option to pass options through to the underlying Java |
392 |
launcher. |
|
393 |
.RE |
|
21743 | 394 |
.TP |
55140 | 395 |
.B \f[CB]\-\-limit\-modules\f[R] \f[I]module\f[R]\f[CB],\f[R]\f[I]module\f[R]* |
396 |
Limits the universe of observable modules. |
|
397 |
.RS |
|
398 |
.RE |
|
399 |
.TP |
|
55666 | 400 |
.B \f[CB]\-\-module\f[R] \f[I]module\-name\f[R] (\f[CB],\f[R]\f[I]module\-name\f[R])* or \f[CB]\-m\f[R] \f[I]module\-name\f[R] (\f[CB],\f[R]\f[I]module\-name\f[R])* |
401 |
Compiles those source files in the named modules that are newer than the |
|
402 |
corresponding files in the output directory. |
|
55140 | 403 |
.RS |
404 |
.RE |
|
405 |
.TP |
|
406 |
.B \f[CB]\-\-module\-path\f[R] \f[I]path\f[R] or \f[CB]\-p\f[R] \f[I]path\f[R] |
|
407 |
Specifies where to find application modules. |
|
408 |
.RS |
|
409 |
.RE |
|
410 |
.TP |
|
411 |
.B \f[CB]\-\-module\-source\-path\f[R] \f[I]module\-source\-path\f[R] |
|
55666 | 412 |
Specifies where to find source files when compiling code in multiple |
413 |
modules. |
|
414 |
See [Compilation Modes] and \f[B]The Module Source Path Option\f[R]. |
|
55140 | 415 |
.RS |
416 |
.RE |
|
21743 | 417 |
.TP |
55140 | 418 |
.B \f[CB]\-\-module\-version\f[R] \f[I]version\f[R] |
419 |
Specifies the version of modules that are being compiled. |
|
420 |
.RS |
|
421 |
.RE |
|
21743 | 422 |
.TP |
55140 | 423 |
.B \f[CB]\-nowarn\f[R] |
424 |
Disables warning messages. |
|
425 |
This option operates the same as the \f[CB]\-Xlint:none\f[R] option. |
|
426 |
.RS |
|
427 |
.RE |
|
21743 | 428 |
.TP |
55140 | 429 |
.B \f[CB]\-parameters\f[R] |
430 |
Generates metadata for reflection on method parameters. |
|
431 |
Stores formal parameter names of constructors and methods in the |
|
432 |
generated class file so that the method |
|
433 |
\f[CB]java.lang.reflect.Executable.getParameters\f[R] from the Reflection |
|
434 |
API can retrieve them. |
|
435 |
.RS |
|
436 |
.RE |
|
21743 | 437 |
.TP |
55140 | 438 |
.B \f[CB]\-proc:\f[R][\f[CB]none\f[R], \f[CB]only\f[R]] |
439 |
Controls whether annotation processing and compilation are done. |
|
440 |
\f[CB]\-proc:none\f[R] means that compilation takes place without |
|
441 |
annotation processing. |
|
442 |
\f[CB]\-proc:only\f[R] means that only annotation processing is done, |
|
443 |
without any subsequent compilation. |
|
444 |
.RS |
|
445 |
.RE |
|
446 |
.TP |
|
447 |
.B \f[CB]\-processor\f[R] \f[I]class1\f[R][\f[CB],\f[R]\f[I]class2\f[R]\f[CB],\f[R]\f[I]class3\f[R]...] |
|
448 |
Names of the annotation processors to run. |
|
449 |
This bypasses the default discovery process. |
|
450 |
.RS |
|
451 |
.RE |
|
452 |
.TP |
|
453 |
.B \f[CB]\-\-processor\-module\-path\f[R] \f[I]path\f[R] |
|
454 |
Specifies the module path used for finding annotation processors. |
|
455 |
.RS |
|
456 |
.RE |
|
457 |
.TP |
|
458 |
.B \f[CB]\-\-processor\-path\f[R] \f[I]path\f[R] or \f[CB]\-processorpath\f[R] \f[I]path\f[R] |
|
459 |
Specifies where to find annotation processors. |
|
55666 | 460 |
If this option is not used, then the class path is searched for |
55140 | 461 |
processors. |
462 |
.RS |
|
463 |
.RE |
|
21743 | 464 |
.TP |
55140 | 465 |
.B \f[CB]\-profile\f[R] \f[I]profile\f[R] |
466 |
Checks that the API used is available in the specified profile. |
|
467 |
.RS |
|
468 |
.PP |
|
55666 | 469 |
\f[B]Note:\f[R] This can only be used when compiling for releases prior |
470 |
to JDK 9. |
|
471 |
As applicable, see the descriptions in \f[CB]\-\-release\f[R], |
|
472 |
\f[CB]\-source\f[R], or \f[CB]\-target\f[R] for details. |
|
55140 | 473 |
.RE |
21743 | 474 |
.TP |
55140 | 475 |
.B \f[CB]\-\-release\f[R] \f[I]release\f[R] |
476 |
Compiles source code according to the rules of the Java programming |
|
55666 | 477 |
language for the specified Java SE release, generating class files which |
478 |
target that release. |
|
479 |
Source code is compiled against the combined Java SE and JDK API for the |
|
480 |
specified release. |
|
55140 | 481 |
.RS |
21743 | 482 |
.PP |
55666 | 483 |
The supported values of \f[I]release\f[R] are the current Java SE release |
484 |
and a limited number of previous releases, detailed in the command\-line |
|
485 |
help. |
|
486 |
.PP |
|
487 |
For the current release, the Java SE API consists of the |
|
488 |
\f[CB]java.*\f[R], \f[CB]javax.*\f[R], and \f[CB]org.*\f[R] packages that are |
|
489 |
exported by the Java SE modules in the release; the JDK API consists of |
|
490 |
the \f[CB]com.*\f[R] and \f[CB]jdk.*\f[R] packages that are exported by the |
|
491 |
JDK modules in the release, plus the \f[CB]javax.*\f[R] packages that are |
|
492 |
exported by standard, but non\-Java SE, modules in the release. |
|
55140 | 493 |
.PP |
55666 | 494 |
For previous releases, the Java SE API and the JDK API are as defined in |
495 |
that release. |
|
55140 | 496 |
.PP |
55666 | 497 |
\f[B]Note:\f[R] When using \f[CB]\-\-release\f[R], you cannot also use the |
498 |
\f[CB]\-\-source\f[R]/\f[CB]\-source\f[R] or |
|
499 |
\f[CB]\-\-target\f[R]/\f[CB]\-target\f[R] options. |
|
55140 | 500 |
.PP |
55666 | 501 |
\f[B]Note:\f[R] When using \f[CB]\-\-release\f[R] to specify a release that |
502 |
supports the Java Platform Module System, the \f[CB]\-\-add\-exports\f[R] |
|
503 |
option cannot be used to enlarge the set of packages exported by the |
|
504 |
Java SE, JDK, and standard modules in the specified release. |
|
55140 | 505 |
.RE |
21743 | 506 |
.TP |
55140 | 507 |
.B \f[CB]\-s\f[R] \f[I]directory\f[R] |
508 |
Specifies the directory used to place the generated source files. |
|
509 |
If a class is part of a package, then the compiler puts the source file |
|
55666 | 510 |
in a subdirectory that reflects the module name (if appropriate) and |
511 |
package name. |
|
512 |
The directory, and any necessary subdirectories, will be created if they |
|
513 |
do not already exist. |
|
55140 | 514 |
.RS |
55666 | 515 |
.PP |
516 |
Except when compiling code for multiple modules, the contents of the |
|
517 |
source output directory will be organized in a package hierarchy. |
|
518 |
When compiling code for multiple modules, the contents of the source |
|
519 |
output directory will be organized in a module hierarchy, with the |
|
520 |
contents of each module in a separate subdirectory, each organized as a |
|
521 |
package hierarchy. |
|
55140 | 522 |
.RE |
523 |
.TP |
|
524 |
.B \f[CB]\-\-source\f[R] \f[I]release\f[R] or \f[CB]\-source\f[R] \f[I]release\f[R] |
|
525 |
Compiles source code according to the rules of the Java programming |
|
526 |
language for the specified Java SE release. |
|
527 |
The supported values of \f[I]release\f[R] are the current Java SE release |
|
55666 | 528 |
and a limited number of previous releases, detailed in the command\-line |
529 |
help. |
|
55140 | 530 |
.RS |
531 |
.PP |
|
532 |
If the option is not specified, the default is to compile source code |
|
533 |
according to the rules of the Java programming language for the current |
|
534 |
Java SE release. |
|
535 |
.RE |
|
21743 | 536 |
.TP |
55140 | 537 |
.B \f[CB]\-\-source\-path\f[R] \f[I]path\f[R] or \f[CB]\-sourcepath\f[R] \f[I]path\f[R] |
55666 | 538 |
Specifies where to find source files. |
539 |
Except when compiling multiple modules together, this is the source code |
|
540 |
path used to search for class or interface definitions. |
|
55140 | 541 |
.RS |
542 |
.PP |
|
55666 | 543 |
\f[B]Note:\f[R] Classes found through the class path might be recompiled |
544 |
when their source files are also found. |
|
545 |
See \f[B]Searching for Module, Package and Type Declarations\f[R]. |
|
55140 | 546 |
.RE |
547 |
.TP |
|
548 |
.B \f[CB]\-\-system\f[R] \f[I]jdk\f[R] | \f[CB]none\f[R] |
|
549 |
Overrides the location of system modules. |
|
550 |
.RS |
|
551 |
.RE |
|
21743 | 552 |
.TP |
55140 | 553 |
.B \f[CB]\-\-target\f[R] \f[I]release\f[R] or \f[CB]\-target\f[R] \f[I]release\f[R] |
554 |
Generates \f[CB]class\f[R] files suitable for the specified Java SE |
|
555 |
release. |
|
556 |
The supported values of \f[I]release\f[R] are the current Java SE release |
|
55666 | 557 |
and a limited number of previous releases, detailed in the command\-line |
558 |
help. |
|
55140 | 559 |
.RS |
560 |
.PP |
|
55666 | 561 |
\f[B]Note:\f[R] The target release must be equal to or higher than the |
562 |
source release. |
|
563 |
(See \f[CB]\-\-source\f[R].) |
|
55140 | 564 |
.RE |
565 |
.TP |
|
566 |
.B \f[CB]\-\-upgrade\-module\-path\f[R] \f[I]path\f[R] |
|
567 |
Overrides the location of upgradeable modules. |
|
568 |
.RS |
|
569 |
.RE |
|
570 |
.TP |
|
571 |
.B \f[CB]\-verbose\f[R] |
|
572 |
Outputs messages about what the compiler is doing. |
|
573 |
Messages include information about each class loaded and each source |
|
574 |
file compiled. |
|
575 |
.RS |
|
576 |
.RE |
|
577 |
.TP |
|
578 |
.B \f[CB]\-\-version\f[R] or \f[CB]\-version\f[R] |
|
579 |
Prints version information. |
|
580 |
.RS |
|
581 |
.RE |
|
21743 | 582 |
.TP |
55140 | 583 |
.B \f[CB]\-Werror\f[R] |
584 |
Terminates compilation when warnings occur. |
|
585 |
.RS |
|
586 |
.RE |
|
55666 | 587 |
.SS Extra Options |
55140 | 588 |
.TP |
589 |
.B \f[CB]\-\-add\-exports\f[R] \f[I]module\f[R]\f[CB]/\f[R]\f[I]package\f[R]\f[CB]=\f[R]\f[I]other\-module\f[R](\f[CB],\f[R]\f[I]other\-module\f[R])* |
|
590 |
Specifies a package to be considered as exported from its defining |
|
591 |
module to additional modules or to all unnamed modules when the value of |
|
592 |
\f[I]other\-module\f[R] is \f[CB]ALL\-UNNAMED\f[R]. |
|
593 |
.RS |
|
594 |
.RE |
|
595 |
.TP |
|
596 |
.B \f[CB]\-\-add\-reads\f[R] \f[I]module\f[R]\f[CB]=\f[R]\f[I]other\-module\f[R](\f[CB],\f[R]\f[I]other\-module\f[R])* |
|
597 |
Specifies additional modules to be considered as required by a given |
|
598 |
module. |
|
599 |
.RS |
|
600 |
.RE |
|
601 |
.TP |
|
602 |
.B \f[CB]\-\-default\-module\-for\-created\-files\f[R] \f[I]module\-name\f[R] |
|
603 |
Specifies the fallback target module for files created by annotation |
|
604 |
processors, if none is specified or inferred. |
|
605 |
.RS |
|
606 |
.RE |
|
21743 | 607 |
.TP |
55140 | 608 |
.B \f[CB]\-Djava.endorsed.dirs=\f[R]\f[I]dirs\f[R] |
609 |
Overrides the location of the endorsed standards path. |
|
610 |
.RS |
|
611 |
.PP |
|
55666 | 612 |
\f[B]Note:\f[R] This can only be used when compiling for releases prior |
613 |
to JDK 9. |
|
614 |
As applicable, see the descriptions in \f[CB]\-\-release\f[R], |
|
615 |
\f[CB]\-source\f[R], or \f[CB]\-target\f[R] for details. |
|
55140 | 616 |
.RE |
617 |
.TP |
|
618 |
.B \f[CB]\-Djava.ext.dirs=\f[R]\f[I]dirs\f[R] |
|
619 |
Overrides the location of installed extensions. |
|
620 |
.RS |
|
621 |
.PP |
|
55666 | 622 |
\f[B]Note:\f[R] This can only be used when compiling for releases prior |
623 |
to JDK 9. |
|
624 |
As applicable, see the descriptions in \f[CB]\-\-release\f[R], |
|
625 |
\f[CB]\-source\f[R], or \f[CB]\-target\f[R] for details. |
|
55140 | 626 |
.RE |
21743 | 627 |
.TP |
55140 | 628 |
.B \f[CB]\-\-doclint\-format\f[R] [\f[CB]html4\f[R]|\f[CB]html5\f[R]] |
629 |
Specifies the format for documentation comments. |
|
630 |
.RS |
|
631 |
.RE |
|
632 |
.TP |
|
55666 | 633 |
.B \f[CB]\-\-patch\-module\f[R] \f[I]module\f[R]\f[CB]=\f[R]\f[I]path\f[R] |
55140 | 634 |
Overrides or augments a module with classes and resources in JAR files |
635 |
or directories. |
|
636 |
.RS |
|
637 |
.RE |
|
638 |
.TP |
|
639 |
.B \f[CB]\-Xbootclasspath:\f[R]\f[I]path\f[R] |
|
640 |
Overrides the location of the bootstrap class files. |
|
641 |
.RS |
|
642 |
.PP |
|
55666 | 643 |
\f[B]Note:\f[R] This can only be used when compiling for releases prior |
644 |
to JDK 9. |
|
645 |
As applicable, see the descriptions in \f[CB]\-\-release\f[R], |
|
646 |
\f[CB]\-source\f[R], or \f[CB]\-target\f[R] for details. |
|
55140 | 647 |
.RE |
21743 | 648 |
.TP |
55140 | 649 |
.B \f[CB]\-Xbootclasspath/a:\f[R]\f[I]path\f[R] |
650 |
Adds a suffix to the bootstrap class path. |
|
651 |
.RS |
|
652 |
.PP |
|
55666 | 653 |
\f[B]Note:\f[R] This can only be used when compiling for releases prior |
654 |
to JDK 9. |
|
655 |
As applicable, see the descriptions in \f[CB]\-\-release\f[R], |
|
656 |
\f[CB]\-source\f[R], or \f[CB]\-target\f[R] for details. |
|
55140 | 657 |
.RE |
21743 | 658 |
.TP |
55140 | 659 |
.B \f[CB]\-Xbootclasspath/p:\f[R]\f[I]path\f[R] |
660 |
Adds a prefix to the bootstrap class path. |
|
661 |
.RS |
|
662 |
.PP |
|
55666 | 663 |
\f[B]Note:\f[R] This can only be used when compiling for releases prior |
664 |
to JDK 9. |
|
665 |
As applicable, see the descriptions in \f[CB]\-\-release\f[R], |
|
666 |
\f[CB]\-source\f[R], or \f[CB]\-target\f[R] for details. |
|
55140 | 667 |
.RE |
21743 | 668 |
.TP |
55140 | 669 |
.B \f[CB]\-Xdiags:\f[R][\f[CB]compact\f[R], \f[CB]verbose\f[R]] |
670 |
Selects a diagnostic mode. |
|
671 |
.RS |
|
672 |
.RE |
|
21743 | 673 |
.TP |
55140 | 674 |
.B \f[CB]\-Xdoclint\f[R] |
675 |
Enables recommended checks for problems in \f[CB]javadoc\f[R] comments |
|
676 |
.RS |
|
677 |
.RE |
|
21743 | 678 |
.TP |
55140 | 679 |
.B \f[CB]\-Xdoclint:\f[R](\f[CB]all\f[R]|\f[CB]none\f[R]|[\f[CB]\-\f[R]]\f[I]group\f[R])[\f[CB]/\f[R]\f[I]access\f[R]] |
680 |
Enables or disables specific groups of checks, |
|
681 |
.RS |
|
682 |
.PP |
|
683 |
\f[I]group\f[R] can have one of the following values: |
|
684 |
.IP \[bu] 2 |
|
685 |
\f[CB]accessibility\f[R] |
|
686 |
.IP \[bu] 2 |
|
687 |
\f[CB]html\f[R] |
|
688 |
.IP \[bu] 2 |
|
689 |
\f[CB]missing\f[R] |
|
690 |
.IP \[bu] 2 |
|
691 |
\f[CB]reference\f[R] |
|
692 |
.IP \[bu] 2 |
|
693 |
\f[CB]syntax\f[R] |
|
694 |
.PP |
|
695 |
The variable \f[I]access\f[R] specifies the minimum visibility level of |
|
696 |
classes and members that the \f[CB]\-Xdoclint\f[R] option checks. |
|
697 |
It can have one of the following values (in order of most to least |
|
698 |
visible): |
|
699 |
.IP \[bu] 2 |
|
700 |
\f[CB]public\f[R] |
|
701 |
.IP \[bu] 2 |
|
702 |
\f[CB]protected\f[R] |
|
703 |
.IP \[bu] 2 |
|
704 |
\f[CB]package\f[R] |
|
705 |
.IP \[bu] 2 |
|
706 |
\f[CB]private\f[R] |
|
707 |
.PP |
|
708 |
The default \f[I]access\f[R] level is \f[CB]private\f[R]. |
|
709 |
.PP |
|
710 |
For more information about these groups of checks, see the |
|
711 |
\f[CB]\-Xdoclint\f[R] option of the \f[CB]javadoc\f[R] command. |
|
712 |
The \f[CB]\-Xdoclint\f[R] option is disabled by default in the |
|
713 |
\f[CB]javac\f[R] command. |
|
714 |
.PP |
|
715 |
For example, the following option checks classes and members (with all |
|
716 |
groups of checks) that have the access level of protected and higher |
|
717 |
(which includes protected and public): |
|
718 |
.RS |
|
719 |
.PP |
|
720 |
\f[CB]\-Xdoclint:all/protected\f[R] |
|
721 |
.RE |
|
722 |
.PP |
|
723 |
The following option enables all groups of checks for all access levels, |
|
55666 | 724 |
except it will not check for HTML errors for classes and members that |
55140 | 725 |
have the access level of package and higher (which includes package, |
726 |
protected and public): |
|
727 |
.RS |
|
728 |
.PP |
|
729 |
\f[CB]\-Xdoclint:all,\-html/package\f[R] |
|
730 |
.RE |
|
731 |
.RE |
|
21743 | 732 |
.TP |
55140 | 733 |
.B \f[CB]\-Xdoclint/package:\f[R][\f[CB]\-\f[R]]\f[I]packages\f[R](\f[CB],\f[R][\f[CB]\-\f[R]]\f[I]package\f[R])* |
734 |
Enables or disables checks in specific packages. |
|
735 |
Each \f[I]package\f[R] is either the qualified name of a package or a |
|
736 |
package name prefix followed by \f[CB]\&.*\f[R], which expands to all |
|
737 |
sub\-packages of the given package. |
|
738 |
Each \f[I]package\f[R] can be prefixed with a hyphen (\f[CB]\-\f[R]) to |
|
739 |
disable checks for a specified package or packages. |
|
740 |
.RS |
|
741 |
.RE |
|
21743 | 742 |
.TP |
55140 | 743 |
.B \f[CB]\-Xlint\f[R] |
744 |
Enables all recommended warnings. |
|
745 |
In this release, enabling all available warnings is recommended. |
|
746 |
.RS |
|
747 |
.RE |
|
21743 | 748 |
.TP |
55140 | 749 |
.B \f[CB]\-Xlint:\f[R][\f[CB]\-\f[R]]\f[I]key\f[R](\f[CB],\f[R][\f[CB]\-\f[R]]\f[I]key\f[R])* |
750 |
Supplies warnings to enable or disable, separated by comma. |
|
751 |
Precede a key by a hyphen (\f[CB]\-\f[R]) to disable the specified |
|
752 |
warning. |
|
753 |
.RS |
|
754 |
.PP |
|
755 |
Supported values for \f[I]key\f[R] are: |
|
756 |
.IP \[bu] 2 |
|
757 |
\f[CB]all\f[R]: Enables all warnings. |
|
758 |
.IP \[bu] 2 |
|
759 |
\f[CB]auxiliaryclass\f[R]: Warns about an auxiliary class that\[aq]s |
|
760 |
hidden in a source file, and is used from other files. |
|
761 |
.IP \[bu] 2 |
|
762 |
\f[CB]cast\f[R]: Warns about the use of unnecessary casts. |
|
763 |
.IP \[bu] 2 |
|
764 |
\f[CB]classfile\f[R]: Warns about the issues related to classfile |
|
765 |
contents. |
|
766 |
.IP \[bu] 2 |
|
767 |
\f[CB]deprecation\f[R]: Warns about the use of deprecated items. |
|
768 |
.IP \[bu] 2 |
|
769 |
\f[CB]dep\-ann\f[R]: Warns about the items marked as deprecated in |
|
770 |
\f[CB]javadoc\f[R] but without the \f[CB]\@Deprecated\f[R] annotation. |
|
771 |
.IP \[bu] 2 |
|
772 |
\f[CB]divzero\f[R]: Warns about the division by the constant integer 0. |
|
773 |
.IP \[bu] 2 |
|
774 |
\f[CB]empty\f[R]: Warns about an empty statement after \f[CB]if\f[R]. |
|
775 |
.IP \[bu] 2 |
|
776 |
\f[CB]exports\f[R]: Warns about the issues regarding module exports. |
|
777 |
.IP \[bu] 2 |
|
778 |
\f[CB]fallthrough\f[R]: Warns about the falling through from one case of a |
|
779 |
switch statement to the next. |
|
780 |
.IP \[bu] 2 |
|
55666 | 781 |
\f[CB]finally\f[R]: Warns about \f[CB]finally\f[R] clauses that do not |
55140 | 782 |
terminate normally. |
783 |
.IP \[bu] 2 |
|
784 |
\f[CB]module\f[R]: Warns about the module system\-related issues. |
|
785 |
.IP \[bu] 2 |
|
786 |
\f[CB]opens\f[R]: Warns about the issues related to module opens. |
|
787 |
.IP \[bu] 2 |
|
788 |
\f[CB]options\f[R]: Warns about the issues relating to use of command line |
|
789 |
options. |
|
790 |
.IP \[bu] 2 |
|
791 |
\f[CB]overloads\f[R]: Warns about the issues related to method overloads. |
|
792 |
.IP \[bu] 2 |
|
793 |
\f[CB]overrides\f[R]: Warns about the issues related to method overrides. |
|
794 |
.IP \[bu] 2 |
|
795 |
\f[CB]path\f[R]: Warns about the invalid path elements on the command l |
|
796 |
ine. |
|
797 |
.IP \[bu] 2 |
|
798 |
\f[CB]processing\f[R]: Warns about the issues related to annotation |
|
799 |
processing. |
|
800 |
.IP \[bu] 2 |
|
801 |
\f[CB]rawtypes\f[R]: Warns about the use of raw types. |
|
802 |
.IP \[bu] 2 |
|
803 |
\f[CB]removal\f[R]: Warns about the use of an API that has been marked for |
|
804 |
removal. |
|
805 |
.IP \[bu] 2 |
|
806 |
\f[CB]requires\-automatic\f[R]: Warns developers about the use of |
|
807 |
automatic modules in requires clauses. |
|
808 |
.IP \[bu] 2 |
|
809 |
\f[CB]requires\-transitive\-automatic\f[R]: Warns about automatic modules |
|
810 |
in requires transitive. |
|
811 |
.IP \[bu] 2 |
|
55666 | 812 |
\f[CB]serial\f[R]: Warns about the serializable classes that do not |
55140 | 813 |
provide a serial version ID. |
814 |
Also warns about access to non\-public members from a serializable |
|
815 |
element. |
|
816 |
.IP \[bu] 2 |
|
817 |
\f[CB]static\f[R]: Warns about the accessing a static member using an |
|
818 |
instance. |
|
819 |
.IP \[bu] 2 |
|
820 |
\f[CB]try\f[R]: Warns about the issues relating to the use of try blocks ( |
|
821 |
that is, try\-with\-resources). |
|
822 |
.IP \[bu] 2 |
|
823 |
\f[CB]unchecked\f[R]: Warns about the unchecked operations. |
|
824 |
.IP \[bu] 2 |
|
825 |
\f[CB]varargs\f[R]: Warns about the potentially unsafe \f[CB]vararg\f[R] |
|
826 |
methods. |
|
827 |
.IP \[bu] 2 |
|
828 |
\f[CB]none\f[R]: Disables all warnings. |
|
829 |
.PP |
|
830 |
See \f[B]Examples of Using \-Xlint keys\f[R]. |
|
831 |
.RE |
|
832 |
.TP |
|
833 |
.B \f[CB]\-Xmaxerrs\f[R] \f[I]number\f[R] |
|
834 |
Sets the maximum number of errors to print. |
|
835 |
.RS |
|
836 |
.RE |
|
837 |
.TP |
|
838 |
.B \f[CB]\-Xmaxwarns\f[R] \f[I]number\f[R] |
|
839 |
Sets the maximum number of warnings to print. |
|
840 |
.RS |
|
841 |
.RE |
|
842 |
.TP |
|
843 |
.B \f[CB]\-Xpkginfo:\f[R][\f[CB]always\f[R], \f[CB]legacy\f[R], \f[CB]nonempty\f[R]] |
|
844 |
Specifies when and how the \f[CB]javac\f[R] command generates |
|
845 |
\f[CB]package\-info.class\f[R] files from \f[CB]package\-info.java\f[R] |
|
846 |
files using one of the following options: |
|
847 |
.RS |
|
848 |
.TP |
|
849 |
.B \f[CB]always\f[R] |
|
850 |
Generates a \f[CB]package\-info.class\f[R] file for every |
|
851 |
\f[CB]package\-info.java\f[R] file. |
|
852 |
This option may be useful if you use a build system such as Ant, which |
|
853 |
checks that each \f[CB]\&.java\f[R] file has a corresponding |
|
854 |
\f[CB]\&.class\f[R] file. |
|
855 |
.RS |
|
856 |
.RE |
|
857 |
.TP |
|
858 |
.B \f[CB]legacy\f[R] |
|
859 |
Generates a \f[CB]package\-info.class\f[R] file only if |
|
860 |
\f[CB]package\-info.java\f[R] contains annotations. |
|
55666 | 861 |
This option does not generate a \f[CB]package\-info.class\f[R] file if |
55140 | 862 |
\f[CB]package\-info.java\f[R] contains only comments. |
863 |
.RS |
|
864 |
.PP |
|
55666 | 865 |
\f[B]Note:\f[R] A \f[CB]package\-info.class\f[R] file might be generated |
866 |
but be empty if all the annotations in the \f[CB]package\-info.java\f[R] |
|
867 |
file have \f[CB]RetentionPolicy.SOURCE\f[R]. |
|
55140 | 868 |
.RE |
869 |
.TP |
|
870 |
.B \f[CB]nonempty\f[R] |
|
871 |
Generates a \f[CB]package\-info.class\f[R] file only if |
|
872 |
\f[CB]package\-info.java\f[R] contains annotations with |
|
873 |
\f[CB]RetentionPolicy.CLASS\f[R] or \f[CB]RetentionPolicy.RUNTIME\f[R]. |
|
874 |
.RS |
|
875 |
.RE |
|
876 |
.RE |
|
877 |
.TP |
|
878 |
.B \f[CB]\-Xplugin:\f[R]\f[I]name\f[R] \f[I]args\f[R] |
|
879 |
Specifies the name and optional arguments for a plug\-in to be run. |
|
55666 | 880 |
If \f[I]args\f[R] are provided, \f[I]name\f[R] and \f[I]args\f[R] should be |
881 |
quoted or otherwise escape the whitespace characters between the name |
|
882 |
and all the arguments. |
|
883 |
For details on the API for a plugin, see the API documentation for |
|
884 |
\f[B]jdk.compiler/com.sun.source.util.Plugin\f[R]. |
|
55140 | 885 |
.RS |
886 |
.RE |
|
21743 | 887 |
.TP |
55140 | 888 |
.B \f[CB]\-Xprefer:\f[R][\f[CB]source\f[R], \f[CB]newer\f[R]] |
889 |
Specifies which file to read when both a source file and class file are |
|
890 |
found for an implicitly compiled class using one of the following |
|
891 |
options. |
|
55666 | 892 |
See \f[B]Searching for Module, Package and Type Declarations\f[R]. |
55140 | 893 |
.RS |
894 |
.IP \[bu] 2 |
|
895 |
\f[CB]\-Xprefer:newer\f[R]: Reads the newer of the source or class files |
|
896 |
for a type (default). |
|
897 |
.IP \[bu] 2 |
|
898 |
\f[CB]\-Xprefer:source\f[R] : Reads the source file. |
|
899 |
Use \f[CB]\-Xprefer:source\f[R] when you want to be sure that any |
|
900 |
annotation processors can access annotations declared with a retention |
|
901 |
policy of \f[CB]SOURCE\f[R]. |
|
902 |
.RE |
|
903 |
.TP |
|
904 |
.B \f[CB]\-Xprint\f[R] |
|
905 |
Prints a textual representation of specified types for debugging |
|
906 |
purposes. |
|
55666 | 907 |
This does not perform annotation processing or compilation. |
55140 | 908 |
The format of the output could change. |
909 |
.RS |
|
910 |
.RE |
|
911 |
.TP |
|
912 |
.B \f[CB]\-XprintProcessorInfo\f[R] |
|
913 |
Prints information about which annotations a processor is asked to |
|
914 |
process. |
|
915 |
.RS |
|
916 |
.RE |
|
21743 | 917 |
.TP |
55140 | 918 |
.B \f[CB]\-XprintRounds\f[R] |
919 |
Prints information about initial and subsequent annotation processing |
|
920 |
rounds. |
|
921 |
.RS |
|
922 |
.RE |
|
923 |
.TP |
|
924 |
.B \f[CB]\-Xstdout\f[R] \f[I]filename\f[R] |
|
925 |
Sends compiler messages to the named file. |
|
926 |
By default, compiler messages go to \f[CB]System.err\f[R]. |
|
927 |
.RS |
|
928 |
.RE |
|
55666 | 929 |
.SH ENVIRONMENT VARIABLES |
930 |
.SS CLASSPATH |
|
931 |
.PP |
|
932 |
If the \f[CB]\-\-class\-path\f[R] option or any of its alternate forms are |
|
933 |
not specified, the class path will default to the value of the |
|
934 |
\f[CB]CLASSPATH\f[R] environment variable if it is set. |
|
935 |
However, it is recommended that this environment variable should |
|
936 |
\f[I]not\f[R] be set, and that the \f[CB]\-\-class\-path\f[R] option should |
|
937 |
be used to provide an explicit value for the class path when one is |
|
938 |
required. |
|
939 |
.SS JDK_JAVAC_OPTIONS |
|
940 |
.PP |
|
941 |
The content of the \f[CB]JDK_JAVAC_OPTIONS\f[R] environment variable, |
|
942 |
separated by white\-spaces ( ) or white\-space characters (\f[CB]\\n\f[R], |
|
943 |
\f[CB]\\t\f[R], \f[CB]\\r\f[R], or \f[CB]\\f\f[R]) is prepended to the command |
|
944 |
line arguments passed to \f[CB]javac\f[R] as a list of arguments. |
|
945 |
.PP |
|
946 |
The encoding requirement for the environment variable is the same as the |
|
947 |
\f[CB]javac\f[R] command line on the system. |
|
948 |
\f[CB]JDK_JAVAC_OPTIONS\f[R] environment variable content is treated in |
|
949 |
the same manner as that specified in the command line. |
|
55140 | 950 |
.PP |
55666 | 951 |
Single quotes (\f[CB]\[aq]\f[R]) or double quotes (\f[CB]"\f[R]) can be used |
952 |
to enclose arguments that contain whitespace characters. |
|
953 |
All content between the open quote and the first matching close quote |
|
954 |
are preserved by simply removing the pair of quotes. |
|
955 |
In case a matching quote is not found, the launcher will abort with an |
|
956 |
error message. |
|
957 |
\f[CB]\@\f[R]\f[I]files\f[R] are supported as they are specified in the |
|
958 |
command line. |
|
959 |
However, as in \f[CB]\@\f[R]\f[I]files\f[R], use of a wildcard is not |
|
960 |
supported. |
|
961 |
.PP |
|
962 |
\f[B]Examples of quoting arguments containing white spaces:\f[R] |
|
963 |
.RS |
|
964 |
.PP |
|
965 |
\f[CB]export\ JDK_JAVAC_OPTIONS=\[aq]\@"C:\\white\ spaces\\argfile"\[aq]\f[R] |
|
966 |
.RE |
|
967 |
.RS |
|
968 |
.PP |
|
969 |
\f[CB]export\ JDK_JAVAC_OPTIONS=\[aq]"\@C:\\white\ spaces\\argfile"\[aq]\f[R] |
|
970 |
.RE |
|
971 |
.RS |
|
972 |
.PP |
|
973 |
\f[CB]export\ JDK_JAVAC_OPTIONS=\[aq]\@C:\\"white\ spaces"\\argfile\[aq]\f[R] |
|
974 |
.RE |
|
975 |
.SH COMMAND\-LINE ARGUMENT FILES |
|
976 |
.PP |
|
977 |
An argument file can include command\-line options and source file names |
|
978 |
in any combination. |
|
55140 | 979 |
The arguments within a file can be separated by spaces or new line |
980 |
characters. |
|
981 |
If a file name contains embedded spaces, then put the whole file name in |
|
982 |
double quotation marks. |
|
983 |
.PP |
|
984 |
File names within an argument file are relative to the current |
|
985 |
directory, not to the location of the argument file. |
|
55666 | 986 |
Wildcards (\f[CB]*\f[R]) are not allowed in these lists (such as for |
987 |
specifying \f[CB]*.java\f[R]). |
|
988 |
Use of the at sign (\f[CB]\@\f[R]) to recursively interpret files is not |
|
989 |
supported. |
|
990 |
The \f[CB]\-J\f[R] options are not supported because they\[aq]re passed to |
|
991 |
the launcher, which does not support argument files. |
|
55140 | 992 |
.PP |
993 |
When executing the \f[CB]javac\f[R] command, pass in the path and name of |
|
994 |
each argument file with the at sign (\f[CB]\@\f[R]) leading character. |
|
995 |
When the \f[CB]javac\f[R] command encounters an argument beginning with |
|
996 |
the at sign (\f[CB]\@\f[R]), it expands the contents of that file into the |
|
997 |
argument list. |
|
55666 | 998 |
.SS Examples of Using javac \@filename |
21743 | 999 |
.TP |
55140 | 1000 |
.B Single Argument File |
1001 |
You could use a single argument file named \f[CB]argfile\f[R] to hold all |
|
1002 |
\f[CB]javac\f[R] arguments: |
|
1003 |
.RS |
|
1004 |
.RS |
|
1005 |
.PP |
|
1006 |
\f[CB]javac\ \@argfile\f[R] |
|
1007 |
.RE |
|
1008 |
.PP |
|
1009 |
This argument file could contain the contents of both files shown in the |
|
1010 |
following \f[B]Two Argument Files\f[R] example. |
|
1011 |
.RE |
|
1012 |
.TP |
|
1013 |
.B Two Argument Files |
|
1014 |
You can create two argument files: one for the \f[CB]javac\f[R] options |
|
1015 |
and the other for the source file names. |
|
1016 |
Note that the following lists have no line\-continuation characters. |
|
1017 |
.RS |
|
1018 |
.PP |
|
1019 |
Create a file named \f[CB]options\f[R] that contains the following: |
|
1020 |
.PP |
|
55666 | 1021 |
\f[B]Oracle Solaris, Linux, and macOS:\f[R] |
55140 | 1022 |
.IP |
1023 |
.nf |
|
1024 |
\f[CB] |
|
1025 |
\-d\ classes |
|
1026 |
\-g |
|
1027 |
\-sourcepath\ /java/pubs/ws/1.3/src/share/classes |
|
1028 |
\f[R] |
|
1029 |
.fi |
|
1030 |
.PP |
|
1031 |
\f[B]Windows:\f[R] |
|
1032 |
.IP |
|
1033 |
.nf |
|
1034 |
\f[CB] |
|
1035 |
\-d\ classes |
|
1036 |
\-g |
|
1037 |
\-sourcepath\ C:\\java\\pubs\\ws\\1.3\\src\\share\\classes |
|
1038 |
\f[R] |
|
1039 |
.fi |
|
1040 |
.PP |
|
1041 |
Create a file named \f[CB]classes\f[R] that contains the following: |
|
1042 |
.IP |
|
1043 |
.nf |
|
1044 |
\f[CB] |
|
1045 |
MyClass1.java |
|
1046 |
MyClass2.java |
|
1047 |
MyClass3.java |
|
1048 |
\f[R] |
|
1049 |
.fi |
|
1050 |
.PP |
|
1051 |
Then, run the \f[CB]javac\f[R] command as follows: |
|
1052 |
.RS |
|
1053 |
.PP |
|
1054 |
\f[CB]javac\ \@options\ \@classes\f[R] |
|
1055 |
.RE |
|
1056 |
.RE |
|
1057 |
.TP |
|
1058 |
.B Argument Files with Paths |
|
1059 |
The argument files can have paths, but any file names inside the files |
|
1060 |
are relative to the current working directory (not \f[CB]path1\f[R] or |
|
1061 |
\f[CB]path2\f[R]): |
|
1062 |
.RS |
|
1063 |
.RS |
|
1064 |
.PP |
|
1065 |
\f[CB]javac\ \@path1/options\ \@path2/classes\f[R] |
|
1066 |
.RE |
|
1067 |
.RE |
|
55666 | 1068 |
.SH ARRANGEMENT OF SOURCE CODE |
1069 |
.PP |
|
1070 |
In the Java language, classes and interfaces can be organized into |
|
1071 |
packages, and packages can be organized into modules. |
|
1072 |
\f[CB]javac\f[R] expects that the physical arrangement of source files in |
|
1073 |
directories of the file system will mirror the organization of classes |
|
1074 |
into packages, and packages into modules. |
|
1075 |
.PP |
|
1076 |
It is a widely adopted convention that module names and package names |
|
1077 |
begin with a lower\-case letter, and that class names begin with an |
|
1078 |
upper\-case letter. |
|
1079 |
.SS Arrangement of Source Code for a Package |
|
1080 |
.PP |
|
1081 |
When classes and interfaces are organized into a package, the package is |
|
1082 |
represented as a directory, and any subpackages are represented as |
|
1083 |
subdirectories. |
|
1084 |
.PP |
|
1085 |
For example: |
|
1086 |
.IP \[bu] 2 |
|
1087 |
The package \f[CB]p\f[R] is represented as a directory called \f[CB]p\f[R]. |
|
1088 |
.IP \[bu] 2 |
|
1089 |
The package \f[CB]p.q\f[R] \-\- that is, the subpackage \f[CB]q\f[R] of |
|
1090 |
package \f[CB]p\f[R] \-\- is represented as the subdirectory \f[CB]q\f[R] of |
|
1091 |
directory \f[CB]p\f[R]. |
|
1092 |
The directory tree representing package \f[CB]p.q\f[R] is therefore |
|
1093 |
\f[CB]p\\q\f[R] on Windows, and \f[CB]p/q\f[R] on other systems. |
|
1094 |
.IP \[bu] 2 |
|
1095 |
The package \f[CB]p.q.r\f[R] is represented as the directory tree |
|
1096 |
\f[CB]p\\q\\r\f[R] (on Windows) or \f[CB]p/q/r\f[R] (on other systems). |
|
1097 |
.PP |
|
1098 |
Within a directory or subdirectory, \f[CB]\&.java\f[R] files represent |
|
1099 |
classes and interfaces in the corresponding package or subpackage. |
|
1100 |
.PP |
|
1101 |
For example: |
|
1102 |
.IP \[bu] 2 |
|
1103 |
The class \f[CB]X\f[R] declared in package \f[CB]p\f[R] is represented by |
|
1104 |
the file \f[CB]X.java\f[R] in the \f[CB]p\f[R] directory. |
|
1105 |
.IP \[bu] 2 |
|
1106 |
The class \f[CB]Y\f[R] declared in package \f[CB]p.q\f[R] is represented by |
|
1107 |
the file \f[CB]Y.java\f[R] in the \f[CB]q\f[R] subdirectory of directory |
|
1108 |
\f[CB]p\f[R]. |
|
1109 |
.IP \[bu] 2 |
|
1110 |
The class \f[CB]Z\f[R] declared in package \f[CB]p.q.r\f[R] is represented |
|
1111 |
by the file \f[CB]Z.java\f[R] in the \f[CB]r\f[R] subdirectory of |
|
1112 |
\f[CB]p\\q\f[R] (on Windows) or \f[CB]p/q\f[R] (on other systems). |
|
1113 |
.PP |
|
1114 |
In some situations, it is convenient to split the code into separate |
|
1115 |
directories, each structured as described above, and the aggregate list |
|
1116 |
of directories specified to \f[CB]javac\f[R]. |
|
1117 |
.SS Arrangement of Source Code for a Module |
|
1118 |
.PP |
|
1119 |
In the Java language, a module is a set of packages designed for reuse. |
|
1120 |
In addition to \f[CB]\&.java\f[R] files for classes and interfaces, each |
|
1121 |
module has a source file called \f[CB]module\-info.java\f[R] which: |
|
1122 |
.IP "1." 3 |
|
1123 |
declares the module\[aq]s name; |
|
1124 |
.IP "2." 3 |
|
1125 |
lists the packages exported by the module (to allow reuse by other |
|
1126 |
modules); |
|
1127 |
.IP "3." 3 |
|
1128 |
lists other modules required by the module (to reuse their exported |
|
1129 |
packages). |
|
1130 |
.PP |
|
1131 |
When packages are organized into a module, the module is represented by |
|
1132 |
one or more directories representing the packages in the module, one of |
|
1133 |
which contains the \f[CB]module\-info.java\f[R] file. |
|
1134 |
It may be convenient, but it is not required, to use a single directory, |
|
1135 |
named after the module, to contain the \f[CB]module\-info.java\f[R] file |
|
1136 |
alongside the directory tree which represents the packages in the module |
|
1137 |
(i.e., the \f[I]package hierarchy\f[R] described above). |
|
1138 |
The exact arrangement of source code for a module is typically dictated |
|
1139 |
by the conventions adopted by a development environment (IDE) or build |
|
1140 |
system. |
|
1141 |
.PP |
|
1142 |
For example: |
|
1143 |
.IP \[bu] 2 |
|
1144 |
The module \f[CB]a.b.c\f[R] may be represented by the directory |
|
1145 |
\f[CB]a.b.c\f[R], on all systems. |
|
1146 |
.IP \[bu] 2 |
|
1147 |
The module\[aq]s declaration is represented by the file |
|
1148 |
\f[CB]module\-info.java\f[R] in the \f[CB]a.b.c\f[R] directory. |
|
1149 |
.IP \[bu] 2 |
|
1150 |
If the module contains package \f[CB]p.q.r\f[R], then the \f[CB]a.b.c\f[R] |
|
1151 |
directory contains the directory tree \f[CB]p\\q\\r\f[R] (on Windows) or |
|
1152 |
\f[CB]p/q/r\f[R] (on other systems). |
|
1153 |
.PP |
|
1154 |
The development environment may prescribe some directory hierarchy |
|
1155 |
between the directory named for the module and the source files to be |
|
1156 |
read by \f[CB]javac\f[R]. |
|
1157 |
.PP |
|
1158 |
For example: |
|
1159 |
.IP \[bu] 2 |
|
1160 |
The module \f[CB]a.b.c\f[R] may be represented by the directory |
|
1161 |
\f[CB]a.b.c\f[R] |
|
1162 |
.IP \[bu] 2 |
|
1163 |
The module\[aq]s declaration and the module\[aq]s packages may be in |
|
1164 |
some subdirectory of \f[CB]a.b.c\f[R], such as \f[CB]src\\main\\java\f[R] |
|
1165 |
(on Windows) or \f[CB]src/main/java\f[R] (on other systems). |
|
1166 |
.SH CONFIGURING A COMPILATION |
|
1167 |
.PP |
|
1168 |
This section describes how to configure \f[CB]javac\f[R] to perform a |
|
1169 |
basic compilation. |
|
1170 |
.PP |
|
1171 |
See \f[B]Configuring the Module System\f[R] for additional details for |
|
1172 |
use when compiling for a release of the platform that supports modules. |
|
1173 |
.SS Source Files |
|
1174 |
.IP \[bu] 2 |
|
1175 |
Specify the source files to be compiled on the command line. |
|
1176 |
.PP |
|
1177 |
If there are no compilation errors, the corresponding class files will |
|
1178 |
be placed in the \f[B]output directory\f[R]. |
|
1179 |
.PP |
|
1180 |
Some systems may limit the amount you can put on a command line; to work |
|
1181 |
around those limits, you can use \f[B]argument files\f[R]. |
|
1182 |
.PP |
|
1183 |
When compiling code for modules, you can also specify source files |
|
1184 |
indirectly, by using the \f[CB]\-\-module\f[R] or \f[CB]\-m\f[R] option; see |
|
1185 |
\f[B]Standard Options\f[R]. |
|
1186 |
.SS Output Directory |
|
1187 |
.IP \[bu] 2 |
|
1188 |
Use the \f[CB]\-d\f[R] option to specify an output directory in which to |
|
1189 |
put the compiled class files. |
|
1190 |
.PP |
|
1191 |
This will normally be organized in a \f[B]package hierarchy\f[R], unless |
|
1192 |
you are compiling source code from multiple modules, in which case it |
|
1193 |
will be organized as a \f[B]module hierarchy\f[R]. |
|
1194 |
.PP |
|
1195 |
When the compilation has been completed, if you are compiling one or |
|
1196 |
more modules, you can place the output directory on the module path for |
|
1197 |
the Java \f[B]launcher\f[R]; otherwise, you can place the place the |
|
1198 |
output directory on the class path for the Java launcher. |
|
1199 |
.SS Precompiled Code |
|
1200 |
.PP |
|
1201 |
The code to be compiled may refer to libraries beyond what is provided |
|
1202 |
by the platform. |
|
1203 |
If so, you must place these libraries on the class path or module path. |
|
1204 |
If the library code is not in a module, place it on the class path; if |
|
1205 |
it is in a module, place it on the module path. |
|
1206 |
.IP \[bu] 2 |
|
1207 |
Use the \f[CB]\-\-class\-path\f[R] option to specify libraries to be |
|
1208 |
placed on the class path. |
|
1209 |
Locations on the class path should be organized in a \f[B]package |
|
1210 |
hierarchy\f[R]. |
|
1211 |
You can also use alternate forms of the option: \f[CB]\-classpath\f[R] or |
|
1212 |
\f[CB]\-cp\f[R]. |
|
1213 |
.IP \[bu] 2 |
|
1214 |
Use the \f[CB]\-\-module\-path\f[R] option to specify libraries to be |
|
1215 |
placed on the module path. |
|
1216 |
Locations on the module path should either be modules or directories of |
|
1217 |
modules. |
|
1218 |
You can also use an alternate form of the option: \f[CB]\-p\f[R]. |
|
1219 |
.RS 2 |
|
1220 |
.PP |
|
1221 |
See \f[B]Configuring the Module System\f[R] for details on how to modify |
|
1222 |
the default configuration of library modules. |
|
1223 |
.RE |
|
1224 |
.PP |
|
1225 |
\f[B]Note\f[R]: the options for the class path and module path are not |
|
1226 |
mutually exclusive, although it is not common to specify the class path |
|
1227 |
when compiling code for one or more modules. |
|
1228 |
.SS Additional Source Files |
|
1229 |
.PP |
|
1230 |
The code to be compiled may refer to types in additional source files |
|
1231 |
that are not specified on the command line. |
|
1232 |
If so, you must put those source files on either the source path or |
|
1233 |
module path. |
|
1234 |
You can only specify one of these options: if you are not compiling code |
|
1235 |
for a module, or if you are only compiling code for a single module, use |
|
1236 |
the source path; if you are compiling code for multiple modules, use the |
|
1237 |
module source path. |
|
1238 |
.IP \[bu] 2 |
|
1239 |
Use the \f[CB]\-\-source\-path\f[R] option to specify the locations of |
|
1240 |
additional source files that may be read by javac. |
|
1241 |
Locations on the source path should be organized in a \f[B]package |
|
1242 |
hierarchy\f[R]. |
|
1243 |
You can also use an alternate form of the option: \f[CB]\-sourcepath\f[R]. |
|
1244 |
.IP \[bu] 2 |
|
1245 |
Use the \f[CB]\-\-module\-source\-path\f[R] option one or more times to |
|
1246 |
specify the location of additional source files in different modules |
|
1247 |
that may be read by javac, or when compiling source files in multiple |
|
1248 |
modules. |
|
1249 |
You can either specify the locations for each module |
|
1250 |
\f[B]individually\f[R], or you can organize the source files so that you |
|
1251 |
can specify the locations all \f[B]together\f[R]. |
|
1252 |
For more details, see \f[B]The Module Source Path Option\f[R]. |
|
1253 |
.PP |
|
1254 |
If you want to be able to refer to types in additional source files but |
|
1255 |
do not want them to be compiled, use the \f[CB]\-implicit\f[R] option. |
|
1256 |
.PP |
|
1257 |
\f[B]Note\f[R]: if you are compiling code for multiple modules, you must |
|
1258 |
always specify a module source path, and all source files specified on |
|
1259 |
the command line must be in one of the directories on the module source |
|
1260 |
path, or in a subdirectory thereof. |
|
1261 |
.SS Example of Compiling Multiple Source Files |
|
1262 |
.PP |
|
1263 |
This example compiles the \f[CB]Aloha.java\f[R], \f[CB]GutenTag.java\f[R], |
|
1264 |
\f[CB]Hello.java\f[R], and \f[CB]Hi.java\f[R] source files in the |
|
1265 |
\f[CB]greetings\f[R] package. |
|
1266 |
.PP |
|
1267 |
\f[B]Oracle Solaris, Linux, and macOS:\f[R] |
|
1268 |
.IP |
|
1269 |
.nf |
|
1270 |
\f[CB] |
|
1271 |
%\ javac\ greetings/*.java |
|
1272 |
%\ ls\ greetings |
|
1273 |
Aloha.class\ \ \ \ \ \ \ \ \ GutenTag.class\ \ \ \ \ \ Hello.class\ \ \ \ \ \ \ \ \ Hi.class |
|
1274 |
Aloha.java\ \ \ \ \ \ \ \ \ \ GutenTag.java\ \ \ \ \ \ \ Hello.java\ \ \ \ \ \ \ \ \ \ Hi.java |
|
1275 |
\f[R] |
|
1276 |
.fi |
|
1277 |
.PP |
|
1278 |
\f[B]Windows:\f[R] |
|
1279 |
.IP |
|
1280 |
.nf |
|
1281 |
\f[CB] |
|
1282 |
C:\\>javac\ greetings\\*.java |
|
1283 |
C:\\>dir\ greetings |
|
1284 |
Aloha.class\ \ \ \ \ \ \ \ \ GutenTag.class\ \ \ \ \ \ Hello.class\ \ \ \ \ \ \ \ \ Hi.class |
|
1285 |
Aloha.java\ \ \ \ \ \ \ \ \ \ GutenTag.java\ \ \ \ \ \ \ Hello.java\ \ \ \ \ \ \ \ \ \ Hi.java |
|
1286 |
\f[R] |
|
1287 |
.fi |
|
1288 |
.SS Example of Specifying a User Class Path |
|
1289 |
.PP |
|
1290 |
After changing one of the source files in the previous example, |
|
1291 |
recompile it: |
|
1292 |
.PP |
|
1293 |
\f[B]Oracle Solaris, Linux, and macOS:\f[R] |
|
1294 |
.IP |
|
1295 |
.nf |
|
1296 |
\f[CB] |
|
1297 |
pwd |
|
1298 |
/examples |
|
1299 |
javac\ greetings/Hi.java |
|
1300 |
\f[R] |
|
1301 |
.fi |
|
1302 |
.PP |
|
1303 |
\f[B]Windows:\f[R] |
|
1304 |
.IP |
|
1305 |
.nf |
|
1306 |
\f[CB] |
|
1307 |
C:\\>cd |
|
1308 |
\\examples |
|
1309 |
C:\\>javac\ greetings\\Hi.java |
|
1310 |
\f[R] |
|
1311 |
.fi |
|
1312 |
.PP |
|
1313 |
Because \f[CB]greetings.Hi\f[R] refers to other classes in the |
|
1314 |
\f[CB]greetings\f[R] package, the compiler needs to find these other |
|
1315 |
classes. |
|
1316 |
The previous example works because the default user class path is the |
|
1317 |
directory that contains the package directory. |
|
1318 |
If you want to recompile this file without concern for which directory |
|
1319 |
you are in, then add the examples directory to the user class path by |
|
1320 |
setting \f[CB]CLASSPATH\f[R]. |
|
1321 |
This example uses the \f[CB]\-classpath\f[R] option. |
|
1322 |
.PP |
|
1323 |
\f[B]Oracle Solaris, Linux, and macOS:\f[R] |
|
1324 |
.RS |
|
1325 |
.PP |
|
1326 |
\f[CB]javac\ \-classpath\ /examples\ /examples/greetings/Hi.java\f[R] |
|
1327 |
.RE |
|
1328 |
.PP |
|
1329 |
\f[B]Windows:\f[R] |
|
1330 |
.RS |
|
1331 |
.PP |
|
1332 |
\f[CB]C:\\>javac\ \-classpath\ \\examples\ \\examples\\greetings\\Hi.java\f[R] |
|
1333 |
.RE |
|
1334 |
.PP |
|
1335 |
If you change \f[CB]greetings.Hi\f[R] to use a banner utility, then that |
|
1336 |
utility also needs to be accessible through the user class path. |
|
1337 |
.PP |
|
1338 |
\f[B]Oracle Solaris, Linux, and macOS:\f[R] |
|
1339 |
.IP |
|
1340 |
.nf |
|
1341 |
\f[CB] |
|
1342 |
javac\ \-classpath\ /examples:/lib/Banners.jar\ \\ |
|
1343 |
\ \ \ \ \ \ \ \ \ \ \ \ /examples/greetings/Hi.java |
|
1344 |
\f[R] |
|
1345 |
.fi |
|
1346 |
.PP |
|
1347 |
\f[B]Windows:\f[R] |
|
1348 |
.IP |
|
1349 |
.nf |
|
1350 |
\f[CB] |
|
1351 |
C:\\>javac\ \-classpath\ \\examples;\\lib\\Banners.jar\ ^ |
|
1352 |
\ \ \ \ \ \ \ \ \ \ \ \ \\examples\\greetings\\Hi.java |
|
1353 |
\f[R] |
|
1354 |
.fi |
|
1355 |
.PP |
|
1356 |
To execute a class in the \f[CB]greetings\f[R] package, the program needs |
|
1357 |
access to the \f[CB]greetings\f[R] package, and to the classes that the |
|
1358 |
\f[CB]greetings\f[R] classes use. |
|
1359 |
.PP |
|
1360 |
\f[B]Oracle Solaris, Linux, and macOS:\f[R] |
|
1361 |
.RS |
|
1362 |
.PP |
|
1363 |
\f[CB]java\ \-classpath\ /examples:/lib/Banners.jar\ greetings.Hi\f[R] |
|
1364 |
.RE |
|
1365 |
.PP |
|
1366 |
\f[B]Windows:\f[R] |
|
1367 |
.RS |
|
1368 |
.PP |
|
1369 |
\f[CB]C:\\>java\ \-classpath\ \\examples;\\lib\\Banners.jar\ greetings.Hi\f[R] |
|
1370 |
.RE |
|
1371 |
.SH CONFIGURING THE MODULE SYSTEM |
|
1372 |
.PP |
|
1373 |
If you want to include additional modules in your compilation, use the |
|
1374 |
\f[CB]\-\-add\-modules\f[R] option. |
|
1375 |
This may be necessary when you are compiling code that is not in a |
|
1376 |
module, or which is in an automatic module, and the code refers to API |
|
1377 |
in the additional modules. |
|
1378 |
.PP |
|
1379 |
If you want to restrict the set of modules in your compilation, use the |
|
1380 |
\f[CB]\-\-limit\-modules\f[R] option. |
|
1381 |
This may be useful if you want to ensure that the code you are compiling |
|
1382 |
is capable of running on a system with a limited set of modules |
|
1383 |
installed. |
|
1384 |
.PP |
|
1385 |
If you want to break encapsulation and specify that additional packages |
|
1386 |
should be considered as exported from a module, use the |
|
1387 |
\f[CB]\-\-add\-exports\f[R] option. |
|
1388 |
This may be useful when performing white\-box testing; relying on access |
|
1389 |
to internal API in production code is strongly discouraged. |
|
1390 |
.PP |
|
1391 |
If you want to specify that additional packages should be considered as |
|
1392 |
required by a module, use the \f[CB]\-\-add\-reads\f[R] option. |
|
1393 |
This may be useful when performing white\-box testing; relying on access |
|
1394 |
to internal API in production code is strongly discouraged. |
|
1395 |
.PP |
|
1396 |
You can patch additional content into any module using the |
|
1397 |
\f[CB]\-\-patch\-module\f[R] option. |
|
1398 |
See [Patching a Module] for more details. |
|
1399 |
.SH SEARCHING FOR MODULE, PACKAGE AND TYPE DECLARATIONS |
|
1400 |
.PP |
|
1401 |
To compile a source file, the compiler often needs information about a |
|
1402 |
module or type, but the declaration is not in the source files specified |
|
1403 |
on the command line. |
|
1404 |
.PP |
|
1405 |
\f[CB]javac\f[R] needs type information for every class or interface used, |
|
1406 |
extended, or implemented in the source file. |
|
1407 |
This includes classes and interfaces not explicitly mentioned in the |
|
1408 |
source file, but that provide information through inheritance. |
|
1409 |
.PP |
|
1410 |
For example, when you create a subclass of \f[CB]java.awt.Window\f[R], you |
|
1411 |
are also using the ancestor classes of \f[CB]Window\f[R]: |
|
1412 |
\f[CB]java.awt.Container\f[R], \f[CB]java.awt.Component\f[R], and |
|
1413 |
\f[CB]java.lang.Object\f[R]. |
|
1414 |
.PP |
|
1415 |
When compiling code for a module, the compiler also needs to have |
|
1416 |
available the declaration of that module. |
|
1417 |
.PP |
|
1418 |
A successful search may produce a class file, a source file, or both. |
|
1419 |
If both are found, then you can use the \f[CB]\-Xprefer\f[R] option to |
|
1420 |
instruct the compiler which to use; see \f[B]Extra Options\f[R]. |
|
1421 |
.PP |
|
1422 |
If a search finds and uses a source file, then by default \f[CB]javac\f[R] |
|
1423 |
compiles that source file. |
|
1424 |
This behavior can be altered with \f[CB]\-implicit\f[R]; see \f[B]Standard |
|
1425 |
Options\f[R]. |
|
1426 |
.PP |
|
1427 |
The compiler might not discover the need for some type information until |
|
1428 |
after annotation processing completes. |
|
1429 |
When the type information is found in a source file and no |
|
1430 |
\f[CB]\-implicit\f[R] option is specified, the compiler gives a warning |
|
1431 |
that the file is being compiled without being subject to annotation |
|
1432 |
processing. |
|
1433 |
To disable the warning, either specify the file on the command line (so |
|
1434 |
that it will be subject to annotation processing) or use the |
|
1435 |
\f[CB]\-implicit\f[R] option to specify whether or not class files should |
|
1436 |
be generated for such source files. |
|
1437 |
.PP |
|
1438 |
The way that \f[CB]javac\f[R] locates the declarations of those types |
|
1439 |
depends on whether the reference exists within code for a module or not. |
|
1440 |
.SS Searching Package Oriented Paths |
|
1441 |
.PP |
|
1442 |
When searching for a source or class file on a path composed of package |
|
1443 |
oriented locations, \f[CB]javac\f[R] will check each location on the path |
|
1444 |
in turn for the possible presence of the file. |
|
1445 |
The first occurrence of a particular file shadows (hides) any subsequent |
|
1446 |
occurrences of like\-named files. |
|
1447 |
This shadowing does not affect any search for any files with a different |
|
1448 |
name. |
|
1449 |
This can be convenient when searching for source files, which may be |
|
1450 |
grouped in different locations, such as shared code, platform\-specific |
|
1451 |
code and generated code. |
|
1452 |
It can also be useful when injecting alternate versions of a class file |
|
1453 |
into a package, to debugging or other instrumentation reasons. |
|
1454 |
But, it can also be dangerous, such as when putting incompatible |
|
1455 |
different versions of a library on the class path. |
|
1456 |
.SS Searching Module Oriented Paths |
|
1457 |
.PP |
|
1458 |
Prior to scanning any module paths for any package or type declarations, |
|
1459 |
\f[CB]javac\f[R] will lazily scan the following paths and locations to |
|
1460 |
determine the modules that will be used in the compilation. |
|
1461 |
.IP \[bu] 2 |
|
1462 |
The module source path (see the \f[CB]\-\-module\-source\-path\f[R] |
|
1463 |
option) |
|
1464 |
.IP \[bu] 2 |
|
1465 |
The path for upgradeable modules (see the |
|
1466 |
\f[CB]\-\-upgrade\-module\-path\f[R] option) |
|
1467 |
.IP \[bu] 2 |
|
1468 |
The system modules (see the \f[CB]\-\-system\f[R] option) |
|
1469 |
.IP \[bu] 2 |
|
1470 |
The user module path ( see the \f[CB]\-\-module\-path\f[R] option) |
|
1471 |
.PP |
|
1472 |
For any module, the first occurrence of the module during the scan |
|
1473 |
completely shadows (hides) any subsequent appearance of a like\-named |
|
1474 |
module. |
|
1475 |
While locating the modules, \f[CB]javac\f[R] is able to determine the |
|
1476 |
packages exported by the module and to associate with each module a |
|
1477 |
package oriented path for the contents of the module. |
|
1478 |
For any previously compiled module, this path will typically be a single |
|
1479 |
entry for either a directory or a file that provides an internal |
|
1480 |
directory\-like hierarchy, such as a JAR file. |
|
1481 |
Thus, when searching for a type that is in a package that is known to be |
|
1482 |
exported by a module, \f[CB]javac\f[R] can locate the declaration directly |
|
1483 |
and efficiently. |
|
1484 |
.SS Searching for the Declaration of a Module |
|
1485 |
.PP |
|
1486 |
If the module has been previously compiled, the module declaration is |
|
1487 |
located in a file named \f[CB]module\-info.class\f[R] in the root of the |
|
1488 |
package hierarchy for the content of the module. |
|
1489 |
.PP |
|
1490 |
If the module is one of those currently being compiled, the module |
|
1491 |
declaration will be either the file named \f[CB]module\-info.class\f[R] in |
|
1492 |
the root of the package hierarchy for the module in the class output |
|
1493 |
directory, or the file named \f[CB]module\-info.java\f[R] in one of the |
|
1494 |
locations on the source path or one the module source path for the |
|
1495 |
module. |
|
1496 |
.SS Searching for the Declaration of a Type When the Reference is not in |
|
1497 |
a Module |
|
1498 |
.PP |
|
1499 |
When searching for a type that is referenced in code that is not in a |
|
1500 |
module, \f[CB]javac\f[R] will look in the following places: |
|
1501 |
.IP \[bu] 2 |
|
1502 |
The platform classes (or the types in exported packages of the platform |
|
1503 |
modules) (This is for compiled class files only.) |
|
1504 |
.IP \[bu] 2 |
|
1505 |
Types in exported packages of any modules on the module path, if |
|
1506 |
applicable. |
|
1507 |
(This is for compiled class files only.) |
|
1508 |
.IP \[bu] 2 |
|
1509 |
Types in packages on the class path and/or source path: |
|
1510 |
.RS 2 |
|
1511 |
.IP \[bu] 2 |
|
1512 |
If both are specified, \f[CB]javac\f[R] looks for compiled class files on |
|
1513 |
the class path and for source files on the source path. |
|
1514 |
.IP \[bu] 2 |
|
1515 |
If the class path is specified, but not source path, \f[CB]javac\f[R] |
|
1516 |
looks for both compiled class files and source files on the class path. |
|
1517 |
.IP \[bu] 2 |
|
1518 |
If the class path is not specified, it defaults to the current |
|
1519 |
directory. |
|
1520 |
.RE |
|
1521 |
.PP |
|
1522 |
When looking for a type on the class path and/or source path, if both a |
|
1523 |
compiled class file and a source file are found, the most recently |
|
1524 |
modified file will be used by default. |
|
1525 |
If the source file is newer, it will be compiled and will may override |
|
1526 |
any previously compiled version of the file. |
|
1527 |
You can use the \f[CB]\-Xprefer\f[R] option to override the default |
|
1528 |
behavior. |
|
1529 |
.SS Searching for the Declaration of a Type When the Reference is in a |
|
1530 |
Module |
|
1531 |
.PP |
|
1532 |
When searching for a type that is referenced in code in a module, |
|
1533 |
\f[CB]javac\f[R] will examine the declaration of the enclosing module to |
|
1534 |
determine if the type is in a package that is exported from another |
|
1535 |
module that is readable by the enclosing module. |
|
1536 |
If so, \f[CB]javac\f[R] will simply and directly go to the definition of |
|
1537 |
that module to find the definition of the required type. |
|
1538 |
Unless the module is another of the modules being compiled, |
|
1539 |
\f[CB]javac\f[R] will only look for compiled class files files. |
|
1540 |
In other words, \f[CB]javac\f[R] will not look for source files in |
|
1541 |
platform modules or modules on the module path. |
|
1542 |
.PP |
|
1543 |
If the type being referenced is not in some other readable module, |
|
1544 |
\f[CB]javac\f[R] will examine the module being compiled to try and find |
|
1545 |
the declaration of the type. |
|
1546 |
\f[CB]javac\f[R] will look for the declaration of the type as follows: |
|
1547 |
.IP \[bu] 2 |
|
1548 |
Source files specified on the command line or on the source path or |
|
1549 |
module source path. |
|
1550 |
.IP \[bu] 2 |
|
1551 |
Previously compiled files in the output directory. |
|
1552 |
.SH DIRECTORY HIERARCHIES |
|
1553 |
.PP |
|
1554 |
\f[CB]javac\f[R] generally assumes that source files and compiled class |
|
1555 |
files will be organized in a file system directory hierarchy or in a |
|
1556 |
type of file that supports in an internal directory hierarchy, such as a |
|
1557 |
JAR file. |
|
1558 |
Three different kinds of hierarchy are supported: a \f[I]package |
|
1559 |
hierarchy\f[R], a \f[I]module hierarchy\f[R], and a \f[I]module source |
|
1560 |
hierarchy\f[R]. |
|
1561 |
.PP |
|
1562 |
While \f[CB]javac\f[R] is fairly relaxed about the organization of source |
|
1563 |
code, beyond the expectation that source will be organized in one or |
|
1564 |
package hierarchies, and can generally accomodate organizations |
|
1565 |
prescribed by development environments and build tools, Java tools in |
|
1566 |
general, and \f[CB]javac\f[R] and the Java launcher in particular, are |
|
1567 |
more stringent regarding the organization of compiled class files, and |
|
1568 |
will be organized in package hierarchies or module hierarchies, as |
|
1569 |
appropriate. |
|
1570 |
.PP |
|
1571 |
The location of these hierarchies are specified to \f[CB]javac\f[R] with |
|
1572 |
command\-line options, whose names typically end in "path", like |
|
1573 |
\f[CB]\-\-source\-path\f[R] or \f[CB]\-\-class\-path\f[R]. |
|
1574 |
Also as a general rule, path options whose name includes the word |
|
1575 |
\f[CB]module\f[R], like \f[CB]\-\-module\-path\f[R], are used to specify |
|
1576 |
module hierarchies, although some module\-related path options allow a |
|
1577 |
package hierarchy to be specified on a per\-module basis. |
|
1578 |
All other path options are used to specify package hierarchies. |
|
1579 |
.SS Package Hierarchy |
|
1580 |
.PP |
|
1581 |
In a package hierarchy, directories and subdirectories are used to |
|
1582 |
represent the component parts of the package name, with the source file |
|
1583 |
or compiled class file for a type being stored as a file with an |
|
1584 |
extension of \f[CB]\&.java\f[R] or \f[CB]\&.class\f[R] in the most nested |
|
1585 |
directory. |
|
1586 |
.PP |
|
1587 |
For example, in a package hierarchy, the source file for a class |
|
1588 |
\f[CB]com.example.MyClass\f[R] will be stored in the file |
|
1589 |
\f[I]com/example/MyClass.java\f[R] |
|
1590 |
.SS Module Hierarchy |
|
1591 |
.PP |
|
1592 |
In a module hierarchy, the first level of directories are named for the |
|
1593 |
modules in the hierarchy; within each of those directories the contents |
|
1594 |
of the module are organized in package hierarchies. |
|
1595 |
.PP |
|
1596 |
For example, in a module hierarchy, the compiled class file for a type |
|
1597 |
called \f[CB]com.example.MyClass\f[R] in a module called |
|
1598 |
\f[CB]my.library\f[R] will be stored in |
|
1599 |
\f[I]my.library/com/example/MyClass.class\f[R]. |
|
1600 |
.PP |
|
1601 |
The various output directories used by \f[CB]javac\f[R] (the class output |
|
1602 |
directory, the source output directory, and native header output |
|
1603 |
directory) will all be organized in a module hierarchy when multiple |
|
1604 |
modules are being compiled. |
|
1605 |
.SS Module Source Hierarchy |
|
1606 |
.PP |
|
1607 |
Although the source for each individual module should always be |
|
1608 |
organized in a package hierarchy, it may be convenient to group those |
|
1609 |
hierarchies into a module source hierarchy. |
|
1610 |
This is similar to a module hierarchy, except that there may be |
|
1611 |
intervening directories between the directory for the module and the |
|
1612 |
directory that is the root of the package hierarchy for the source code |
|
1613 |
of the module. |
|
1614 |
.PP |
|
1615 |
For example, in a module source hierarchy, the source file for a type |
|
1616 |
called \f[CB]com.example.MyClass\f[R] in a module called |
|
1617 |
\f[CB]my.library\f[R] may be stored in a file such as |
|
1618 |
\f[I]my.library/src/main/java/com/example/MyClass.java\f[R]. |
|
1619 |
.SH THE MODULE SOURCE PATH OPTION |
|
1620 |
.PP |
|
1621 |
The \f[CB]\-\-module\-source\-path\f[R] option has two forms: a |
|
1622 |
\f[I]module\-specific form\f[R], in which a package path is given for |
|
1623 |
each module containing code to be compiled, and a |
|
1624 |
\f[I]module\-pattern\f[R] form, in which the source path for each module |
|
1625 |
is specified by a pattern. |
|
1626 |
The module\-specific form is generally simpler to use when only a small |
|
1627 |
number of modules are involved; the module\-pattern form may be more |
|
1628 |
convenient when the number of modules is large and the modules are |
|
1629 |
organized in a regular manner that can be described by a pattern. |
|
1630 |
.PP |
|
1631 |
Multiple instances of the \f[CB]\-\-module\-source\-path\f[R] option may |
|
1632 |
be given, each one using either the module\-pattern form or the |
|
1633 |
module\-specific form, subject to the following limitations: |
|
1634 |
.IP \[bu] 2 |
|
1635 |
the module\-pattern form may be used at most once |
|
1636 |
.IP \[bu] 2 |
|
1637 |
the module\-specific form may be used at most once for any given module |
|
1638 |
.PP |
|
1639 |
If the module\-specific form is used for any module, the associated |
|
1640 |
search path overrides any path that might otherwise have been inferred |
|
1641 |
from the module\-pattern form. |
|
1642 |
.SS Module\-specific form |
|
1643 |
.PP |
|
1644 |
The module\-specific form allows an explicit search path to be given for |
|
1645 |
any specific module. |
|
1646 |
This form is: |
|
1647 |
.IP \[bu] 2 |
|
1648 |
\f[CB]\-\-module\-source\-path\f[R] |
|
1649 |
\f[I]module\-name\f[R]\f[CB]=\f[R]\f[I]file\-path\f[R] |
|
1650 |
(\f[I]path\-separator\f[R] \f[I]file\-path\f[R])* |
|
1651 |
.PP |
|
1652 |
The path separator character is \f[CB];\f[R] on Windows, and \f[CB]:\f[R] |
|
1653 |
otherwise. |
|
1654 |
.PP |
|
1655 |
\f[B]Note:\f[R] this is similar to the form used for the |
|
1656 |
\f[CB]\-\-patch\-module\f[R] option. |
|
1657 |
.SS Module\-pattern form |
|
1658 |
.PP |
|
1659 |
The module\-pattern form allows a concise specification of the module |
|
1660 |
source path for any number of modules organized in regular manner. |
|
1661 |
.IP \[bu] 2 |
|
1662 |
\f[CB]\-\-module\-source\-path\f[R] \f[I]pattern\f[R] |
|
1663 |
.PP |
|
1664 |
The pattern is defined by the following rules, which are applied in |
|
1665 |
order: |
|
1666 |
.IP \[bu] 2 |
|
1667 |
The argument is considered to be a series of segments separated by the |
|
1668 |
path separator character (\f[CB];\f[R] on Windows, and \f[CB]:\f[R] |
|
1669 |
otherwise). |
|
1670 |
.IP \[bu] 2 |
|
1671 |
Each segment containing curly braces of the form |
|
1672 |
.RS 2 |
|
1673 |
.IP |
|
1674 |
.nf |
|
1675 |
\f[CB] |
|
1676 |
string1{alt1\ (\ ,alt2\ )*\ }\ string2 |
|
1677 |
\f[R] |
|
1678 |
.fi |
|
1679 |
.PP |
|
1680 |
is considered to be replaced by a series of segments formed by |
|
1681 |
"expanding" the braces: |
|
1682 |
.IP |
|
1683 |
.nf |
|
1684 |
\f[CB] |
|
1685 |
string1\ alt1\ string2 |
|
1686 |
string1\ alt2\ string2 |
|
1687 |
and\ so\ on... |
|
1688 |
\f[R] |
|
1689 |
.fi |
|
1690 |
.PP |
|
1691 |
The braces may be nested. |
|
1692 |
.PP |
|
1693 |
This rule is applied for all such usages of braces. |
|
1694 |
.RE |
|
1695 |
.IP \[bu] 2 |
|
1696 |
Each segment must have at most one asterisk (\f[CB]*\f[R]). |
|
1697 |
If a segment does not contain an asterisk, it is considered to be as |
|
1698 |
though the file separator character and an asterisk are appended. |
|
1699 |
.RS 2 |
|
1700 |
.PP |
|
1701 |
For any module \f[I]M\f[R], the source path for that module is formed |
|
1702 |
from the series of segments obtained by substituting the module name |
|
1703 |
\f[I]M\f[R] for the asterisk in each segment. |
|
1704 |
.PP |
|
1705 |
\f[B]Note\f[R]: in this context, the asterisk is just used as a special |
|
1706 |
marker, to denote the position in the path of the module name. |
|
1707 |
It should not be confused with the use of \f[CB]*\f[R] as a file name |
|
1708 |
wildcard character, as found on most operating systems. |
|
1709 |
.RE |
|
1710 |
.SH PATCHING MODULES |
|
1711 |
.PP |
|
1712 |
javac allows any content, whether in source or compiled form, to be |
|
1713 |
patched into any module using the \f[CB]\-\-patch\-module\f[R] option. |
|
1714 |
You may want to do this to compile alternative implementations of a |
|
1715 |
class to be patched at runtime into a JVM, or to inject additional |
|
1716 |
classes into the module, such as when testing. |
|
1717 |
.PP |
|
1718 |
The form of the option is: |
|
1719 |
.IP \[bu] 2 |
|
1720 |
\f[CB]\-\-patch\-module\f[R] |
|
1721 |
\f[I]module\-name\f[R]\f[CB]=\f[R]\f[I]file\-path\f[R] |
|
1722 |
(\f[I]path\-separator\f[R] \f[I]file\-path\f[R] )* |
|
1723 |
.PP |
|
1724 |
The path separator character is \f[CB];\f[R] on Windows, and \f[CB]:\f[R] |
|
1725 |
otherwise. |
|
1726 |
The paths given for the module must specify the root of a package |
|
1727 |
hierarchy for the contents of the module |
|
1728 |
.PP |
|
1729 |
The option may be given at most once for any given module. |
|
1730 |
Any content on the path will hide any like\-named content later in the |
|
1731 |
path and in the patched module. |
|
1732 |
.PP |
|
1733 |
When patching source code into more than one module, the |
|
1734 |
\f[CB]\-\-module\-source\-path\f[R] must also be used, so that the output |
|
1735 |
directory is organized in a module hierarchy, and capable of holding the |
|
1736 |
compiled class files for the modules being compiled. |
|
1737 |
.SH ANNOTATION PROCESSING |
|
1738 |
.PP |
|
1739 |
The \f[CB]javac\f[R] command provides direct support for annotation |
|
1740 |
processing. |
|
1741 |
.PP |
|
1742 |
The API for annotation processors is defined in the |
|
1743 |
\f[CB]javax.annotation.processing\f[R] and \f[CB]javax.lang.model\f[R] |
|
1744 |
packages and subpackages. |
|
1745 |
.SS How Annotation Processing Works |
|
1746 |
.PP |
|
1747 |
Unless annotation processing is disabled with the \f[CB]\-proc:none\f[R] |
|
1748 |
option, the compiler searches for any annotation processors that are |
|
1749 |
available. |
|
1750 |
The search path can be specified with the \f[CB]\-processorpath\f[R] |
|
1751 |
option. |
|
1752 |
If no path is specified, then the user class path is used. |
|
1753 |
Processors are located by means of service provider\-configuration files |
|
1754 |
named \f[CB]META\-INF/services/javax.annotation.processing\f[R]. |
|
1755 |
Processor on the search path. |
|
1756 |
Such files should contain the names of any annotation processors to be |
|
1757 |
used, listed one per line. |
|
1758 |
Alternatively, processors can be specified explicitly, using the |
|
1759 |
\f[CB]\-processor\f[R] option. |
|
1760 |
.PP |
|
1761 |
After scanning the source files and classes on the command line to |
|
1762 |
determine what annotations are present, the compiler queries the |
|
1763 |
processors to determine what annotations they process. |
|
1764 |
When a match is found, the processor is called. |
|
1765 |
A processor can claim the annotations it processes, in which case no |
|
1766 |
further attempt is made to find any processors for those annotations. |
|
1767 |
After all of the annotations are claimed, the compiler does not search |
|
1768 |
for additional processors. |
|
1769 |
.PP |
|
1770 |
If any processors generate new source files, then another round of |
|
1771 |
annotation processing occurs: Any newly generated source files are |
|
1772 |
scanned, and the annotations processed as before. |
|
1773 |
Any processors called on previous rounds are also called on all |
|
1774 |
subsequent rounds. |
|
1775 |
This continues until no new source files are generated. |
|
1776 |
.PP |
|
1777 |
After a round occurs where no new source files are generated, the |
|
1778 |
annotation processors are called one last time, to give them a chance to |
|
1779 |
complete any remaining work. |
|
1780 |
Finally, unless the \f[CB]\-proc:only\f[R] option is used, the compiler |
|
1781 |
compiles the original and all generated source files. |
|
1782 |
.PP |
|
1783 |
If you use an annotation processor that generates additional source |
|
1784 |
files to be included in the compilation, you can specify a default |
|
1785 |
module to be used for the newly generated files, for use when a module |
|
1786 |
declaration is not also generated. |
|
1787 |
In this case, use the \f[CB]\-\-default\-module\-for\-created\-files\f[R] |
|
1788 |
option. |
|
1789 |
.SS Compilation Environment and Runtime Environment. |
|
1790 |
.PP |
|
1791 |
The declarations in source files and previously compiled class files are |
|
1792 |
analyzed by \f[CB]javac\f[R] in a \f[I]compilation environment\f[R] that is |
|
1793 |
distinct from the \f[I]runtime environment\f[R] used to execute |
|
1794 |
\f[CB]javac\f[R] itself. |
|
1795 |
Although there is a deliberate similarity between many \f[CB]javac\f[R] |
|
1796 |
options and like\-named options for the Java \f[B]launcher\f[R], such as |
|
1797 |
\f[CB]\-\-class\-path\f[R], \f[CB]\-\-module\-path\f[R] and so on, it is |
|
1798 |
important to understand that in general the \f[CB]javac\f[R] options just |
|
1799 |
affect the environment in which the source files are compiled, and do |
|
1800 |
not affect the operation of \f[CB]javac\f[R] itself. |
|
1801 |
.PP |
|
1802 |
The distinction between the compilation environment and runtime |
|
1803 |
environment is significant when it comes to using annotation processors. |
|
1804 |
Although annotations processors process elements (declarations) that |
|
1805 |
exist in the compilation environment, the annotation processor itself is |
|
1806 |
executed in the runtime environment. |
|
1807 |
If an annotation processor has dependencies on libraries that are not in |
|
1808 |
modules, the libraries can be placed, along with the annotation |
|
1809 |
processor itself, on the processor path. |
|
1810 |
(See the \f[CB]\-\-processor\-path\f[R] option.) If the annotation |
|
1811 |
processor and its dependencies are in modules, you should use the |
|
1812 |
processor module path instead. |
|
1813 |
(See the \f[CB]\-\-processor\-module\-path\f[R] option.) When those are |
|
1814 |
insufficient, it may be necessary to provide further configuration of |
|
1815 |
the runtime environment. |
|
1816 |
This can be done in two ways: |
|
1817 |
.IP "1." 3 |
|
1818 |
If \f[CB]javac\f[R] is invoked from the command line, options can be |
|
1819 |
passed to the underlying runtime by prefixing the option with |
|
1820 |
\f[CB]\-J\f[R]. |
|
1821 |
(See the \f[CB]\-J\f[R] option.) |
|
1822 |
.IP "2." 3 |
|
1823 |
You can start an instance of a Java Virtual Machine directly and use |
|
1824 |
command line options and API to configure an environment in which |
|
1825 |
\f[CB]javac\f[R] can be invoked via one of its \f[B]APIs\f[R]. |
|
1826 |
.SH COMPILING FOR EARLIER RELEASES OF THE PLATFORM |
|
1827 |
.PP |
|
1828 |
\f[CB]javac\f[R] can compile code that is to be used on other releases of |
|
1829 |
the platform, using either the \f[CB]\-\-release\f[R] option, or the |
|
1830 |
\f[CB]\-\-source\f[R]/\f[CB]\-source\f[R] and |
|
1831 |
\f[CB]\-\-target\f[R]/\f[CB]\-target\f[R] options, together with additional |
|
1832 |
options to specify the platform classes. |
|
1833 |
.PP |
|
1834 |
Depending on the desired platform release, there are some restrictions |
|
1835 |
on some of the options that can be used. |
|
1836 |
.IP \[bu] 2 |
|
1837 |
When compiling for JDK 8 and earlier releases, you cannot use any option |
|
1838 |
that is intended for use with the module system. |
|
1839 |
This includes all of the following options: |
|
1840 |
.RS 2 |
|
1841 |
.IP \[bu] 2 |
|
1842 |
\f[CB]\-\-module\-source\-path\f[R], \f[CB]\-\-upgrade\-module\-path\f[R], |
|
1843 |
\f[CB]\-\-system\f[R], \f[CB]\-\-module\-path\f[R], |
|
1844 |
\f[CB]\-\-add\-modules\f[R], \f[CB]\-\-add\-exports\f[R], |
|
1845 |
\f[CB]\-\-add\-opens\f[R], \f[CB]\-\-add\-reads\f[R], |
|
1846 |
\f[CB]\-\-limit\-modules\f[R], \f[CB]\-\-patch\-module\f[R] |
|
1847 |
.PP |
|
1848 |
If you use the \f[CB]\-\-source\f[R]/\f[CB]\-source\f[R] or |
|
1849 |
\f[CB]\-\-target\f[R]/\f[CB]\-target\f[R] options, you should also set the |
|
1850 |
appropriate platform classes using the boot class path family of |
|
1851 |
options. |
|
1852 |
.RE |
|
1853 |
.IP \[bu] 2 |
|
1854 |
When compiling for JDK 9 and later releases, you cannot use any option |
|
1855 |
that is intended to configure the boot class path. |
|
1856 |
This includes all of the following options: |
|
1857 |
.RS 2 |
|
1858 |
.IP \[bu] 2 |
|
1859 |
\f[CB]\-Xbootclasspath/p:\f[R], \f[CB]\-Xbootclasspath\f[R], |
|
1860 |
\f[CB]\-Xbootclasspath/a:\f[R], \f[CB]\-endorseddirs\f[R], |
|
1861 |
\f[CB]\-Djava.endorsed.dirs\f[R], \f[CB]\-extdirs\f[R], |
|
1862 |
\f[CB]\-Djava.ext.dirs\f[R], \f[CB]\-profile\f[R] |
|
1863 |
.PP |
|
1864 |
If you use the \f[CB]\-\-source\f[R]/\f[CB]\-source\f[R] or |
|
1865 |
\f[CB]\-\-target\f[R]/\f[CB]\-target\f[R] options, you should also set the |
|
1866 |
appropriate platform classes using the \f[CB]\-\-system\f[R] option to |
|
1867 |
give the location of an appropriate installed release of JDK. |
|
1868 |
.RE |
|
1869 |
.PP |
|
1870 |
When using the \f[CB]\-\-release\f[R] option, only the supported |
|
1871 |
documented API for that release may be used; you cannot use any options |
|
1872 |
to break encapsulation to access any internal classes. |
|
1873 |
.SH APIS |
|
1874 |
.PP |
|
1875 |
The \f[CB]javac\f[R] compiler can be invoked using an API in three |
|
1876 |
different ways: |
|
1877 |
.TP |
|
1878 |
.B The \f[B]Java Compiler API\f[R] |
|
1879 |
This provides the most flexible way to invoke the compiler, including |
|
1880 |
the ability to compile source files provided in memory buffers or other |
|
1881 |
non\-standard file systems. |
|
1882 |
.RS |
|
1883 |
.RE |
|
1884 |
.TP |
|
1885 |
.B The \f[B]ToolProvider API\f[R] |
|
1886 |
A \f[CB]ToolProvider\f[R] for \f[CB]javac\f[R] can be obtained by calling |
|
1887 |
\f[CB]ToolProvider.findFirst("javac")\f[R]. |
|
1888 |
This returns an object with the equivalent functionality of the |
|
1889 |
command\-line tool. |
|
1890 |
.RS |
|
1891 |
.PP |
|
1892 |
\f[B]Note\f[R]: This API should not be confused with the like\-named API |
|
1893 |
in the \f[B]\f[BC]javax.tools\f[B]\f[R] package. |
|
1894 |
.RE |
|
1895 |
.TP |
|
1896 |
.B The \f[CB]javac\f[R] \f[B]Legacy API\f[R] |
|
1897 |
This API is retained for backward compatibility only. |
|
1898 |
All new code should use either the Java Compiler API or the ToolProvider |
|
1899 |
API. |
|
1900 |
.RS |
|
1901 |
.RE |
|
1902 |
.PP |
|
1903 |
\f[B]Note:\f[R] All other classes and methods found in a package with |
|
1904 |
names that start with \f[CB]com.sun.tools.javac\f[R] (subpackages of |
|
1905 |
\f[CB]com.sun.tools.javac\f[R]) are strictly internal and subject to |
|
1906 |
change at any time. |
|
55140 | 1907 |
.SH EXAMPLES OF USING \-XLINT KEYS |
1908 |
.TP |
|
1909 |
.B \f[CB]cast\f[R] |
|
21743 | 1910 |
Warns about unnecessary and redundant casts, for example: |
55140 | 1911 |
.RS |
1912 |
.RS |
|
1913 |
.PP |
|
1914 |
\f[CB]String\ s\ =\ (String)\ "Hello!"\f[R] |
|
1915 |
.RE |
|
1916 |
.RE |
|
1917 |
.TP |
|
1918 |
.B \f[CB]classfile\f[R] |
|
1919 |
Warns about issues related to class file contents. |
|
1920 |
.RS |
|
1921 |
.RE |
|
1922 |
.TP |
|
1923 |
.B \f[CB]deprecation\f[R] |
|
1924 |
Warns about the use of deprecated items. |
|
1925 |
For example: |
|
1926 |
.RS |
|
1927 |
.IP |
|
1928 |
.nf |
|
1929 |
\f[CB] |
|
1930 |
java.util.Date\ myDate\ =\ new\ java.util.Date(); |
|
1931 |
int\ currentDay\ =\ myDate.getDay(); |
|
1932 |
\f[R] |
|
1933 |
.fi |
|
1934 |
.PP |
|
1935 |
The method \f[CB]java.util.Date.getDay\f[R] has been deprecated since JDK |
|
1936 |
1.1. |
|
1937 |
.RE |
|
1938 |
.TP |
|
1939 |
.B \f[CB]dep\-ann\f[R] |
|
1940 |
Warns about items that are documented with the \f[CB]\@deprecated\f[R] |
|
55666 | 1941 |
Javadoc comment, but do not have the \f[CB]\@Deprecated\f[R] annotation, |
1942 |
for example: |
|
55140 | 1943 |
.RS |
1944 |
.IP |
|
1945 |
.nf |
|
1946 |
\f[CB] |
|
1947 |
/** |
|
1948 |
\ \ *\ \@deprecated\ As\ of\ Java\ SE\ 7,\ replaced\ by\ {\@link\ #newMethod()} |
|
1949 |
\ \ */ |
|
1950 |
public\ static\ void\ deprecatedMethod()\ {\ } |
|
1951 |
public\ static\ void\ newMethod()\ {\ } |
|
1952 |
\f[R] |
|
1953 |
.fi |
|
1954 |
.RE |
|
1955 |
.TP |
|
1956 |
.B \f[CB]divzero\f[R] |
|
21743 | 1957 |
Warns about division by the constant integer 0, for example: |
55140 | 1958 |
.RS |
1959 |
.RS |
|
1960 |
.PP |
|
1961 |
\f[CB]int\ divideByZero\ =\ 42\ /\ 0;\f[R] |
|
1962 |
.RE |
|
1963 |
.RE |
|
1964 |
.TP |
|
1965 |
.B \f[CB]empty\f[R] |
|
1966 |
Warns about empty statements after \f[CB]if\f[R]statements, for example: |
|
1967 |
.RS |
|
1968 |
.IP |
|
1969 |
.nf |
|
1970 |
\f[CB] |
|
1971 |
class\ E\ { |
|
1972 |
\ \ \ \ void\ m()\ { |
|
1973 |
\ \ \ \ \ \ \ \ \ if\ (true)\ ; |
|
1974 |
\ \ \ \ } |
|
1975 |
} |
|
1976 |
\f[R] |
|
1977 |
.fi |
|
1978 |
.RE |
|
1979 |
.TP |
|
1980 |
.B \f[CB]fallthrough\f[R] |
|
1981 |
Checks the switch blocks for fall\-through cases and provides a warning |
|
1982 |
message for any that are found. |
|
1983 |
Fall\-through cases are cases in a switch block, other than the last |
|
55666 | 1984 |
case in the block, whose code does not include a \f[CB]break\f[R] |
1985 |
statement, allowing code execution to fall through from that case to the |
|
1986 |
next case. |
|
55140 | 1987 |
For example, the code following the case 1 label in this switch block |
55666 | 1988 |
does not end with a \f[CB]break\f[R] statement: |
55140 | 1989 |
.RS |
1990 |
.IP |
|
1991 |
.nf |
|
1992 |
\f[CB] |
|
1993 |
switch\ (x)\ { |
|
1994 |
case\ 1: |
|
1995 |
\ \ System.out.println("1"); |
|
1996 |
\ \ //\ No\ break\ statement\ here. |
|
1997 |
case\ 2: |
|
1998 |
\ \ System.out.println("2"); |
|
1999 |
} |
|
2000 |
\f[R] |
|
2001 |
.fi |
|
2002 |
.PP |
|
2003 |
If the \f[CB]\-Xlint:fallthrough\f[R] option was used when compiling this |
|
2004 |
code, then the compiler emits a warning about possible fall\-through |
|
2005 |
into case, with the line number of the case in question. |
|
2006 |
.RE |
|
2007 |
.TP |
|
2008 |
.B \f[CB]finally\f[R] |
|
55666 | 2009 |
Warns about \f[CB]finally\f[R] clauses that cannot be completed normally, |
2010 |
for example: |
|
55140 | 2011 |
.RS |
2012 |
.IP |
|
2013 |
.nf |
|
2014 |
\f[CB] |
|
2015 |
public\ static\ int\ m()\ { |
|
2016 |
\ \ try\ { |
|
2017 |
\ \ \ \ \ throw\ new\ NullPointerException(); |
|
2018 |
\ \ }\ \ catch\ (NullPointerException();\ { |
|
2019 |
\ \ \ \ \ System.err.println("Caught\ NullPointerException."); |
|
2020 |
\ \ \ \ \ return\ 1; |
|
2021 |
\ \ \ }\ finally\ { |
|
2022 |
\ \ \ \ \ return\ 0; |
|
2023 |
\ \ \ } |
|
2024 |
\ \ } |
|
2025 |
\f[R] |
|
2026 |
.fi |
|
2027 |
.PP |
|
2028 |
The compiler generates a warning for the \f[CB]finally\f[R] block in this |
|
2029 |
example. |
|
2030 |
When the \f[CB]int\f[R] method is called, it returns a value of 0. |
|
2031 |
A \f[CB]finally\f[R] block executes when the \f[CB]try\f[R] block exits. |
|
2032 |
In this example, when control is transferred to the \f[CB]catch\f[R] |
|
2033 |
block, the \f[CB]int\f[R] method exits. |
|
2034 |
However, the \f[CB]finally\f[R] block must execute, so it\[aq]s executed, |
|
2035 |
even though control was transferred outside the method. |
|
2036 |
.RE |
|
2037 |
.TP |
|
2038 |
.B \f[CB]options\f[R] |
|
2039 |
Warns about issues that related to the use of command\-line options. |
|
55666 | 2040 |
See \f[B]Compiling for Earlier Releases of the Platform\f[R]. |
55140 | 2041 |
.RS |
2042 |
.RE |
|
2043 |
.TP |
|
2044 |
.B \f[CB]overrides\f[R] |
|
2045 |
Warns about issues related to method overrides. |
|
2046 |
For example, consider the following two classes: |
|
2047 |
.RS |
|
2048 |
.IP |
|
2049 |
.nf |
|
2050 |
\f[CB] |
|
2051 |
public\ class\ ClassWithVarargsMethod\ { |
|
2052 |
\ \ void\ varargsMethod(String...\ s)\ {\ } |
|
2053 |
} |
|
21743 | 2054 |
|
55140 | 2055 |
public\ class\ ClassWithOverridingMethod\ extends\ ClassWithVarargsMethod\ { |
2056 |
\ \ \ \@Override |
|
2057 |
\ \ \ void\ varargsMethod(String[]\ s)\ {\ } |
|
2058 |
} |
|
2059 |
\f[R] |
|
2060 |
.fi |
|
2061 |
.PP |
|
2062 |
The compiler generates a warning similar to the following:. |
|
2063 |
.IP |
|
2064 |
.nf |
|
2065 |
\f[CB] |
|
2066 |
warning:\ [override]\ varargsMethod(String[])\ in\ ClassWithOverridingMethod |
|
2067 |
overrides\ varargsMethod(String...)\ in\ ClassWithVarargsMethod;\ overriding |
|
2068 |
method\ is\ missing\ \[aq]...\[aq] |
|
2069 |
\f[R] |
|
2070 |
.fi |
|
2071 |
.PP |
|
2072 |
When the compiler encounters a \f[CB]varargs\f[R] method, it translates |
|
2073 |
the \f[CB]varargs\f[R] formal parameter into an array. |
|
2074 |
In the method \f[CB]ClassWithVarargsMethod.varargsMethod\f[R], the |
|
2075 |
compiler translates the \f[CB]varargs\f[R] formal parameter |
|
2076 |
\f[CB]String...\ s\f[R] to the formal parameter \f[CB]String[]\ s\f[R], an |
|
2077 |
array that matches the formal parameter of the method |
|
2078 |
\f[CB]ClassWithOverridingMethod.varargsMethod\f[R]. |
|
2079 |
Consequently, this example compiles. |
|
2080 |
.RE |
|
2081 |
.TP |
|
2082 |
.B \f[CB]path\f[R] |
|
2083 |
Warns about invalid path elements and nonexistent path directories on |
|
2084 |
the command line (with regard to the class path, the source path, and |
|
2085 |
other paths). |
|
55666 | 2086 |
Such warnings cannot be suppressed with the \f[CB]\@SuppressWarnings\f[R] |
2087 |
annotation. |
|
55140 | 2088 |
For example: |
2089 |
.RS |
|
2090 |
.IP \[bu] 2 |
|
55666 | 2091 |
\f[B]Oracle Solaris, Linux, and macOS:\f[R] |
55140 | 2092 |
\f[CB]javac\ \-Xlint:path\ \-classpath\ /nonexistentpath\ Example.java\f[R] |
2093 |
.IP \[bu] 2 |
|
2094 |
\f[B]Windows:\f[R] |
|
2095 |
\f[CB]javac\ \-Xlint:path\ \-classpath\ C:\\nonexistentpath\ Example.java\f[R] |
|
2096 |
.RE |
|
2097 |
.TP |
|
2098 |
.B \f[CB]processing\f[R] |
|
2099 |
Warns about issues related to annotation processing. |
|
2100 |
The compiler generates this warning when you have a class that has an |
|
55666 | 2101 |
annotation, and you use an annotation processor that cannot handle that |
2102 |
type of exception. |
|
55140 | 2103 |
For example, the following is a simple annotation processor: |
2104 |
.RS |
|
2105 |
.PP |
|
2106 |
\f[B]Source file AnnocProc.java\f[R]: |
|
2107 |
.IP |
|
2108 |
.nf |
|
2109 |
\f[CB] |
|
2110 |
import\ java.util.*; |
|
2111 |
import\ javax.annotation.processing.*; |
|
2112 |
import\ javax.lang.model.*; |
|
2113 |
import\ javaz.lang.model.element.*; |
|
21743 | 2114 |
|
55140 | 2115 |
\@SupportedAnnotationTypes("NotAnno") |
2116 |
public\ class\ AnnoProc\ extends\ AbstractProcessor\ { |
|
2117 |
\ \ public\ boolean\ process(Set<?\ extends\ TypeElement>\ elems,\ RoundEnvironment\ renv){ |
|
2118 |
\ \ \ \ \ return\ true; |
|
2119 |
\ \ } |
|
21743 | 2120 |
|
55140 | 2121 |
\ \ public\ SourceVersion\ getSupportedSourceVersion()\ { |
2122 |
\ \ \ \ \ return\ SourceVersion.latest(); |
|
2123 |
\ \ \ } |
|
2124 |
} |
|
2125 |
\f[R] |
|
2126 |
.fi |
|
2127 |
.PP |
|
2128 |
\f[B]Source file AnnosWithoutProcessors.java\f[R]: |
|
2129 |
.IP |
|
2130 |
.nf |
|
2131 |
\f[CB] |
|
2132 |
\@interface\ Anno\ {\ } |
|
12047 | 2133 |
|
55140 | 2134 |
\@Anno |
2135 |
class\ AnnosWithoutProcessors\ {\ } |
|
2136 |
\f[R] |
|
2137 |
.fi |
|
2138 |
.PP |
|
2139 |
The following commands compile the annotation processor |
|
2140 |
\f[CB]AnnoProc\f[R], then run this annotation processor against the source |
|
2141 |
file \f[CB]AnnosWithoutProcessors.java\f[R]: |
|
2142 |
.IP |
|
2143 |
.nf |
|
2144 |
\f[CB] |
|
2145 |
javac\ AnnoProc.java |
|
2146 |
javac\ \-cp\ .\ \-Xlint:processing\ \-processor\ AnnoProc\ \-proc:only\ AnnosWithoutProcessors.java |
|
2147 |
\f[R] |
|
2148 |
.fi |
|
2149 |
.PP |
|
2150 |
When the compiler runs the annotation processor against the source file |
|
2151 |
\f[CB]AnnosWithoutProcessors.java\f[R], it generates the following |
|
2152 |
warning: |
|
2153 |
.IP |
|
2154 |
.nf |
|
2155 |
\f[CB] |
|
2156 |
warning:\ [processing]\ No\ processor\ claimed\ any\ of\ these\ annotations:\ Anno |
|
2157 |
\f[R] |
|
2158 |
.fi |
|
2159 |
.PP |
|
2160 |
To resolve this issue, you can rename the annotation defined and used in |
|
2161 |
the class \f[CB]AnnosWithoutProcessors\f[R] from \f[CB]Anno\f[R] to |
|
2162 |
\f[CB]NotAnno\f[R]. |
|
2163 |
.RE |
|
2164 |
.TP |
|
2165 |
.B \f[CB]rawtypes\f[R] |
|
2166 |
Warns about unchecked operations on raw types. |
|
2167 |
The following statement generates a \f[CB]rawtypes\f[R] warning: |
|
2168 |
.RS |
|
2169 |
.RS |
|
2170 |
.PP |
|
2171 |
\f[CB]void\ countElements(List\ l)\ {\ ...\ }\f[R] |
|
2172 |
.RE |
|
2173 |
.PP |
|
55666 | 2174 |
The following example does not generate a \f[CB]rawtypes\f[R] warning: |
55140 | 2175 |
.RS |
2176 |
.PP |
|
2177 |
\f[CB]void\ countElements(List<?>\ l)\ {\ ...\ }\f[R] |
|
2178 |
.RE |
|
2179 |
.PP |
|
2180 |
\f[CB]List\f[R] is a raw type. |
|
2181 |
However, \f[CB]List<?>\f[R] is an unbounded wildcard parameterized type. |
|
2182 |
Because \f[CB]List\f[R] is a parameterized interface, always specify its |
|
2183 |
type argument. |
|
2184 |
In this example, the \f[CB]List\f[R] formal argument is specified with an |
|
2185 |
unbounded wildcard (\f[CB]?\f[R]) as its formal type parameter, which |
|
2186 |
means that the \f[CB]countElements\f[R] method can accept any |
|
2187 |
instantiation of the \f[CB]List\f[R] interface. |
|
2188 |
.RE |
|
2189 |
.TP |
|
2190 |
.B \f[CB]serial\f[R] |
|
2191 |
Warns about missing \f[CB]serialVersionUID\f[R] definitions on |
|
2192 |
serializable classes. |
|
2193 |
For example: |
|
2194 |
.RS |
|
2195 |
.IP |
|
2196 |
.nf |
|
2197 |
\f[CB] |
|
2198 |
public\ class\ PersistentTime\ implements\ Serializable |
|
2199 |
{ |
|
2200 |
\ \ private\ Date\ time; |
|
21743 | 2201 |
|
55140 | 2202 |
\ \ \ public\ PersistentTime()\ { |
2203 |
\ \ \ \ \ time\ =\ Calendar.getInstance().getTime(); |
|
2204 |
\ \ \ } |
|
21743 | 2205 |
|
55140 | 2206 |
\ \ \ public\ Date\ getTime()\ { |
2207 |
\ \ \ \ \ return\ time; |
|
2208 |
\ \ \ } |
|
2209 |
} |
|
2210 |
\f[R] |
|
2211 |
.fi |
|
2212 |
.PP |
|
2213 |
The compiler generates the following warning: |
|
2214 |
.IP |
|
2215 |
.nf |
|
2216 |
\f[CB] |
|
2217 |
warning:\ [serial]\ serializable\ class\ PersistentTime\ has\ no\ definition\ of |
|
2218 |
serialVersionUID |
|
2219 |
\f[R] |
|
2220 |
.fi |
|
2221 |
.PP |
|
55666 | 2222 |
If a serializable class does not explicitly declare a field named |
55140 | 2223 |
\f[CB]serialVersionUID\f[R], then the serialization runtime environment |
2224 |
calculates a default \f[CB]serialVersionUID\f[R] value for that class |
|
2225 |
based on various aspects of the class, as described in the Java Object |
|
2226 |
Serialization Specification. |
|
2227 |
However, it\[aq]s strongly recommended that all serializable classes |
|
2228 |
explicitly declare \f[CB]serialVersionUID\f[R] values because the default |
|
2229 |
process of computing \f[CB]serialVersionUID\f[R] values is highly |
|
2230 |
sensitive to class details that can vary depending on compiler |
|
2231 |
implementations. |
|
2232 |
As a result, this might cause an unexpected |
|
2233 |
\f[CB]InvalidClassExceptions\f[R] during deserialization. |
|
2234 |
To guarantee a consistent \f[CB]serialVersionUID\f[R] value across |
|
2235 |
different Java compiler implementations, a serializable class must |
|
2236 |
declare an explicit \f[CB]serialVersionUID\f[R] value. |
|
2237 |
.RE |
|
2238 |
.TP |
|
2239 |
.B \f[CB]static\f[R] |
|
55666 | 2240 |
Warns about issues relating to the use of static variables, for example: |
55140 | 2241 |
.RS |
2242 |
.IP |
|
2243 |
.nf |
|
2244 |
\f[CB] |
|
2245 |
class\ XLintStatic\ { |
|
2246 |
\ \ \ \ static\ void\ m1()\ {\ } |
|
2247 |
\ \ \ \ void\ m2()\ {\ this.m1();\ } |
|
2248 |
} |
|
2249 |
\f[R] |
|
2250 |
.fi |
|
2251 |
.PP |
|
2252 |
The compiler generates the following warning: |
|
2253 |
.IP |
|
2254 |
.nf |
|
2255 |
\f[CB] |
|
2256 |
warning:\ [static]\ static\ method\ should\ be\ qualified\ by\ type\ name, |
|
2257 |
XLintStatic,\ instead\ of\ by\ an\ expression |
|
2258 |
\f[R] |
|
2259 |
.fi |
|
2260 |
.PP |
|
2261 |
To resolve this issue, you can call the \f[CB]static\f[R] method |
|
2262 |
\f[CB]m1\f[R] as follows: |
|
2263 |
.RS |
|
2264 |
.PP |
|
2265 |
\f[CB]XLintStatic.m1();\f[R] |
|
2266 |
.RE |
|
21743 | 2267 |
.PP |
55140 | 2268 |
Alternately, you can remove the \f[CB]static\f[R] keyword from the |
2269 |
declaration of the method \f[CB]m1\f[R]. |
|
2270 |
.RE |
|
2271 |
.TP |
|
2272 |
.B \f[CB]try\f[R] |
|
2273 |
Warns about issues relating to the use of \f[CB]try\f[R] blocks, including |
|
2274 |
try\-with\-resources statements. |
|
2275 |
For example, a warning is generated for the following statement because |
|
55666 | 2276 |
the resource \f[CB]ac\f[R] declared in the \f[CB]try\f[R] block is not used: |
55140 | 2277 |
.RS |
2278 |
.IP |
|
2279 |
.nf |
|
2280 |
\f[CB] |
|
2281 |
try\ (\ AutoCloseable\ ac\ =\ getResource()\ )\ {\ \ \ \ //\ do\ nothing} |
|
2282 |
\f[R] |
|
2283 |
.fi |
|
2284 |
.RE |
|
2285 |
.TP |
|
2286 |
.B \f[CB]unchecked\f[R] |
|
2287 |
Gives more detail for unchecked conversion warnings that are mandated by |
|
2288 |
the Java Language Specification, for example: |
|
2289 |
.RS |
|
2290 |
.IP |
|
2291 |
.nf |
|
2292 |
\f[CB] |
|
2293 |
List\ l\ =\ new\ ArrayList<Number>(); |
|
2294 |
List<String>\ ls\ =\ l;\ \ \ \ \ \ \ //\ unchecked\ warning |
|
2295 |
\f[R] |
|
2296 |
.fi |
|
21743 | 2297 |
.PP |
55140 | 2298 |
During type erasure, the types \f[CB]ArrayList<Number>\f[R] and |
2299 |
\f[CB]List<String>\f[R] become \f[CB]ArrayList\f[R] and \f[CB]List\f[R], |
|
2300 |
respectively. |
|
21743 | 2301 |
.PP |
55140 | 2302 |
The \f[CB]ls\f[R] command has the parameterized type |
2303 |
\f[CB]List<String>\f[R]. |
|
2304 |
When the \f[CB]List\f[R] referenced by \f[CB]l\f[R] is assigned to |
|
2305 |
\f[CB]ls\f[R], the compiler generates an unchecked warning. |
|
55666 | 2306 |
At compile time, the compiler and JVM cannot determine whether |
55140 | 2307 |
\f[CB]l\f[R] refers to a \f[CB]List<String>\f[R] type. |
55666 | 2308 |
In this case, \f[CB]l\f[R] does not refer to a \f[CB]List<String>\f[R] type. |
55140 | 2309 |
As a result, heap pollution occurs. |
21743 | 2310 |
.PP |
55140 | 2311 |
A heap pollution situation occurs when the \f[CB]List\f[R] object |
2312 |
\f[CB]l\f[R], whose static type is \f[CB]List<Number>\f[R], is assigned to |
|
2313 |
another \f[CB]List\f[R] object, \f[CB]ls\f[R], that has a different static |
|
2314 |
type, \f[CB]List<String>\f[R]. |
|
2315 |
However, the compiler still allows this assignment. |
|
2316 |
It must allow this assignment to preserve backward compatibility with |
|
55666 | 2317 |
releases of Java SE that do not support generics. |
55140 | 2318 |
Because of type erasure, \f[CB]List<Number>\f[R] and \f[CB]List<String>\f[R] |
2319 |
both become \f[CB]List\f[R]. |
|
2320 |
Consequently, the compiler allows the assignment of the object |
|
2321 |
\f[CB]l\f[R], which has a raw type of \f[CB]List\f[R], to the object |
|
2322 |
\f[CB]ls\f[R]. |
|
2323 |
.RE |
|
2324 |
.TP |
|
2325 |
.B \f[CB]varargs\f[R] |
|
2326 |
Warns about unsafe use of variable arguments (\f[CB]varargs\f[R]) methods, |
|
2327 |
in particular, those that contain non\-reifiable arguments, for example: |
|
2328 |
.RS |
|
2329 |
.IP |
|
2330 |
.nf |
|
2331 |
\f[CB] |
|
2332 |
public\ class\ ArrayBuilder\ { |
|
2333 |
\ \ public\ static\ <T>\ void\ addToList\ (List<T>\ listArg,\ T...\ elements)\ { |
|
2334 |
\ \ \ \ for\ (T\ x\ :\ elements)\ { |
|
2335 |
\ \ \ \ \ \ listArg.add(x); |
|
2336 |
\ \ \ \ } |
|
2337 |
\ \ } |
|
2338 |
} |
|
2339 |
\f[R] |
|
2340 |
.fi |
|
21743 | 2341 |
.PP |
55666 | 2342 |
A non\-reifiable type is a type whose type information is not fully |
55140 | 2343 |
available at runtime. |
2344 |
.PP |
|
2345 |
The compiler generates the following warning for the definition of the |
|
2346 |
method \f[CB]ArrayBuilder.addToList\f[R]: |
|
2347 |
.IP |
|
2348 |
.nf |
|
2349 |
\f[CB] |
|
2350 |
warning:\ [varargs]\ Possible\ heap\ pollution\ from\ parameterized\ vararg\ type\ T |
|
2351 |
\f[R] |
|
2352 |
.fi |
|
21743 | 2353 |
.PP |
55140 | 2354 |
When the compiler encounters a varargs method, it translates the |
2355 |
\f[CB]varargs\f[R] formal parameter into an array. |
|
55666 | 2356 |
However, the Java programming language does not permit the creation of |
2357 |
arrays of parameterized types. |
|
55140 | 2358 |
In the method \f[CB]ArrayBuilder.addToList\f[R], the compiler translates |
2359 |
the \f[CB]varargs\f[R] formal parameter \f[CB]T...\f[R] elements to the |
|
2360 |
formal parameter \f[CB]T[]\f[R] elements, an array. |
|
2361 |
However, because of type erasure, the compiler converts the |
|
2362 |
\f[CB]varargs\f[R] formal parameter to \f[CB]Object[]\f[R] elements. |
|
2363 |
Consequently, there\[aq]s a possibility of heap pollution. |
|
2364 |
.RE |