blob: a3d55e275d5ba0d5794e533943cff5708cc20c9f [file] [log] [blame]
rgallardb6435452013-11-25 20:19:02 -08001'\" t
rgallard36ba8532014-06-06 15:45:48 -07002.\" Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved.
3.\"
4.\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.\"
6.\" This code is free software; you can redistribute it and/or modify it
7.\" under the terms of the GNU General Public License version 2 only, as
8.\" published by the Free Software Foundation.
9.\"
10.\" This code is distributed in the hope that it will be useful, but WITHOUT
11.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13.\" version 2 for more details (a copy is included in the LICENSE file that
14.\" accompanied this code).
15.\"
16.\" You should have received a copy of the GNU General Public License version
17.\" 2 along with this work; if not, write to the Free Software Foundation,
18.\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19.\"
20.\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21.\" or visit www.oracle.com if you need additional information or have any
22.\" questions.
23.\"
24.\" Title: javac
25.\" Language: English
26.\" Date: 8 August 2014
27.\" SectDesc: Basic Tools
28.\" Software: JDK 8
29.\" Arch: generic
30.\" Part Number: E38207-03
rgallardb6435452013-11-25 20:19:02 -080031.\"
32.if n .pl 99999
rgallard36ba8532014-06-06 15:45:48 -070033.TH "javac" "1" "8 August 2014" "JDK 8" "Basic Tools"
34.\" -----------------------------------------------------------------
35.\" * Define some portability stuff
36.\" -----------------------------------------------------------------
37.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38.\" http://bugs.debian.org/507673
39.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
40.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41.ie \n(.g .ds Aq \(aq
42.el .ds Aq '
43.\" -----------------------------------------------------------------
44.\" * set default formatting
45.\" -----------------------------------------------------------------
46.\" disable hyphenation
47.nh
48.\" disable justification (adjust text to left margin only)
49.ad l
50.\" -----------------------------------------------------------------
51.\" * MAIN CONTENT STARTS HERE *
52.\" -----------------------------------------------------------------
53.SH "NAME"
rgallardb6435452013-11-25 20:19:02 -080054javac \- Reads Java class and interface definitions and compiles them into bytecode and class files\&.
rgallard36ba8532014-06-06 15:45:48 -070055.SH "SYNOPSIS"
56.sp
57.if n \{\
58.RS 4
59.\}
60.nf
rgallardb6435452013-11-25 20:19:02 -080061\fBjavac\fR [ \fIoptions\fR ] [ \fIsourcefiles\fR ] [ \fIclasses\fR] [ \fI@argfiles\fR ]
rgallard36ba8532014-06-06 15:45:48 -070062.fi
63.if n \{\
64.RE
65.\}
66.PP
rgallardb6435452013-11-25 20:19:02 -080067Arguments can be in any order:
rgallard36ba8532014-06-06 15:45:48 -070068.PP
rgallardb6435452013-11-25 20:19:02 -080069\fIoptions\fR
rgallard36ba8532014-06-06 15:45:48 -070070.RS 4
71Command\-line options\&. See Options\&.
72.RE
73.PP
rgallardb6435452013-11-25 20:19:02 -080074\fIsourcefiles\fR
rgallard36ba8532014-06-06 15:45:48 -070075.RS 4
76One or more source files to be compiled (such as
77\fBMyClass\&.java\fR)\&.
78.RE
79.PP
rgallardb6435452013-11-25 20:19:02 -080080\fIclasses\fR
rgallard36ba8532014-06-06 15:45:48 -070081.RS 4
82One or more classes to be processed for annotations (such as
83\fBMyPackage\&.MyClass\fR)\&.
84.RE
85.PP
rgallardb6435452013-11-25 20:19:02 -080086\fI@argfiles\fR
rgallard36ba8532014-06-06 15:45:48 -070087.RS 4
88One or more files that list options and source files\&. The
89\fB\-J\fR
90options are not allowed in these files\&. See Command\-Line Argument Files\&.
91.RE
92.SH "DESCRIPTION"
rgallardb6435452013-11-25 20:19:02 -080093.PP
rgallard36ba8532014-06-06 15:45:48 -070094The
95\fBjavac\fR
96command reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files\&. The
97\fBjavac\fR
98command can also process annotations in Java source files and classes\&.
99.PP
100There are two ways to pass source code file names to
101\fBjavac\fR\&.
102.sp
103.RS 4
104.ie n \{\
105\h'-04'\(bu\h'+03'\c
106.\}
107.el \{\
108.sp -1
109.IP \(bu 2.3
110.\}
rgallardb6435452013-11-25 20:19:02 -0800111For a small number of source files, list the file names on the command line\&.
rgallard36ba8532014-06-06 15:45:48 -0700112.RE
113.sp
114.RS 4
115.ie n \{\
116\h'-04'\(bu\h'+03'\c
117.\}
118.el \{\
119.sp -1
120.IP \(bu 2.3
121.\}
122For a large number of source files, list the file names in a file that is separated by blanks or line breaks\&. Use the list file name preceded by an at sign (@) with the
123\fBjavac\fR
124command\&.
125.RE
rgallardb6435452013-11-25 20:19:02 -0800126.PP
rgallard36ba8532014-06-06 15:45:48 -0700127Source code file names must have \&.java suffixes, class file names must have \&.class suffixes, and both source and class files must have root names that identify the class\&. For example, a class called
128\fBMyClass\fR
129would be written in a source file called
130\fBMyClass\&.java\fR
131and compiled into a bytecode class file called
132\fBMyClass\&.class\fR\&.
rgallardb6435452013-11-25 20:19:02 -0800133.PP
rgallard36ba8532014-06-06 15:45:48 -0700134Inner class definitions produce additional class files\&. These class files have names that combine the inner and outer class names, such as
135\fBMyClass$MyInnerClass\&.class\fR\&.
rgallardb6435452013-11-25 20:19:02 -0800136.PP
rgallard36ba8532014-06-06 15:45:48 -0700137Arrange source files in a directory tree that reflects their package tree\&. For example, if all of your source files are in
138\fB/workspace\fR, then put the source code for
139\fBcom\&.mysoft\&.mypack\&.MyClass\fR
140in
141\fB/workspace/com/mysoft/mypack/MyClass\&.java\fR\&.
rgallardb6435452013-11-25 20:19:02 -0800142.PP
rgallard36ba8532014-06-06 15:45:48 -0700143By default, the compiler puts each class file in the same directory as its source file\&. You can specify a separate destination directory with the
144\fB\-d\fR
145option\&.
146.SH "OPTIONS"
147.PP
148The compiler has a set of standard options that are supported on the current development environment\&. An additional set of nonstandard options are specific to the current virtual machine and compiler implementations and are subject to change in the future\&. Nonstandard options begin with the
149\fB\-X\fR
150option\&.
151.sp
152.RS 4
153.ie n \{\
154\h'-04'\(bu\h'+03'\c
155.\}
156.el \{\
157.sp -1
158.IP \(bu 2.3
159.\}
160See also Cross\-Compilation Options
161.RE
162.sp
163.RS 4
164.ie n \{\
165\h'-04'\(bu\h'+03'\c
166.\}
167.el \{\
168.sp -1
169.IP \(bu 2.3
170.\}
rgallardb6435452013-11-25 20:19:02 -0800171See also Nonstandard Options
rgallard36ba8532014-06-06 15:45:48 -0700172.RE
173.SS "Standard Options"
174.PP
175\-A\fIkey\fR[\fI=value\fR]
176.RS 4
177Specifies options to pass to annotation processors\&. These options are not interpreted by
178\fBjavac\fR
179directly, but are made available for use by individual processors\&. The
180\fBkey\fR
181value should be one or more identifiers separated by a dot (\&.)\&.
182.RE
183.PP
184\-cp \fIpath\fR or \-classpath \fIpath\fR
185.RS 4
186Specifies where to find user class files, and (optionally) annotation processors and source files\&. This class path overrides the user class path in the
187\fBCLASSPATH\fR
188environment variable\&. If neither
189\fBCLASSPATH\fR,
190\fB\-cp\fR
191nor
192\fB\-classpath\fR
193is specified, then the user
194\fIclass path\fR
195is the current directory\&. See Setting the Class Path \&.
196.sp
197If the
198\fB\-sourcepath\fR
199option is not specified, then the user class path is also searched for source files\&.
200.sp
201If the
202\fB\-processorpath\fR
203option is not specified, then the class path is also searched for annotation processors\&.
204.RE
205.PP
206\-Djava\&.ext\&.dirs=\fIdirectories\fR
207.RS 4
rgallardb6435452013-11-25 20:19:02 -0800208Overrides the location of installed extensions\&.
rgallard36ba8532014-06-06 15:45:48 -0700209.RE
210.PP
211\-Djava\&.endorsed\&.dirs=\fIdirectories\fR
212.RS 4
rgallardb6435452013-11-25 20:19:02 -0800213Overrides the location of the endorsed standards path\&.
rgallard36ba8532014-06-06 15:45:48 -0700214.RE
215.PP
216\-d \fIdirectory\fR
217.RS 4
218Sets the destination directory for class files\&. The directory must already exist because
219\fBjavac\fR
220does not create it\&. If a class is part of a package, then
221\fBjavac\fR
222puts the class file in a subdirectory that reflects the package name and creates directories as needed\&.
223.sp
224If you specify
225\fB\-d\fR
226\fB/home/myclasses\fR
227and the class is called
228\fBcom\&.mypackage\&.MyClass\fR, then the class file is
229\fB/home/myclasses/com/mypackage/MyClass\&.class\fR\&.
230.sp
231If the
232\fI\-d\fR
233option is not specified, then
234\fBjavac\fR
235puts each class file in the same directory as the source file from which it was generated\&.
236.sp
237\fBNote:\fR
238The directory specified by the
239\fI\-d\fR
240option is not automatically added to your user class path\&.
241.RE
242.PP
243\-deprecation
244.RS 4
245Shows a description of each use or override of a deprecated member or class\&. Without the
246\fB\-deprecation\fR
247option,
248\fBjavac\fR
249shows a summary of the source files that use or override deprecated members or classes\&. The
250\fB\-deprecation\fR
251option is shorthand for
252\fB\-Xlint:deprecation\fR\&.
253.RE
254.PP
255\-encoding \fIencoding\fR
256.RS 4
257Sets the source file encoding name, such as EUC\-JP and UTF\-8\&. If the
258\fB\-encoding\fR
259option is not specified, then the platform default converter is used\&.
260.RE
261.PP
262\-endorseddirs \fIdirectories\fR
263.RS 4
rgallardb6435452013-11-25 20:19:02 -0800264Overrides the location of the endorsed standards path\&.
rgallard36ba8532014-06-06 15:45:48 -0700265.RE
266.PP
267\-extdirs \fIdirectories\fR
268.RS 4
269Overrides the location of the
270\fBext\fR
271directory\&. The directories variable is a colon\-separated list of directories\&. Each JAR file in the specified directories is searched for class files\&. All JAR files found become part of the class path\&.
272.sp
273If you are cross\-compiling (compiling classes against bootstrap and extension classes of a different Java platform implementation), then this option specifies the directories that contain the extension classes\&. See Cross\-Compilation Options for more information\&.
274.RE
275.PP
276\-g
277.RS 4
rgallardb6435452013-11-25 20:19:02 -0800278Generates all debugging information, including local variables\&. By default, only line number and source file information is generated\&.
rgallard36ba8532014-06-06 15:45:48 -0700279.RE
280.PP
281\-g:none
282.RS 4
rgallardb6435452013-11-25 20:19:02 -0800283Does not generate any debugging information\&.
rgallard36ba8532014-06-06 15:45:48 -0700284.RE
285.PP
286\-g:[\fIkeyword list\fR]
287.RS 4
rgallardb6435452013-11-25 20:19:02 -0800288Generates only some kinds of debugging information, specified by a comma separated list of keywords\&. Valid keywords are:
rgallard36ba8532014-06-06 15:45:48 -0700289.PP
michaelm5ac8c152012-03-06 20:34:38 +0000290source
rgallard36ba8532014-06-06 15:45:48 -0700291.RS 4
rgallardb6435452013-11-25 20:19:02 -0800292Source file debugging information\&.
rgallard36ba8532014-06-06 15:45:48 -0700293.RE
294.PP
michaelm5ac8c152012-03-06 20:34:38 +0000295lines
rgallard36ba8532014-06-06 15:45:48 -0700296.RS 4
rgallardb6435452013-11-25 20:19:02 -0800297Line number debugging information\&.
rgallard36ba8532014-06-06 15:45:48 -0700298.RE
299.PP
michaelm5ac8c152012-03-06 20:34:38 +0000300vars
rgallard36ba8532014-06-06 15:45:48 -0700301.RS 4
rgallardb6435452013-11-25 20:19:02 -0800302Local variable debugging information\&.
rgallard36ba8532014-06-06 15:45:48 -0700303.RE
304.RE
305.PP
306\-help
307.RS 4
rgallardb6435452013-11-25 20:19:02 -0800308Prints a synopsis of standard options\&.
rgallard36ba8532014-06-06 15:45:48 -0700309.RE
310.PP
311\-implicit:[\fIclass, none\fR]
312.RS 4
313Controls the generation of class files for implicitly loaded source files\&. To automatically generate class files, use
314\fB\-implicit:class\fR\&. To suppress class file generation, use
315\fB\-implicit:none\fR\&. If this option is not specified, then the default is to automatically generate class files\&. In this case, the compiler issues a warning if any such class files are generated when also doing annotation processing\&. The warning is not issued when the
316\fB\-implicit\fR
317option is set explicitly\&. See Searching for Types\&.
318.RE
319.PP
320\-J\fIoption\fR
321.RS 4
322Passes
323\fBoption\fR
324to the Java Virtual Machine (JVM), where option is one of the options described on the reference page for the Java launcher\&. For example,
325\fB\-J\-Xms48m\fR
326sets the startup memory to 48 MB\&. See
327java(1)\&.
328.sp
329\fBNote:\fR
330The
331\fICLASSPATH\fR,
332\fB\-classpath\fR,
333\fB\-bootclasspath\fR, and
334\fB\-extdirs\fR
335options do not specify the classes used to run
336\fBjavac\fR\&. Trying to customize the compiler implementation with these options and variables is risky and often does not accomplish what you want\&. If you must customize the complier implementation, then use the
337\fB\-J\fR
338option to pass options through to the underlying Java launcher\&.
339.RE
340.PP
341\-nowarn
342.RS 4
343Disables warning messages\&. This option operates the same as the
344\fB\-Xlint:none\fR
345option\&.
346.RE
347.PP
348\-parameters
349.RS 4
350Stores formal parameter names of constructors and methods in the generated class file so that the method
351\fBjava\&.lang\&.reflect\&.Executable\&.getParameters\fR
352from the Reflection API can retrieve them\&.
353.RE
354.PP
355\-proc: [\fInone\fR, \fIonly\fR]
356.RS 4
357Controls whether annotation processing and compilation are done\&.
358\fB\-proc:none\fR
359means that compilation takes place without annotation processing\&.
360\fB\-proc:only\fR
361means that only annotation processing is done, without any subsequent compilation\&.
362.RE
363.PP
364\-processor \fIclass1\fR [,\fIclass2\fR,\fIclass3\fR\&.\&.\&.]
365.RS 4
rgallardb6435452013-11-25 20:19:02 -0800366Names of the annotation processors to run\&. This bypasses the default discovery process\&.
rgallard36ba8532014-06-06 15:45:48 -0700367.RE
368.PP
369\-processorpath \fIpath\fR
370.RS 4
rgallardb6435452013-11-25 20:19:02 -0800371Specifies where to find annotation processors\&. If this option is not used, then the class path is searched for processors\&.
rgallard36ba8532014-06-06 15:45:48 -0700372.RE
373.PP
374\-s \fIdir\fR
375.RS 4
376Specifies the directory where to place the generated source files\&. The directory must already exist because
377\fBjavac\fR
378does not create it\&. If a class is part of a package, then the compiler puts the source file in a subdirectory that reflects the package name and creates directories as needed\&.
379.sp
380If you specify
381\fB\-s /home/mysrc\fR
382and the class is called
383\fBcom\&.mypackage\&.MyClass\fR, then the source file is put in
384\fB/home/mysrc/com/mypackage/MyClass\&.java\fR\&.
385.RE
386.PP
387\-source \fIrelease\fR
388.RS 4
389Specifies the version of source code accepted\&. The following values for
390\fBrelease\fR
391are allowed:
392.PP
rgallardb6435452013-11-25 20:19:02 -08003931\&.3
rgallard36ba8532014-06-06 15:45:48 -0700394.RS 4
rgallardb6435452013-11-25 20:19:02 -0800395The compiler does not support assertions, generics, or other language features introduced after Java SE 1\&.3\&.
rgallard36ba8532014-06-06 15:45:48 -0700396.RE
397.PP
rgallardb6435452013-11-25 20:19:02 -08003981\&.4
rgallard36ba8532014-06-06 15:45:48 -0700399.RS 4
rgallardb6435452013-11-25 20:19:02 -0800400The compiler accepts code containing assertions, which were introduced in Java SE 1\&.4\&.
rgallard36ba8532014-06-06 15:45:48 -0700401.RE
402.PP
rgallardb6435452013-11-25 20:19:02 -08004031\&.5
rgallard36ba8532014-06-06 15:45:48 -0700404.RS 4
rgallardb6435452013-11-25 20:19:02 -0800405The compiler accepts code containing generics and other language features introduced in Java SE 5\&.
rgallard36ba8532014-06-06 15:45:48 -0700406.RE
407.PP
michaelm5ac8c152012-03-06 20:34:38 +00004085
rgallard36ba8532014-06-06 15:45:48 -0700409.RS 4
rgallardb6435452013-11-25 20:19:02 -0800410Synonym for 1\&.5\&.
rgallard36ba8532014-06-06 15:45:48 -0700411.RE
412.PP
rgallardb6435452013-11-25 20:19:02 -08004131\&.6
rgallard36ba8532014-06-06 15:45:48 -0700414.RS 4
rgallardb6435452013-11-25 20:19:02 -0800415No language changes were introduced in Java SE 6\&. However, encoding errors in source files are now reported as errors instead of warnings as in earlier releases of Java Platform, Standard Edition\&.
rgallard36ba8532014-06-06 15:45:48 -0700416.RE
417.PP
michaelm5ac8c152012-03-06 20:34:38 +00004186
rgallard36ba8532014-06-06 15:45:48 -0700419.RS 4
rgallardb6435452013-11-25 20:19:02 -0800420Synonym for 1\&.6\&.
rgallard36ba8532014-06-06 15:45:48 -0700421.RE
422.PP
rgallardb6435452013-11-25 20:19:02 -08004231\&.7
rgallard36ba8532014-06-06 15:45:48 -0700424.RS 4
425The compiler accepts code with features introduced in Java SE 7\&.
426.RE
427.PP
michaelm5ac8c152012-03-06 20:34:38 +00004287
rgallard36ba8532014-06-06 15:45:48 -0700429.RS 4
rgallardb6435452013-11-25 20:19:02 -0800430Synonym for 1\&.7\&.
rgallard36ba8532014-06-06 15:45:48 -0700431.RE
432.PP
4331\&.8
434.RS 4
435This is the default value\&. The compiler accepts code with features introduced in Java SE 8\&.
436.RE
437.PP
4388
439.RS 4
440Synonym for 1\&.8\&.
441.RE
442.RE
443.PP
444\-sourcepath \fIsourcepath\fR
445.RS 4
rgallardb6435452013-11-25 20:19:02 -0800446Specifies the source code path to search for class or interface definitions\&. As with the user class path, source path entries are separated by colons (:) on Oracle Solaris and semicolons on Windows and can be directories, JAR archives, or ZIP archives\&. If packages are used, then the local path name within the directory or archive must reflect the package name\&.
rgallard36ba8532014-06-06 15:45:48 -0700447.sp
448\fBNote:\fR
449Classes found through the class path might be recompiled when their source files are also found\&. See Searching for Types\&.
450.RE
451.PP
452\-verbose
453.RS 4
rgallardb6435452013-11-25 20:19:02 -0800454Uses verbose output, which includes information about each class loaded and each source file compiled\&.
rgallard36ba8532014-06-06 15:45:48 -0700455.RE
456.PP
457\-version
458.RS 4
rgallardb6435452013-11-25 20:19:02 -0800459Prints release information\&.
rgallard36ba8532014-06-06 15:45:48 -0700460.RE
461.PP
462\-werror
463.RS 4
rgallardb6435452013-11-25 20:19:02 -0800464Terminates compilation when warnings occur\&.
rgallard36ba8532014-06-06 15:45:48 -0700465.RE
466.PP
467\-X
468.RS 4
rgallardb6435452013-11-25 20:19:02 -0800469Displays information about nonstandard options and exits\&.
rgallard36ba8532014-06-06 15:45:48 -0700470.RE
471.SS "Cross\-Compilation Options"
rgallardb6435452013-11-25 20:19:02 -0800472.PP
rgallard36ba8532014-06-06 15:45:48 -0700473By default, classes are compiled against the bootstrap and extension classes of the platform that
474\fBjavac\fR
475shipped with\&. But
476\fBjavac\fR
477also supports cross\-compiling, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation\&. It is important to use the
478\fB\-bootclasspath\fR
479and
480\fB\-extdirs\fR
481options when cross\-compiling\&.
482.PP
483\-target \fIversion\fR
484.RS 4
485Generates class files that target a specified release of the virtual machine\&. Class files will run on the specified target and on later releases, but not on earlier releases of the JVM\&. Valid targets are 1\&.1, 1\&.2, 1\&.3, 1\&.4, 1\&.5 (also 5), 1\&.6 (also 6), 1\&.7 (also 7), and 1\&.8 (also 8)\&.
486.sp
487The default for the
488\fB\-target\fR
489option depends on the value of the
490\fB\-source\fR
491option:
492.sp
493.RS 4
494.ie n \{\
495\h'-04'\(bu\h'+03'\c
496.\}
497.el \{\
498.sp -1
499.IP \(bu 2.3
500.\}
501If the
502\fB\-source\fR
503option is not specified, then the value of the
504\fB\-target\fR
505option is 1\&.8
506.RE
507.sp
508.RS 4
509.ie n \{\
510\h'-04'\(bu\h'+03'\c
511.\}
512.el \{\
513.sp -1
514.IP \(bu 2.3
515.\}
516If the
517\fB\-source\fR
518option is 1\&.2, then the value of the
519\fB\-target\fR
520option is 1\&.4
521.RE
522.sp
523.RS 4
524.ie n \{\
525\h'-04'\(bu\h'+03'\c
526.\}
527.el \{\
528.sp -1
529.IP \(bu 2.3
530.\}
531If the
532\fB\-source\fR
533option is 1\&.3, then the value of the
534\fB\-target\fR
535option is 1\&.4
536.RE
537.sp
538.RS 4
539.ie n \{\
540\h'-04'\(bu\h'+03'\c
541.\}
542.el \{\
543.sp -1
544.IP \(bu 2.3
545.\}
546If the
547\fB\-source\fR
548option is 1\&.5, then the value of the
549\fB\-target\fR
550option is 1\&.8
551.RE
552.sp
553.RS 4
554.ie n \{\
555\h'-04'\(bu\h'+03'\c
556.\}
557.el \{\
558.sp -1
559.IP \(bu 2.3
560.\}
561If the
562\fB\-source\fR
563option is 1\&.6, then the value of the
564\fB\-target\fR
565is option 1\&.8
566.RE
567.sp
568.RS 4
569.ie n \{\
570\h'-04'\(bu\h'+03'\c
571.\}
572.el \{\
573.sp -1
574.IP \(bu 2.3
575.\}
576If the
577\fB\-source\fR
578option is 1\&.7, then the value of the
579\fB\-target\fR
580is option 1\&.8
581.RE
582.sp
583.RS 4
584.ie n \{\
585\h'-04'\(bu\h'+03'\c
586.\}
587.el \{\
588.sp -1
589.IP \(bu 2.3
590.\}
591For all other values of the
592\fB\-source\fR
593option, the value of the
594\fB\-target\fR
595option is the value of the
596\fB\-source\fR
597option\&.
598.RE
599.RE
600.PP
601\-bootclasspath \fIbootclasspath\fR
602.RS 4
603Cross\-compiles against the specified set of boot classes\&. As with the user class path, boot class path entries are separated by colons (:) and can be directories, JAR archives, or ZIP archives\&.
604.RE
605.SS "Compact Profile Option"
606.PP
607Beginning with JDK 8, the
608\fBjavac\fR
609compiler supports compact profiles\&. With compact profiles, applications that do not require the entire Java platform can be deployed and run with a smaller footprint\&. The compact profiles feature could be used to shorten the download time for applications from app stores\&. This feature makes for more compact deployment of Java applications that bundle the JRE\&. This feature is also useful in small devices\&.
610.PP
611The supported profile values are
612\fBcompact1\fR,
613\fBcompact2\fR, and
614\fBcompact3\fR\&. These are additive layers\&. Each higher\-numbered compact profile contains all of the APIs in profiles with smaller number names\&.
615.PP
616\-profile
617.RS 4
rgallardb6435452013-11-25 20:19:02 -0800618When using compact profiles, this option specifies the profile name when compiling\&. For example:
rgallard36ba8532014-06-06 15:45:48 -0700619.sp
620.if n \{\
621.RS 4
622.\}
623.nf
624\fBjavac \-profile compact1 Hello\&.java\fR
625
626.fi
627.if n \{\
628.RE
629.\}
rgallardb6435452013-11-25 20:19:02 -0800630javac does not compile source code that uses any Java SE APIs that is not in the specified profile\&. Here is an example of the error message that results from attempting to compile such source code:
rgallard36ba8532014-06-06 15:45:48 -0700631.sp
632.if n \{\
633.RS 4
634.\}
635.nf
636\fBcd jdk1\&.8\&.0/bin\fR
637\fB\&./javac \-profile compact1 Paint\&.java\fR
638\fBPaint\&.java:5: error: Applet is not available in profile \*(Aqcompact1\*(Aq\fR
639\fBimport java\&.applet\&.Applet;\fR
640
641.fi
642.if n \{\
643.RE
644.\}
645In this example, you can correct the error by modifying the source to not use the
646\fBApplet\fR
647class\&. You could also correct the error by compiling without the \-profile option\&. Then the compilation would be run against the full set of Java SE APIs\&. (None of the compact profiles include the
648\fBApplet\fR
649class\&.)
650.sp
651An alternative way to compile with compact profiles is to use the
652\fB\-bootclasspath\fR
653option to specify a path to an
654\fBrt\&.jar\fR
655file that specifies a profile\*(Aqs image\&. Using the
656\fB\-profile\fR
657option instead does not require a profile image to be present on the system at compile time\&. This is useful when cross\-compiling\&.
658.RE
659.SS "Nonstandard Options"
660.PP
661\-Xbootclasspath/p:\fIpath\fR
662.RS 4
rgallardb6435452013-11-25 20:19:02 -0800663Adds a suffix to the bootstrap class path\&.
rgallard36ba8532014-06-06 15:45:48 -0700664.RE
665.PP
666\-Xbootclasspath/a:\fIpath\fR
667.RS 4
rgallardb6435452013-11-25 20:19:02 -0800668Adds a prefix to the bootstrap class path\&.
rgallard36ba8532014-06-06 15:45:48 -0700669.RE
670.PP
671\-Xbootclasspath/:\fIpath\fR
672.RS 4
rgallardb6435452013-11-25 20:19:02 -0800673Overrides the location of the bootstrap class files\&.
rgallard36ba8532014-06-06 15:45:48 -0700674.RE
675.PP
676\-Xdoclint:[\-]\fIgroup\fR [\fI/access\fR]
677.RS 4
678Enables or disables specific groups of checks, where
679\fIgroup\fR
680is one of the following values:
681\fBaccessibility\fR,
682\fBsyntax\fR,
683\fBreference\fR,
684\fBhtml\fR
685or
686\fBmissing\fR\&. For more information about these groups of checks see the
687\fB\-Xdoclint\fR
688option of the
689\fBjavadoc\fR
690command\&. The
691\fB\-Xdoclint\fR
692option is disabled by default in the
693\fBjavac\fR
694command\&.
695.sp
696The variable
697\fIaccess\fR
698specifies the minimum visibility level of classes and members that the
699\fB\-Xdoclint\fR
700option checks\&. It can have one of the following values (in order of most to least visible) :
701\fBpublic\fR,
702\fBprotected\fR,
703\fBpackage\fR
704and
705\fBprivate\fR\&. For example, the following option checks classes and members (with all groups of checks) that have the access level protected and higher (which includes protected, package and public):
706.sp
707.if n \{\
708.RS 4
709.\}
710.nf
711\fB\-Xdoclint:all/protected\fR
712
713.fi
714.if n \{\
715.RE
716.\}
rgallardb6435452013-11-25 20:19:02 -0800717The following option enables all groups of checks for all access levels, except it will not check for HTML errors for classes and members that have access level package and higher (which includes package and public):
rgallard36ba8532014-06-06 15:45:48 -0700718.sp
719.if n \{\
720.RS 4
721.\}
722.nf
723\fB\-Xdoclint:all,\-html/package\fR
724
725.fi
726.if n \{\
727.RE
728.\}
729.RE
730.PP
731\-Xdoclint:none
732.RS 4
rgallardb6435452013-11-25 20:19:02 -0800733Disables all groups of checks\&.
rgallard36ba8532014-06-06 15:45:48 -0700734.RE
735.PP
736\-Xdoclint:all[\fI/access\fR]
737.RS 4
rgallardb6435452013-11-25 20:19:02 -0800738Enables all groups of checks\&.
rgallard36ba8532014-06-06 15:45:48 -0700739.RE
740.PP
741\-Xlint
742.RS 4
743Enables all recommended warnings\&. In this release, enabling all available warnings is recommended\&.
744.RE
745.PP
746\-Xlint:all
747.RS 4
748Enables all recommended warnings\&. In this release, enabling all available warnings is recommended\&.
749.RE
750.PP
751\-Xlint:none
752.RS 4
rgallardb6435452013-11-25 20:19:02 -0800753Disables all warnings\&.
rgallard36ba8532014-06-06 15:45:48 -0700754.RE
755.PP
756\-Xlint:\fIname\fR
757.RS 4
758Disables warning name\&. See Enable or Disable Warnings with the \-Xlint Option for a list of warnings you can disable with this option\&.
759.RE
760.PP
761\-Xlint:\fI\-name\fR
762.RS 4
763Disables warning name\&. See Enable or Disable Warnings with the \-Xlint Option with the
764\fB\-Xlint\fR
765option to get a list of warnings that you can disable with this option\&.
766.RE
767.PP
768\-Xmaxerrs \fInumber\fR
769.RS 4
rgallardb6435452013-11-25 20:19:02 -0800770Sets the maximum number of errors to print\&.
rgallard36ba8532014-06-06 15:45:48 -0700771.RE
772.PP
773\-Xmaxwarns \fInumber\fR
774.RS 4
rgallardb6435452013-11-25 20:19:02 -0800775Sets the maximum number of warnings to print\&.
rgallard36ba8532014-06-06 15:45:48 -0700776.RE
777.PP
778\-Xstdout \fIfilename\fR
779.RS 4
780Sends compiler messages to the named file\&. By default, compiler messages go to
781\fBSystem\&.err\fR\&.
782.RE
783.PP
784\-Xprefer:[\fInewer,source\fR]
785.RS 4
786Specifies which file to read when both a source file and class file are found for a type\&. (See Searching for Types)\&. If the
787\fB\-Xprefer:newer\fR
788option is used, then it reads the newer of the source or class file for a type (default)\&. If the
789\fB\-Xprefer:source\fR
790option is used, then it reads the source file\&. Use \-\fBXprefer:source\fR
791when you want to be sure that any annotation processors can access annotations declared with a retention policy of
792\fBSOURCE\fR\&.
793.RE
794.PP
795\-Xpkginfo:[\fIalways\fR,\fIlegacy\fR,\fInonempty\fR]
796.RS 4
797Control whether javac generates
798\fBpackage\-info\&.class\fR
799files from package\-info\&.java files\&. Possible mode arguments for this option include the following\&.
800.PP
rgallardb6435452013-11-25 20:19:02 -0800801always
rgallard36ba8532014-06-06 15:45:48 -0700802.RS 4
803Always generate a
804\fBpackage\-info\&.class\fR
805file for every
806\fBpackage\-info\&.java\fR
807file\&. This option may be useful if you use a build system such as Ant, which checks that each
808\fB\&.java\fR
809file has a corresponding
810\fB\&.class\fR
811file\&.
812.RE
813.PP
rgallardb6435452013-11-25 20:19:02 -0800814legacy
rgallard36ba8532014-06-06 15:45:48 -0700815.RS 4
816Generate a
817\fBpackage\-info\&.class\fR
818file only if package\-info\&.java contains annotations\&. Don\*(Aqt generate a
819\fBpackage\-info\&.class\fR
820file if package\-info\&.java only contains comments\&.
821.sp
822\fBNote:\fR
823A
824\fBpackage\-info\&.class\fR
825file might be generated but be empty if all the annotations in the package\-info\&.java file have
826\fBRetentionPolicy\&.SOURCE\fR\&.
827.RE
828.PP
rgallardb6435452013-11-25 20:19:02 -0800829nonempty
rgallard36ba8532014-06-06 15:45:48 -0700830.RS 4
831Generate a
832\fBpackage\-info\&.class\fR
833file only if package\-info\&.java contains annotations with
834\fBRetentionPolicy\&.CLASS\fR
835or
836\fBRetentionPolicy\&.RUNTIME\fR\&.
837.RE
838.RE
839.PP
840\-Xprint
841.RS 4
rgallardb6435452013-11-25 20:19:02 -0800842Prints a textual representation of specified types for debugging purposes\&. Perform neither annotation processing nor compilation\&. The format of the output could change\&.
rgallard36ba8532014-06-06 15:45:48 -0700843.RE
844.PP
845\-XprintProcessorInfo
846.RS 4
rgallardb6435452013-11-25 20:19:02 -0800847Prints information about which annotations a processor is asked to process\&.
rgallard36ba8532014-06-06 15:45:48 -0700848.RE
849.PP
850\-XprintRounds
851.RS 4
rgallardb6435452013-11-25 20:19:02 -0800852Prints information about initial and subsequent annotation processing rounds\&.
rgallard36ba8532014-06-06 15:45:48 -0700853.RE
854.SH "ENABLE OR DISABLE WARNINGS WITH THE -XLINT OPTION"
855.PP
856Enable warning
857\fIname\fR
858with the
859\fB\-Xlint:name\fR
860option, where
861\fBname\fR
862is one of the following warning names\&. Note that you can disable a warning with the
863\fB\-Xlint:\-name:\fR
864option\&.
865.PP
michaelm5ac8c152012-03-06 20:34:38 +0000866cast
rgallard36ba8532014-06-06 15:45:48 -0700867.RS 4
rgallardb6435452013-11-25 20:19:02 -0800868Warns about unnecessary and redundant casts, for example:
rgallard36ba8532014-06-06 15:45:48 -0700869.sp
870.if n \{\
871.RS 4
872.\}
873.nf
874\fBString s = (String) "Hello!"\fR
875
876.fi
877.if n \{\
878.RE
879.\}
880.RE
881.PP
michaelm5ac8c152012-03-06 20:34:38 +0000882classfile
rgallard36ba8532014-06-06 15:45:48 -0700883.RS 4
rgallardb6435452013-11-25 20:19:02 -0800884Warns about issues related to class file contents\&.
rgallard36ba8532014-06-06 15:45:48 -0700885.RE
886.PP
michaelm5ac8c152012-03-06 20:34:38 +0000887deprecation
rgallard36ba8532014-06-06 15:45:48 -0700888.RS 4
rgallardb6435452013-11-25 20:19:02 -0800889Warns about the use of deprecated items, for example:
rgallard36ba8532014-06-06 15:45:48 -0700890.sp
891.if n \{\
892.RS 4
893.\}
894.nf
895\fBjava\&.util\&.Date myDate = new java\&.util\&.Date();\fR
896\fBint currentDay = myDate\&.getDay();\fR
897
898.fi
899.if n \{\
900.RE
901.\}
902The method
903\fBjava\&.util\&.Date\&.getDay\fR
904has been deprecated since JDK 1\&.1
905.RE
906.PP
907dep\-ann
908.RS 4
909Warns about items that are documented with an
910\fB@deprecated\fR
911Javadoc comment, but do not have a
912\fB@Deprecated\fR
913annotation, for example:
914.sp
915.if n \{\
916.RS 4
917.\}
918.nf
919\fB/**\fR
920\fB * @deprecated As of Java SE 7, replaced by {@link #newMethod()}\fR
921\fB */\fR
922\fBpublic static void deprecatedMethood() { }\fR
923\fBpublic static void newMethod() { }\fR
924
925.fi
926.if n \{\
927.RE
928.\}
929.RE
930.PP
michaelm5ac8c152012-03-06 20:34:38 +0000931divzero
rgallard36ba8532014-06-06 15:45:48 -0700932.RS 4
rgallardb6435452013-11-25 20:19:02 -0800933Warns about division by the constant integer 0, for example:
rgallard36ba8532014-06-06 15:45:48 -0700934.sp
935.if n \{\
936.RS 4
937.\}
938.nf
939\fBint divideByZero = 42 / 0;\fR
940
941.fi
942.if n \{\
943.RE
944.\}
945.RE
946.PP
michaelm5ac8c152012-03-06 20:34:38 +0000947empty
rgallard36ba8532014-06-06 15:45:48 -0700948.RS 4
949Warns about empty statements after
950\fBif \fRstatements, for example:
951.sp
952.if n \{\
953.RS 4
954.\}
955.nf
956\fBclass E {\fR
957\fB void m() {\fR
958\fB if (true) ;\fR
959\fB }\fR
960\fB}\fR
961
962.fi
963.if n \{\
964.RE
965.\}
966.RE
967.PP
michaelm5ac8c152012-03-06 20:34:38 +0000968fallthrough
rgallard36ba8532014-06-06 15:45:48 -0700969.RS 4
970Checks the switch blocks for fall\-through cases and provides a warning message for any that are found\&. Fall\-through cases are cases in a switch block, other than the last case in the block, whose code does not include a break statement, allowing code execution to fall through from that case to the next case\&. For example, the code following the case 1 label in this switch block does not end with a break statement:
971.sp
972.if n \{\
973.RS 4
974.\}
975.nf
976\fBswitch (x) {\fR
977\fBcase 1:\fR
978\fB System\&.out\&.println("1");\fR
979\fB // No break statement here\&.\fR
980\fBcase 2:\fR
981\fB System\&.out\&.println("2");\fR
982\fB}\fR
983
984.fi
985.if n \{\
986.RE
987.\}
988If the
989\fB\-Xlint:fallthrough\fR
990option was used when compiling this code, then the compiler emits a warning about possible fall\-through into case, with the line number of the case in question\&.
991.RE
992.PP
michaelm5ac8c152012-03-06 20:34:38 +0000993finally
rgallard36ba8532014-06-06 15:45:48 -0700994.RS 4
995Warns about
996\fBfinally\fR
997clauses that cannot complete normally, for example:
998.sp
999.if n \{\
1000.RS 4
1001.\}
1002.nf
1003\fBpublic static int m() {\fR
1004\fB try {\fR
1005\fB throw new NullPointerException();\fR
1006\fB } catch (NullPointerException(); {\fR
1007\fB System\&.err\&.println("Caught NullPointerException\&.");\fR
1008\fB return 1;\fR
1009\fB } finally {\fR
1010\fB return 0;\fR
1011\fB }\fR
1012\fB }\fR
1013
1014.fi
1015.if n \{\
1016.RE
1017.\}
1018The compiler generates a warning for the
1019\fBfinally\fR
1020block in this example\&. When the
1021\fBint\fR
1022method is called, it returns a value of 0\&. A
1023\fBfinally\fR
1024block executes when the
1025\fBtry\fR
1026block exits\&. In this example, when control is transferred to the
1027\fBcatch\fR
1028block, the
1029\fBint\fR
1030method exits\&. However, the
1031\fBfinally\fR
1032block must execute, so it is executed, even though control was transferred outside the method\&.
1033.RE
1034.PP
michaelm5ac8c152012-03-06 20:34:38 +00001035options
rgallard36ba8532014-06-06 15:45:48 -07001036.RS 4
1037Warns about issues that related to the use of command\-line options\&. See Cross\-Compilation Options\&.
1038.RE
1039.PP
michaelm5ac8c152012-03-06 20:34:38 +00001040overrides
rgallard36ba8532014-06-06 15:45:48 -07001041.RS 4
rgallardb6435452013-11-25 20:19:02 -08001042Warns about issues regarding method overrides\&. For example, consider the following two classes:
rgallard36ba8532014-06-06 15:45:48 -07001043.sp
1044.if n \{\
1045.RS 4
1046.\}
1047.nf
1048\fBpublic class ClassWithVarargsMethod {\fR
1049\fB void varargsMethod(String\&.\&.\&. s) { }\fR
1050\fB}\fR
1051
1052\fBpublic class ClassWithOverridingMethod extends ClassWithVarargsMethod {\fR
1053\fB @Override\fR
1054\fB void varargsMethod(String[] s) { }\fR
1055\fB}\fR
1056
1057.fi
1058.if n \{\
1059.RE
1060.\}
rgallardb6435452013-11-25 20:19:02 -08001061The compiler generates a warning similar to the following:\&.
rgallard36ba8532014-06-06 15:45:48 -07001062.sp
1063.if n \{\
1064.RS 4
1065.\}
1066.nf
1067\fBwarning: [override] varargsMethod(String[]) in ClassWithOverridingMethod \fR
1068\fBoverrides varargsMethod(String\&.\&.\&.) in ClassWithVarargsMethod; overriding\fR
1069\fBmethod is missing \*(Aq\&.\&.\&.\*(Aq\fR
1070
1071.fi
1072.if n \{\
1073.RE
1074.\}
1075When the compiler encounters a
1076\fBvarargs\fR
1077method, it translates the
1078\fBvarargs\fR
1079formal parameter into an array\&. In the method
1080\fBClassWithVarargsMethod\&.varargsMethod\fR, the compiler translates the
1081\fBvarargs\fR
1082formal parameter
1083\fBString\&.\&.\&. s\fR
1084to the formal parameter
1085\fBString[] s\fR, an array, which matches the formal parameter of the method
1086\fBClassWithOverridingMethod\&.varargsMethod\fR\&. Consequently, this example compiles\&.
1087.RE
1088.PP
michaelm5ac8c152012-03-06 20:34:38 +00001089path
rgallard36ba8532014-06-06 15:45:48 -07001090.RS 4
1091Warns about invalid path elements and nonexistent path directories on the command line (with regard to the class path, the source path, and other paths)\&. Such warnings cannot be suppressed with the
1092\fB@SuppressWarnings\fR
1093annotation, for example:
1094.sp
1095.if n \{\
1096.RS 4
1097.\}
1098.nf
1099\fBjavac \-Xlint:path \-classpath /nonexistentpath Example\&.java\fR
1100
1101.fi
1102.if n \{\
1103.RE
1104.\}
1105.RE
1106.PP
michaelm5ac8c152012-03-06 20:34:38 +00001107processing
rgallard36ba8532014-06-06 15:45:48 -07001108.RS 4
rgallardb6435452013-11-25 20:19:02 -08001109Warn about issues regarding annotation processing\&. The compiler generates this warning when you have a class that has an annotation, and you use an annotation processor that cannot handle that type of exception\&. For example, the following is a simple annotation processor:
rgallard36ba8532014-06-06 15:45:48 -07001110.sp
1111\fBSource file AnnocProc\&.java\fR:
1112.sp
1113.if n \{\
1114.RS 4
1115.\}
1116.nf
1117\fBimport java\&.util\&.*;\fR
1118\fBimport javax\&.annotation\&.processing\&.*;\fR
1119\fBimport javax\&.lang\&.model\&.*;\fR
1120\fBimport\&.javaz\&.lang\&.model\&.element\&.*;\fR
1121
1122\fB@SupportedAnnotationTypes("NotAnno")\fR
1123\fBpublic class AnnoProc extends AbstractProcessor {\fR
1124\fB public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv){\fR
1125\fB return true;\fR
1126\fB }\fR
1127
1128\fB public SourceVersion getSupportedSourceVersion() {\fR
1129\fB return SourceVersion\&.latest();\fR
1130\fB }\fR
1131\fB}\fR
1132
1133.fi
1134.if n \{\
1135.RE
1136.\}
1137\fBSource file AnnosWithoutProcessors\&.java\fR:
1138.sp
1139.if n \{\
1140.RS 4
1141.\}
1142.nf
1143\fB@interface Anno { }\fR
1144\fB \fR
1145\fB@Anno\fR
1146\fBclass AnnosWithoutProcessors { }\fR
1147
1148.fi
1149.if n \{\
1150.RE
1151.\}
1152The following commands compile the annotation processor
1153\fBAnnoProc\fR, then run this annotation processor against the source file
1154\fBAnnosWithoutProcessors\&.java\fR:
1155.sp
1156.if n \{\
1157.RS 4
1158.\}
1159.nf
1160\fBjavac AnnoProc\&.java\fR
1161\fBjavac \-cp \&. \-Xlint:processing \-processor AnnoProc \-proc:only AnnosWithoutProcessors\&.java\fR
1162
1163.fi
1164.if n \{\
1165.RE
1166.\}
1167When the compiler runs the annotation processor against the source file
1168\fBAnnosWithoutProcessors\&.java\fR, it generates the following warning:
1169.sp
1170.if n \{\
1171.RS 4
1172.\}
1173.nf
1174\fBwarning: [processing] No processor claimed any of these annotations: Anno\fR
1175\fB \fR
1176.fi
1177.if n \{\
1178.RE
1179.\}
1180To resolve this issue, you can rename the annotation defined and used in the class
1181\fBAnnosWithoutProcessors\fR
1182from
1183\fBAnno\fR
1184to
1185\fBNotAnno\fR\&.
1186.RE
1187.PP
michaelm5ac8c152012-03-06 20:34:38 +00001188rawtypes
rgallard36ba8532014-06-06 15:45:48 -07001189.RS 4
1190Warns about unchecked operations on raw types\&. The following statement generates a
1191\fBrawtypes\fR
1192warning:
1193.sp
1194.if n \{\
1195.RS 4
1196.\}
1197.nf
1198\fBvoid countElements(List l) { \&.\&.\&. }\fR
1199
1200.fi
1201.if n \{\
1202.RE
1203.\}
1204The following example does not generate a
1205\fBrawtypes\fR
1206warning
1207.sp
1208.if n \{\
1209.RS 4
1210.\}
1211.nf
1212\fBvoid countElements(List<?> l) { \&.\&.\&. }\fR
1213
1214.fi
1215.if n \{\
1216.RE
1217.\}
1218\fBList\fR
1219is a raw type\&. However,
1220\fBList<?>\fR
1221is an unbounded wildcard parameterized type\&. Because
1222\fBList\fR
1223is a parameterized interface, always specify its type argument\&. In this example, the
1224\fBList\fR
1225formal argument is specified with an unbounded wildcard (\fB?\fR) as its formal type parameter, which means that the
1226\fBcountElements\fR
1227method can accept any instantiation of the
1228\fBList\fR
1229interface\&.
1230.RE
1231.PP
rgallardb6435452013-11-25 20:19:02 -08001232Serial
rgallard36ba8532014-06-06 15:45:48 -07001233.RS 4
1234Warns about missing
1235\fBserialVersionUID\fR
1236definitions on serializable classes, for example:
1237.sp
1238.if n \{\
1239.RS 4
1240.\}
1241.nf
1242\fBpublic class PersistentTime implements Serializable\fR
1243\fB{\fR
1244\fB private Date time;\fR
1245\fB \fR
1246\fB public PersistentTime() {\fR
1247\fB time = Calendar\&.getInstance()\&.getTime();\fR
1248\fB }\fR
1249\fB \fR
1250\fB public Date getTime() {\fR
1251\fB return time;\fR
1252\fB }\fR
1253\fB}\fR
1254
1255.fi
1256.if n \{\
1257.RE
1258.\}
michaelm5ac8c152012-03-06 20:34:38 +00001259The compiler generates the following warning:
rgallard36ba8532014-06-06 15:45:48 -07001260.sp
1261.if n \{\
1262.RS 4
1263.\}
1264.nf
1265\fBwarning: [serial] serializable class PersistentTime has no definition of\fR
1266\fBserialVersionUID\fR
1267
1268.fi
1269.if n \{\
1270.RE
1271.\}
1272If a serializable class does not explicitly declare a field named
1273\fBserialVersionUID\fR, then the serialization runtime environment calculates a default
1274\fBserialVersionUID\fR
1275value for that class based on various aspects of the class, as described in the Java Object Serialization Specification\&. However, it is strongly recommended that all serializable classes explicitly declare
1276\fBserialVersionUID\fR
1277values because the default process of computing
1278\fBserialVersionUID\fR
1279vales is highly sensitive to class details that can vary depending on compiler implementations, and as a result, might cause an unexpected
1280\fBInvalidClassExceptions\fR
1281during deserialization\&. To guarantee a consistent
1282\fBserialVersionUID\fR
1283value across different Java compiler implementations, a serializable class must declare an explicit
1284\fBserialVersionUID\fR
1285value\&.
1286.RE
1287.PP
michaelm5ac8c152012-03-06 20:34:38 +00001288static
rgallard36ba8532014-06-06 15:45:48 -07001289.RS 4
rgallardb6435452013-11-25 20:19:02 -08001290Warns about issues relating to the use of statics, for example:
rgallard36ba8532014-06-06 15:45:48 -07001291.sp
1292.if n \{\
1293.RS 4
1294.\}
1295.nf
1296\fBclass XLintStatic {\fR
1297\fB static void m1() { }\fR
1298\fB void m2() { this\&.m1(); }\fR
1299\fB}\fR
1300
1301.fi
1302.if n \{\
1303.RE
1304.\}
michaelm5ac8c152012-03-06 20:34:38 +00001305The compiler generates the following warning:
rgallard36ba8532014-06-06 15:45:48 -07001306.sp
1307.if n \{\
1308.RS 4
1309.\}
1310.nf
1311\fBwarning: [static] static method should be qualified by type name, \fR
1312\fBXLintStatic, instead of by an expression\fR
1313
1314.fi
1315.if n \{\
1316.RE
1317.\}
1318To resolve this issue, you can call the
1319\fBstatic\fR
1320method
1321\fBm1\fR
1322as follows:
1323.sp
1324.if n \{\
1325.RS 4
1326.\}
1327.nf
1328\fBXLintStatic\&.m1();\fR
1329
1330.fi
1331.if n \{\
1332.RE
1333.\}
1334Alternately, you can remove the
1335\fBstatic\fR
1336keyword from the declaration of the method
1337\fBm1\fR\&.
1338.RE
1339.PP
michaelm5ac8c152012-03-06 20:34:38 +00001340try
rgallard36ba8532014-06-06 15:45:48 -07001341.RS 4
1342Warns about issues relating to use of
1343\fBtry\fR
1344blocks, including try\-with\-resources statements\&. For example, a warning is generated for the following statement because the resource
1345\fBac\fR
1346declared in the
1347\fBtry\fR
1348block is not used:
1349.sp
1350.if n \{\
1351.RS 4
1352.\}
1353.nf
1354\fBtry ( AutoCloseable ac = getResource() ) { // do nothing}\fR
1355
1356.fi
1357.if n \{\
1358.RE
1359.\}
1360.RE
1361.PP
michaelm5ac8c152012-03-06 20:34:38 +00001362unchecked
rgallard36ba8532014-06-06 15:45:48 -07001363.RS 4
rgallardb6435452013-11-25 20:19:02 -08001364Gives more detail for unchecked conversion warnings that are mandated by the Java Language Specification, for example:
rgallard36ba8532014-06-06 15:45:48 -07001365.sp
1366.if n \{\
1367.RS 4
1368.\}
1369.nf
1370\fBList l = new ArrayList<Number>();\fR
1371\fBList<String> ls = l; // unchecked warning\fR
1372
1373.fi
1374.if n \{\
1375.RE
1376.\}
1377During type erasure, the types
1378\fBArrayList<Number>\fR
1379and
1380\fBList<String>\fR
1381become
1382\fBArrayList\fR
1383and
1384\fBList\fR, respectively\&.
1385.sp
1386The
1387\fBls\fR
1388command has the parameterized type
1389\fBList<String>\fR\&. When the
1390\fBList\fR
1391referenced by
1392\fBl\fR
1393is assigned to
1394\fBls\fR, the compiler generates an unchecked warning\&. At compile time, the compiler and JVM cannot determine whether
1395\fBl\fR
1396refers to a
1397\fBList<String>\fR
1398type\&. In this case,
1399\fBl\fR
1400does not refer to a
1401\fBList<String>\fR
1402type\&. As a result, heap pollution occurs\&.
1403.sp
1404A heap pollution situation occurs when the
1405\fBList\fR
1406object
1407\fBl\fR, whose static type is
1408\fBList<Number>\fR, is assigned to another
1409\fBList\fR
1410object,
1411\fBls\fR, that has a different static type,
1412\fBList<String>\fR\&. However, the compiler still allows this assignment\&. It must allow this assignment to preserve backward compatibility with releases of Java SE that do not support generics\&. Because of type erasure,
1413\fBList<Number>\fR
1414and
1415\fBList<String>\fR
1416both become
1417\fBList\fR\&. Consequently, the compiler allows the assignment of the object
1418\fBl\fR\fB,\fR
1419which has a raw type of
1420\fBList\fR, to the object
1421\fBls\fR\&.
1422.RE
1423.PP
michaelm5ac8c152012-03-06 20:34:38 +00001424varargs
rgallard36ba8532014-06-06 15:45:48 -07001425.RS 4
1426Warns about unsafe usages of variable arguments (\fBvarargs\fR) methods, in particular, those that contain non\-reifiable arguments, for example:
1427.sp
1428.if n \{\
1429.RS 4
1430.\}
1431.nf
1432\fBpublic class ArrayBuilder {\fR
1433\fB public static <T> void addToList (List<T> listArg, T\&.\&.\&. elements) {\fR
1434\fB for (T x : elements) {\fR
1435\fB listArg\&.add(x);\fR
1436\fB }\fR
1437\fB }\fR
1438\fB}\fR
1439
1440.fi
1441.if n \{\
1442.RE
1443.\}
1444\fBNote:\fR
1445A non\-reifiable type is a type whose type information is not fully available at runtime\&.
1446.sp
1447The compiler generates the following warning for the definition of the method
1448\fBArrayBuilder\&.addToList\fR
1449.sp
1450.if n \{\
1451.RS 4
1452.\}
1453.nf
1454\fBwarning: [varargs] Possible heap pollution from parameterized vararg type T\fR
1455
1456.fi
1457.if n \{\
1458.RE
1459.\}
1460When the compiler encounters a varargs method, it translates the
1461\fBvarargs\fR
1462formal parameter into an array\&. However, the Java programming language does not permit the creation of arrays of parameterized types\&. In the method
1463\fBArrayBuilder\&.addToList\fR, the compiler translates the
1464\fBvarargs\fR
1465formal parameter
1466\fBT\&.\&.\&.\fR
1467elements to the formal parameter
1468\fBT[]\fR
1469elements, an array\&. However, because of type erasure, the compiler converts the
1470\fBvarargs\fR
1471formal parameter to
1472\fBObject[]\fR
1473elements\&. Consequently, there is a possibility of heap pollution\&.
1474.RE
1475.SH "COMMAND-LINE ARGUMENT FILES"
rgallardb6435452013-11-25 20:19:02 -08001476.PP
rgallard36ba8532014-06-06 15:45:48 -07001477To shorten or simplify the
1478\fBjavac\fR
1479command, you can specify one or more files that contain arguments to the
1480\fBjavac\fR
1481command (except
1482\fB\-J\fR
1483options)\&. This enables you to create
1484\fBjavac\fR
1485commands of any length on any operating system\&.
rgallardb6435452013-11-25 20:19:02 -08001486.PP
rgallard36ba8532014-06-06 15:45:48 -07001487An argument file can include
1488\fBjavac\fR
1489options and source file names in any combination\&. The arguments within a file can be separated by spaces or new line characters\&. If a file name contains embedded spaces, then put the whole file name in double quotation marks\&.
rgallardb6435452013-11-25 20:19:02 -08001490.PP
rgallard36ba8532014-06-06 15:45:48 -07001491File Names within an argument file are relative to the current directory, not the location of the argument file\&. Wild cards (*) are not allowed in these lists (such as for specifying
1492\fB*\&.java\fR)\&. Use of the at sign (@) to recursively interpret files is not supported\&. The
1493\fB\-J\fR
1494options are not supported because they are passed to the launcher, which does not support argument files\&.
rgallardb6435452013-11-25 20:19:02 -08001495.PP
rgallard36ba8532014-06-06 15:45:48 -07001496When executing the
1497\fBjavac\fR
1498command, pass in the path and name of each argument file with the at sign (@) leading character\&. When the
1499\fBjavac\fR
1500command encounters an argument beginning with the at sign (@), it expands the contents of that file into the argument list\&.
rgallardb6435452013-11-25 20:19:02 -08001501.PP
rgallard36ba8532014-06-06 15:45:48 -07001502\fBExample 1\fR
1503.br
1504Single Argument File
1505.RS 4
1506You could use a single argument file named
1507\fBargfile\fR
1508to hold all
1509\fBjavac\fR
1510arguments:
1511.sp
1512.if n \{\
1513.RS 4
1514.\}
1515.nf
1516\fBjavac @argfile\fR
1517
1518.fi
1519.if n \{\
1520.RE
1521.\}
rgallardb6435452013-11-25 20:19:02 -08001522This argument file could contain the contents of both files shown in Example 2
rgallard36ba8532014-06-06 15:45:48 -07001523.RE
rgallardb6435452013-11-25 20:19:02 -08001524.PP
rgallard36ba8532014-06-06 15:45:48 -07001525\fBExample 2\fR
1526.br
1527Two Argument Files
1528.RS 4
1529You can create two argument files: one for the
1530\fBjavac\fR
1531options and the other for the source file names\&. Note that the following lists have no line\-continuation characters\&.
1532.sp
rgallardb6435452013-11-25 20:19:02 -08001533Create a file named options that contains the following:
rgallard36ba8532014-06-06 15:45:48 -07001534.sp
1535.if n \{\
1536.RS 4
1537.\}
1538.nf
1539\fB\-d classes\fR
1540.fi
1541.if n \{\
1542.RE
1543.\}
1544.sp
1545.if n \{\
1546.RS 4
1547.\}
1548.nf
1549\fB\-g\fR
1550.fi
1551.if n \{\
1552.RE
1553.\}
1554.sp
1555.if n \{\
1556.RS 4
1557.\}
1558.nf
1559\fB\-sourcepath /java/pubs/ws/1\&.3/src/share/classes\fR
1560.fi
1561.if n \{\
1562.RE
1563.\}
1564.sp
1565.if n \{\
1566.RS 4
1567.\}
1568.nf
1569
1570.fi
1571.if n \{\
1572.RE
1573.\}
rgallardb6435452013-11-25 20:19:02 -08001574Create a file named classes that contains the following:
rgallard36ba8532014-06-06 15:45:48 -07001575.sp
1576.if n \{\
1577.RS 4
1578.\}
1579.nf
1580\fBMyClass1\&.java\fR
1581\fBMyClass2\&.java\fR
1582\fBMyClass3\&.java\fR
1583
1584.fi
1585.if n \{\
1586.RE
1587.\}
1588Then, run the
1589\fBjavac\fR
1590command as follows:
1591.sp
1592.if n \{\
1593.RS 4
1594.\}
1595.nf
1596\fBjavac @options @classes\fR
1597
1598.fi
1599.if n \{\
1600.RE
1601.\}
1602.RE
rgallardb6435452013-11-25 20:19:02 -08001603.PP
rgallard36ba8532014-06-06 15:45:48 -07001604\fBExample 3\fR
1605.br
1606Argument Files with Paths
1607.RS 4
1608The argument files can have paths, but any file names inside the files are relative to the current working directory (not
1609\fBpath1\fR
1610or
1611\fBpath2\fR):
1612.sp
1613.if n \{\
1614.RS 4
1615.\}
1616.nf
1617\fBjavac @path1/options @path2/classes\fR
1618
1619.fi
1620.if n \{\
1621.RE
1622.\}
1623.RE
1624.SH "ANNOTATION PROCESSING"
rgallardb6435452013-11-25 20:19:02 -08001625.PP
rgallard36ba8532014-06-06 15:45:48 -07001626The
1627\fBjavac\fR
1628command provides direct support for annotation processing, superseding the need for the separate annotation processing command,
1629\fBapt\fR\&.
1630.PP
1631The API for annotation processors is defined in the
1632\fBjavax\&.annotation\&.processing\fR
1633and j\fBavax\&.lang\&.model\fR
1634packages and subpackages\&.
1635.SS "How Annotation Processing Works"
1636.PP
1637Unless annotation processing is disabled with the
1638\fB\-proc:none\fR
1639option, the compiler searches for any annotation processors that are available\&. The search path can be specified with the
1640\fB\-processorpath\fR
1641option\&. If no path is specified, then the user class path is used\&. Processors are located by means of service provider\-configuration files named
1642\fBMETA\-INF/services/javax\&.annotation\&.processing\fR\&.Processor on the search path\&. Such files should contain the names of any annotation processors to be used, listed one per line\&. Alternatively, processors can be specified explicitly, using the
1643\fB\-processor\fR
1644option\&.
rgallardb6435452013-11-25 20:19:02 -08001645.PP
1646After scanning the source files and classes on the command line to determine what annotations are present, the compiler queries the processors to determine what annotations they process\&. When a match is found, the processor is called\&. A processor can claim the annotations it processes, in which case no further attempt is made to find any processors for those annotations\&. After all of the annotations are claimed, the compiler does not search for additional processors\&.
1647.PP
1648If any processors generate new source files, then another round of annotation processing occurs: Any newly generated source files are scanned, and the annotations processed as before\&. Any processors called on previous rounds are also called on all subsequent rounds\&. This continues until no new source files are generated\&.
1649.PP
rgallard36ba8532014-06-06 15:45:48 -07001650After a round occurs where no new source files are generated, the annotation processors are called one last time, to give them a chance to complete any remaining work\&. Finally, unless the
1651\fB\-proc:only\fR
1652option is used, the compiler compiles the original and all generated source files\&.
1653.SS "Implicitly Loaded Source Files"
1654.PP
1655To compile a set of source files, the compiler might need to implicitly load additional source files\&. See Searching for Types\&. Such files are currently not subject to annotation processing\&. By default, the compiler gives a warning when annotation processing occurred and any implicitly loaded source files are compiled\&. The
1656\fB\-implicit\fR
1657option provides a way to suppress the warning\&.
1658.SH "SEARCHING FOR TYPES"
1659.PP
rgallardb6435452013-11-25 20:19:02 -08001660To compile a source file, the compiler often needs information about a type, but the type definition is not in the source files specified on the command line\&. The compiler needs type information for every class or interface used, extended, or implemented in the source file\&. This includes classes and interfaces not explicitly mentioned in the source file, but that provide information through inheritance\&.
1661.PP
rgallard36ba8532014-06-06 15:45:48 -07001662For example, when you create a subclass
1663\fBjava\&.applet\&.Applet\fR, you are also using the ancestor classes of
1664\fBApplet\fR:
1665\fBjava\&.awt\&.Panel\fR,
1666\fBjava\&.awt\&.Container\fR,
1667\fBjava\&.awt\&.Component\fR, and
1668\fBjava\&.lang\&.Object\fR\&.
rgallardb6435452013-11-25 20:19:02 -08001669.PP
rgallard36ba8532014-06-06 15:45:48 -07001670When the compiler needs type information, it searches for a source file or class file that defines the type\&. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory)\&. The user class path is defined by setting the
1671\fBCLASSPATH\fR
1672environment variable or by using the
1673\fB\-classpath\fR
1674option\&.
rgallardb6435452013-11-25 20:19:02 -08001675.PP
rgallard36ba8532014-06-06 15:45:48 -07001676If you set the
1677\fB\-sourcepath\fR
1678option, then the compiler searches the indicated path for source files\&. Otherwise, the compiler searches the user class path for both class files and source files\&.
rgallardb6435452013-11-25 20:19:02 -08001679.PP
rgallard36ba8532014-06-06 15:45:48 -07001680You can specify different bootstrap or extension classes with the
1681\fB\-bootclasspath\fR
1682and the
1683\fB\-extdirs\fR
1684options\&. See Cross\-Compilation Options\&.
rgallardb6435452013-11-25 20:19:02 -08001685.PP
rgallard36ba8532014-06-06 15:45:48 -07001686A successful type search may produce a class file, a source file, or both\&. If both are found, then you can use the
1687\fB\-Xprefer\fR
1688option to instruct the compiler which to use\&. If
1689\fBnewer\fR
1690is specified, then the compiler uses the newer of the two files\&. If
1691\fBsource\fR
1692is specified, the compiler uses the source file\&. The default is
1693\fBnewer\fR\&.
rgallardb6435452013-11-25 20:19:02 -08001694.PP
rgallard36ba8532014-06-06 15:45:48 -07001695If a type search finds a source file for a required type, either by itself, or as a result of the setting for the
1696\fB\-Xprefer\fR
1697option, then the compiler reads the source file to get the information it needs\&. By default the compiler also compiles the source file\&. You can use the
1698\fB\-implicit\fR
1699option to specify the behavior\&. If
1700\fBnone\fR
1701is specified, then no class files are generated for the source file\&. If
1702\fBclass\fR
1703is specified, then class files are generated for the source file\&.
rgallardb6435452013-11-25 20:19:02 -08001704.PP
rgallard36ba8532014-06-06 15:45:48 -07001705The compiler might not discover the need for some type information until after annotation processing completes\&. When the type information is found in a source file and no
1706\fB\-implicit\fR
1707option is specified, the compiler gives a warning that the file is being compiled without being subject to annotation processing\&. To disable the warning, either specify the file on the command line (so that it will be subject to annotation processing) or use the
1708\fB\-implicit\fR
1709option to specify whether or not class files should be generated for such source files\&.
1710.SH "PROGRAMMATIC INTERFACE"
rgallardb6435452013-11-25 20:19:02 -08001711.PP
rgallard36ba8532014-06-06 15:45:48 -07001712The
1713\fBjavac\fR
1714command supports the new Java Compiler API defined by the classes and interfaces in the
1715\fBjavax\&.tools\fR
1716package\&.
1717.SS "Example"
rgallardb6435452013-11-25 20:19:02 -08001718.PP
rgallard36ba8532014-06-06 15:45:48 -07001719To compile as though providing command\-line arguments, use the following syntax:
1720.sp
1721.if n \{\
1722.RS 4
1723.\}
1724.nf
1725\fBJavaCompiler javac = ToolProvider\&.getSystemJavaCompiler();\fR
1726
1727.fi
1728.if n \{\
1729.RE
1730.\}
rgallardb6435452013-11-25 20:19:02 -08001731.PP
rgallard36ba8532014-06-06 15:45:48 -07001732The example writes diagnostics to the standard output stream and returns the exit code that
1733\fBjavac\fR
1734would give when called from the command line\&.
rgallardb6435452013-11-25 20:19:02 -08001735.PP
rgallard36ba8532014-06-06 15:45:48 -07001736You can use other methods in the
1737\fBjavax\&.tools\&.JavaCompiler\fR
1738interface to handle diagnostics, control where files are read from and written to, and more\&.
1739.SS "Old Interface"
rgallardb6435452013-11-25 20:19:02 -08001740.PP
rgallard36ba8532014-06-06 15:45:48 -07001741\fBNote:\fR
1742This API is retained for backward compatibility only\&. All new code should use the newer Java Compiler API\&.
rgallardb6435452013-11-25 20:19:02 -08001743.PP
rgallard36ba8532014-06-06 15:45:48 -07001744The
1745\fBcom\&.sun\&.tools\&.javac\&.Main\fR
1746class provides two static methods to call the compiler from a program:
1747.sp
1748.if n \{\
1749.RS 4
1750.\}
1751.nf
1752\fBpublic static int compile(String[] args);\fR
1753\fBpublic static int compile(String[] args, PrintWriter out);\fR
1754
1755.fi
1756.if n \{\
1757.RE
1758.\}
rgallardb6435452013-11-25 20:19:02 -08001759.PP
rgallard36ba8532014-06-06 15:45:48 -07001760The
1761\fBargs\fR
1762parameter represents any of the command\-line arguments that would typically be passed to the compiler\&.
1763.PP
1764The
1765\fBout\fR
1766parameter indicates where the compiler diagnostic output is directed\&.
1767.PP
1768The
1769\fBreturn\fR
1770value is equivalent to the
1771\fBexit\fR
1772value from
1773\fBjavac\fR\&.
1774.PP
1775\fBNote:\fR
1776All other classes and methods found in a package with names that start with
1777\fBcom\&.sun\&.tools\&.javac\fR
1778(subpackages of
1779\fBcom\&.sun\&.tools\&.javac\fR) are strictly internal and subject to change at any time\&.
1780.SH "EXAMPLES"
1781.PP
1782\fBExample 1\fR
1783.br
1784Compile a Simple Program
1785.RS 4
1786This example shows how to compile the
1787\fBHello\&.java\fR
1788source file in the greetings directory\&. The class defined in
1789\fBHello\&.java\fR
1790is called
1791\fBgreetings\&.Hello\fR\&. The greetings directory is the package directory both for the source file and the class file and is underneath the current directory\&. This makes it possible to use the default user class path\&. It also makes it unnecessary to specify a separate destination directory with the
1792\fB\-d\fR
1793option\&.
1794.sp
1795The source code in
1796\fBHello\&.java\fR:
1797.sp
1798.if n \{\
1799.RS 4
1800.\}
1801.nf
1802\fBpackage greetings;\fR
1803\fB \fR
1804\fBpublic class Hello {\fR
1805\fB public static void main(String[] args) {\fR
1806\fB for (int i=0; i < args\&.length; i++) {\fR
1807\fB System\&.out\&.println("Hello " + args[i]);\fR
1808\fB }\fR
1809\fB }\fR
1810\fB}\fR
1811
1812.fi
1813.if n \{\
1814.RE
1815.\}
rgallardb6435452013-11-25 20:19:02 -08001816Compile greetings\&.Hello:
rgallard36ba8532014-06-06 15:45:48 -07001817.sp
1818.if n \{\
1819.RS 4
1820.\}
1821.nf
1822\fBjavac greetings/Hello\&.java\fR
1823
1824.fi
1825.if n \{\
1826.RE
1827.\}
1828Run
1829\fBgreetings\&.Hello\fR:
1830.sp
1831.if n \{\
1832.RS 4
1833.\}
1834.nf
1835\fBjava greetings\&.Hello World Universe Everyone\fR
1836\fBHello World\fR
1837\fBHello Universe\fR
1838\fBHello Everyone\fR
1839
1840.fi
1841.if n \{\
1842.RE
1843.\}
1844.RE
rgallardb6435452013-11-25 20:19:02 -08001845.PP
rgallard36ba8532014-06-06 15:45:48 -07001846\fBExample 2\fR
1847.br
1848Compile Multiple Source Files
1849.RS 4
1850This example compiles the
1851\fBAloha\&.java\fR,
1852\fBGutenTag\&.java\fR,
1853\fBHello\&.java\fR, and
1854\fBHi\&.java\fR
1855source files in the
1856\fBgreetings\fR
1857package\&.
1858.sp
1859.if n \{\
1860.RS 4
1861.\}
1862.nf
1863\fB% javac greetings/*\&.java\fR
1864\fB% ls greetings\fR
1865\fBAloha\&.class GutenTag\&.class Hello\&.class Hi\&.class\fR
1866\fBAloha\&.java GutenTag\&.java Hello\&.java Hi\&.java\fR
1867
1868.fi
1869.if n \{\
1870.RE
1871.\}
1872.RE
rgallardb6435452013-11-25 20:19:02 -08001873.PP
rgallard36ba8532014-06-06 15:45:48 -07001874\fBExample 3\fR
1875.br
1876Specify a User Class Path
1877.RS 4
rgallardb6435452013-11-25 20:19:02 -08001878After changing one of the source files in the previous example, recompile it:
rgallard36ba8532014-06-06 15:45:48 -07001879.sp
1880.if n \{\
1881.RS 4
1882.\}
1883.nf
1884\fBpwd\fR
1885\fB/examples\fR
1886\fBjavac greetings/Hi\&.java\fR
1887
1888.fi
1889.if n \{\
1890.RE
1891.\}
1892Because
1893\fBgreetings\&.Hi\fR
1894refers to other classes in the
1895\fBgreetings\fR
1896package, the compiler needs to find these other classes\&. The previous example works because the default user class path is the directory that contains the package directory\&. If you want to recompile this file without concern for which directory you are in, then add the examples directory to the user class path by setting
1897\fBCLASSPATH\fR\&. This example uses the
1898\fB\-classpath\fR
1899option\&.
1900.sp
1901.if n \{\
1902.RS 4
1903.\}
1904.nf
1905\fBjavac \-classpath /examples /examples/greetings/Hi\&.java\fR
1906
1907.fi
1908.if n \{\
1909.RE
1910.\}
1911If you change
1912\fBgreetings\&.Hi\fR
1913to use a banner utility, then that utility also needs to be accessible through the user class path\&.
1914.sp
1915.if n \{\
1916.RS 4
1917.\}
1918.nf
1919\fBjavac \-classpath /examples:/lib/Banners\&.jar \e\fR
1920\fB /examples/greetings/Hi\&.java\fR
1921
1922.fi
1923.if n \{\
1924.RE
1925.\}
1926To execute a class in the
1927\fBgreetings\fR
1928package, the program needs access to the
1929\fBgreetings\fR
1930package, and to the classes that the
1931\fBgreetings\fR
1932classes use\&.
1933.sp
1934.if n \{\
1935.RS 4
1936.\}
1937.nf
1938\fBjava \-classpath /examples:/lib/Banners\&.jar greetings\&.Hi\fR
1939
1940.fi
1941.if n \{\
1942.RE
1943.\}
1944.RE
rgallardb6435452013-11-25 20:19:02 -08001945.PP
rgallard36ba8532014-06-06 15:45:48 -07001946\fBExample 4\fR
1947.br
1948Separate Source Files and Class Files
1949.RS 4
1950The following example uses
1951\fBjavac\fR
1952to compile code that runs on JVM 1\&.7\&.
1953.sp
1954.if n \{\
1955.RS 4
1956.\}
1957.nf
1958\fBjavac \-source 1\&.7 \-target 1\&.7 \-bootclasspath jdk1\&.7\&.0/lib/rt\&.jar \e \fR
1959\fB\-extdirs "" OldCode\&.java\fR
1960
1961.fi
1962.if n \{\
1963.RE
1964.\}
1965The
1966\fB\-source 1\&.7\fR
1967option specifies that release 1\&.7 (or 7) of the Java programming language be used to compile
1968\fBOldCode\&.java\fR\&. The option
1969\fB\-target 1\&.7\fR
1970option ensures that the generated class files are compatible with JVM 1\&.7\&. Note that in most cases, the value of the
1971\fB\-target\fR
1972option is the value of the
1973\fB\-source\fR
1974option; in this example, you can omit the
1975\fB\-target\fR
1976option\&.
1977.sp
1978You must specify the
1979\fB\-bootclasspath\fR
1980option to specify the correct version of the bootstrap classes (the
1981\fBrt\&.jar\fR
1982library)\&. If not, then the compiler generates a warning:
1983.sp
1984.if n \{\
1985.RS 4
1986.\}
1987.nf
1988\fBjavac \-source 1\&.7 OldCode\&.java\fR
1989\fBwarning: [options] bootstrap class path not set in conjunction with \fR
1990\fB\-source 1\&.7\fR
1991
1992.fi
1993.if n \{\
1994.RE
1995.\}
1996If you do not specify the correct version of bootstrap classes, then the compiler uses the old language rules (in this example, it uses version 1\&.7 of the Java programming language) combined with the new bootstrap classes, which can result in class files that do not work on the older platform (in this case, Java SE 7) because reference to nonexistent methods can get included\&.
1997.RE
rgallardb6435452013-11-25 20:19:02 -08001998.PP
rgallard36ba8532014-06-06 15:45:48 -07001999\fBExample 5\fR
2000.br
2001Cross Compile
2002.RS 4
2003This example uses
2004\fBjavac\fR
2005to compile code that runs on JVM 1\&.7\&.
2006.sp
2007.if n \{\
2008.RS 4
2009.\}
2010.nf
2011\fBjavac \-source 1\&.7 \-target 1\&.7 \-bootclasspath jdk1\&.7\&.0/lib/rt\&.jar \e\fR
2012\fB \-extdirs "" OldCode\&.java\fR
2013
2014.fi
2015.if n \{\
2016.RE
2017.\}
2018The\fB \-source 1\&.7\fR
2019option specifies that release 1\&.7 (or 7) of the Java programming language to be used to compile OldCode\&.java\&. The
2020\fB\-target 1\&.7\fR
2021option ensures that the generated class files are compatible with JVM 1\&.7\&. In most cases, the value of the
2022\fB\-target\fR
2023is the value of
2024\fB\-source\fR\&. In this example, the
2025\fB\-target\fR
2026option is omitted\&.
2027.sp
2028You must specify the
2029\fB\-bootclasspath\fR
2030option to specify the correct version of the bootstrap classes (the
2031\fBrt\&.jar\fR
2032library)\&. If not, then the compiler generates a warning:
2033.sp
2034.if n \{\
2035.RS 4
2036.\}
2037.nf
2038\fBjavac \-source 1\&.7 OldCode\&.java\fR
2039\fBwarning: [options] bootstrap class path not set in conjunction with \-source 1\&.7\fR
2040
2041.fi
2042.if n \{\
2043.RE
2044.\}
2045If you do not specify the correct version of bootstrap classes, then the compiler uses the old language rules combined with the new bootstrap classes\&. This combination can result in class files that do not work on the older platform (in this case, Java SE 7) because reference to nonexistent methods can get included\&. In this example, the compiler uses release 1\&.7 of the Java programming language\&.
2046.RE
2047.SH "SEE ALSO"
2048.sp
2049.RS 4
2050.ie n \{\
2051\h'-04'\(bu\h'+03'\c
2052.\}
2053.el \{\
2054.sp -1
2055.IP \(bu 2.3
2056.\}
rgallardb6435452013-11-25 20:19:02 -08002057java(1)
rgallard36ba8532014-06-06 15:45:48 -07002058.RE
2059.sp
2060.RS 4
2061.ie n \{\
2062\h'-04'\(bu\h'+03'\c
2063.\}
2064.el \{\
2065.sp -1
2066.IP \(bu 2.3
2067.\}
rgallardb6435452013-11-25 20:19:02 -08002068jdb(1)
rgallard36ba8532014-06-06 15:45:48 -07002069.RE
2070.sp
2071.RS 4
2072.ie n \{\
2073\h'-04'\(bu\h'+03'\c
2074.\}
2075.el \{\
2076.sp -1
2077.IP \(bu 2.3
2078.\}
rgallardb6435452013-11-25 20:19:02 -08002079javah(1)
rgallard36ba8532014-06-06 15:45:48 -07002080.RE
2081.sp
2082.RS 4
2083.ie n \{\
2084\h'-04'\(bu\h'+03'\c
2085.\}
2086.el \{\
2087.sp -1
2088.IP \(bu 2.3
2089.\}
rgallardb6435452013-11-25 20:19:02 -08002090javadoc(1)
rgallard36ba8532014-06-06 15:45:48 -07002091.RE
2092.sp
2093.RS 4
2094.ie n \{\
2095\h'-04'\(bu\h'+03'\c
2096.\}
2097.el \{\
2098.sp -1
2099.IP \(bu 2.3
2100.\}
rgallardb6435452013-11-25 20:19:02 -08002101jar(1)
rgallard36ba8532014-06-06 15:45:48 -07002102.RE
2103.sp
2104.RS 4
2105.ie n \{\
2106\h'-04'\(bu\h'+03'\c
2107.\}
2108.el \{\
2109.sp -1
2110.IP \(bu 2.3
2111.\}
rgallardb6435452013-11-25 20:19:02 -08002112jdb(1)
rgallard36ba8532014-06-06 15:45:48 -07002113.RE
2114.br
2115'pl 8.5i
2116'bp