18 ." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
16 ." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
19 ." |
17 ." |
20 ." Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
18 ." Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
21 ." CA 95054 USA or visit www.sun.com if you need additional information or |
19 ." CA 95054 USA or visit www.sun.com if you need additional information or |
22 ." have any questions. |
20 ." have any questions. |
23 ." |
21 ." |
24 ." ` |
22 .TH javac 1 "04 May 2009" |
25 .TH javac 1 "07 Aug 2006" |
23 ." Generated from HTML by html2man (author: Eric Armstrong) |
26 ." Generated by html2man |
24 |
27 |
25 .LP |
28 .LP |
26 .SH "Name" |
29 .SH NAME |
|
30 javac \- Java programming language compiler |
27 javac \- Java programming language compiler |
31 .LP |
28 .LP |
32 .SH "SYNOPSIS" |
29 .SH "SYNOPSIS" |
33 .LP |
30 .LP |
34 |
31 |
35 .LP |
32 .LP |
36 .nf |
33 .nf |
37 \f3 |
34 \f3 |
38 .fl |
35 .fl |
39 \fP\f3javac\fP [ options ] [ sourcefiles ] [ @argfiles ] |
36 \fP\f3javac\fP [ options ] [ sourcefiles ] [ classes ] [ @argfiles ] |
|
37 .fl |
|
38 |
40 .fl |
39 .fl |
41 .fi |
40 .fi |
42 |
41 |
43 .LP |
42 .LP |
44 .LP |
43 .LP |
91 You should arrange source files in a directory tree that reflects their package tree. For example, if you keep all your source files in \f3/workspace\fP, the source code for \f2com.mysoft.mypack.MyClass\fP should be in \f3/workspace/com/mysoft/mypack/MyClass.java\fP. |
93 You should arrange source files in a directory tree that reflects their package tree. For example, if you keep all your source files in \f3/workspace\fP, the source code for \f2com.mysoft.mypack.MyClass\fP should be in \f3/workspace/com/mysoft/mypack/MyClass.java\fP. |
92 .LP |
94 .LP |
93 .LP |
95 .LP |
94 By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with \f3\-d\fP (see Options, below). |
96 By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with \f3\-d\fP (see Options, below). |
95 .LP |
97 .LP |
96 .SH "SEARCHING FOR TYPES" |
|
97 .LP |
|
98 |
|
99 .LP |
|
100 .LP |
|
101 When compiling a source file, the compiler often needs information about a type whose definition did not appear in the source files given on the command line. The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance. |
|
102 .LP |
|
103 .LP |
|
104 For example, when you subclass \f3java.applet.Applet\fP, you are also using \f3Applet's\fP ancestor classes: \f3java.awt.Panel\fP, \f3java.awt.Container\fP, \f3java.awt.Component\fP, and \f3java.lang.Object\fP. |
|
105 .LP |
|
106 .LP |
|
107 When the compiler needs type information, it looks for a source file or class file which defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the \f3CLASSPATH\fP environment variable or by using the \f3\-classpath\fP command line option. (For details, see Setting the Class Path). |
|
108 .LP |
|
109 .LP |
|
110 If you set the \-sourcepath option, the compiler searches the indicated path for source files; otherwise the compiler searches the user class path for both class files and source files. |
|
111 .LP |
|
112 .LP |
|
113 You can specify different bootstrap or extension classes with the \f3\-bootclasspath\fP and \f3\-extdirs\fP options; see Cross\-Compilation Options below. |
|
114 .LP |
|
115 .LP |
|
116 A successful type search may produce a class file, a source file, or both. Here is how \f3javac\fP handles each situation: |
|
117 .LP |
|
118 .RS 3 |
|
119 .TP 2 |
|
120 o |
|
121 \f2Search produces a class file but no source file:\fP \f3javac\fP uses the class file. |
|
122 .TP 2 |
|
123 o |
|
124 \f2Search produces a source file but no class file:\fP \f3javac\fP compiles the source file and uses the resulting class file. |
|
125 .TP 2 |
|
126 o |
|
127 \f2Search produces both a source file and a class file:\fP \f3javac\fP determines whether the class file is out of date. If the class file is out of date, \f3javac\fP recompiles the source file and uses the updated class file. Otherwise, \f3javac\fP just uses the class file. |
|
128 .LP |
|
129 \f3javac\fP considers a class file out of date only if it is older than the source file. |
|
130 .RE |
|
131 |
|
132 .LP |
|
133 .LP |
|
134 \f3Note:\fP \ \f3javac\fP can silently compile source files not mentioned on the command line. Use the \f3\-verbose\fP option to trace automatic compilation. |
|
135 .LP |
|
136 .SH "OPTIONS" |
98 .SH "OPTIONS" |
137 .LP |
99 .LP |
138 |
100 |
139 .LP |
101 .LP |
140 .LP |
102 .LP |
146 .RS 3 |
108 .RS 3 |
147 |
109 |
148 .LP |
110 .LP |
149 .RS 3 |
111 .RS 3 |
150 .TP 3 |
112 .TP 3 |
151 \-classpath classpath |
113 \-Akey[=value] |
152 Set the user class path, overriding the user class path in the \f3CLASSPATH\fP environment variable. If neither \f3CLASSPATH\fP or \f3\-classpath\fP is specified, the user class path consists of the current directory. See Setting the Class Path for more details. |
114 Options to pass to annotation processors. These are not interpreted by javac directly, but are made available for use by individual processors. \f2key\fP should be one or more identifiers separated by ".". |
153 .LP |
115 .TP 3 |
154 If the \f3\-sourcepath\fP option is not specified, the user class path is searched for both source files and class files. |
116 \-cp path or \-classpath path |
155 .LP |
117 Specify where to find user class files, and (optionally) annotation processors and source files. This classpath overrides the user class path in the \f3CLASSPATH\fP environment variable. If neither \f3CLASSPATH\fP, \f3\-cp\fP nor \f3\-classpath\fP is specified, the user class path consists of the current directory. See |
156 As a special convenience, a class path element containing a basename of \f2*\fP is considered equivalent to specifying a list of all the files in the directory with the extension \f2.jar\fP or \f2.JAR\fP (a java program cannot tell the difference between the two invocations). |
118 .na |
|
119 \f2Setting the Class Path\fP @ |
|
120 .fi |
|
121 http://java.sun.com/javase/6/docs/technotes/tools/index.html#classpath for more details. |
|
122 .LP |
|
123 If the \f3\-sourcepath\fP option is not specified, the user class path is also searched for source files. |
|
124 .LP |
|
125 If the \f3\-processorpath\fP option is not specified, the classpath is also searched for annotation processors. |
|
126 .LP |
|
127 As a special convenience, a class path element containing a basename of \f2*\fP is considered equivalent to specifying a list of all the files in the directory with the extension \f2.jar\fP or \f2.JAR\fP. |
157 .br |
128 .br |
158 .br |
129 .br |
159 For example, if directory \f2foo\fP contains \f2a.jar\fP and \f2b.JAR\fP, then the class path element \f2foo/*\fP is expanded to a \f2A.jar:b.JAR\fP, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of \f2*\fP expands to a list of all the jar files in the current directory. The \f2CLASSPATH\fP environment variable, where defined, will be similarly expanded. Any classpath wildcard expansion occurs before the Java virtual machine is started \-\- no Java program will ever see unexpanded wildcards except by querying the environment. For example; by invoking \f2System.getenv("CLASSPATH")\fP. |
130 For example, if directory \f2foo\fP contains \f2a.jar\fP and \f2b.JAR\fP, then the class path element \f2foo/*\fP is expanded to \f2A.jar:b.JAR\fP, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of \f2*\fP expands to a list of all the jar files in the current directory. The \f2CLASSPATH\fP environment variable, where defined, will be similarly expanded. \f3Note:\fP \ Depending of the configuration of your command line environment, you may have to quote the wild card character, for example, \f2javac \-cp "*.jar" MyClass.java\fP. |
160 .TP 3 |
131 .TP 3 |
161 \-Djava.ext.dirs=directories |
132 \-Djava.ext.dirs=directories |
162 Override the location of installed extensions. |
133 Override the location of installed extensions. |
163 .TP 3 |
134 .TP 3 |
164 \-Djava.endorsed.dirs=directories |
135 \-Djava.endorsed.dirs=directories |
165 Override the location of endorsed standards path. |
136 Override the location of endorsed standards path. |
166 .TP 3 |
137 .TP 3 |
167 \-d directory |
138 \-d directory |
168 Set the destination directory for class files. The destination directory must already exist; javac will not create the destination directory. If a class is part of a package, \f3javac\fP puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify \f3\-d /home/myclasses\fP and the class is called \f2com.mypackage.MyClass\fP, then the class file is called \f2/home/myclasses/com/mypackage/MyClass.class\fP. |
139 Set the destination directory for class files. The directory must already exist; \f3javac\fP will not create it. If a class is part of a package, \f3javac\fP puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify \f3\-d /home/myclasses\fP and the class is called \f2com.mypackage.MyClass\fP, then the class file is called \f2/home/myclasses/com/mypackage/MyClass.class\fP. |
169 .LP |
140 .LP |
170 If \f3\-d\fP is not specified, \f3javac\fP puts the class file in the same directory as the source file. |
141 If \f3\-d\fP is not specified, \f3javac\fP puts each class files in the same directory as the source file from which it was generated. |
171 .LP |
142 .LP |
172 \f3Note:\fP \ The directory specified by \f3\-d\fP is not automatically added to your user class path. |
143 \f3Note:\fP \ The directory specified by \f3\-d\fP is not automatically added to your user class path. |
173 .TP 3 |
144 .TP 3 |
174 \-deprecation |
145 \-deprecation |
175 Show a description of each use or override of a deprecated member or class. Without \f3\-deprecation\fP, \f3javac\fP shows the names of source files that use or override deprecated members or classes. \f3\-deprecation\fP is shorthand for \f3\-Xlint:deprecation\fP. |
146 Show a description of each use or override of a deprecated member or class. Without \f3\-deprecation\fP, \f3javac\fP shows a summary of the source files that use or override deprecated members or classes. \f3\-deprecation\fP is shorthand for \f3\-Xlint:deprecation\fP. |
176 .TP 3 |
147 .TP 3 |
177 \-encoding encoding |
148 \-encoding encoding |
178 Set the source file encoding name, such as \f2EUC\-JP and UTF\-8.\fP. If \f3\-encoding\fP is not specified, the platform default converter is used. |
149 Set the source file encoding name, such as \f2EUC\-JP and UTF\-8\fP. If \f3\-encoding\fP is not specified, the platform default converter is used. |
179 .TP 3 |
150 .TP 3 |
180 \-g |
151 \-g |
181 Generate all debugging information, including local variables. By default, only line number and source file information is generated. |
152 Generate all debugging information, including local variables. By default, only line number and source file information is generated. |
182 .TP 3 |
153 .TP 3 |
183 \-g:none |
154 \-g:none |
198 .RE |
169 .RE |
199 .TP 3 |
170 .TP 3 |
200 \-help |
171 \-help |
201 Print a synopsis of standard options. |
172 Print a synopsis of standard options. |
202 .TP 3 |
173 .TP 3 |
|
174 \-implicit:{class,none} |
|
175 Controls the generation of class files for implicitly loaded source files. To automatically generate class files, use \f3\-implicit:class\fP. To suppress class file generation, use \f3\-implicit:none\fP. If this option is not specified, the default is to automatically generate class files. In this case, the compiler will issue a warning if any such class files are generated when also doing annotation processing. The warning will not be issued if this option is set explicitly. See Searching For Types. |
|
176 .TP 3 |
203 \-nowarn |
177 \-nowarn |
204 Disable warning messages. This has the same meaning as \f3\-Xlint:none\fP. |
178 Disable warning messages. This has the same meaning as \f3\-Xlint:none\fP. |
205 .LP |
179 .TP 3 |
|
180 \-proc: {none,only} |
|
181 Controls whether annotation processing and/or compilation is done. \f3\-proc:none\fP means that compilation takes place without annotation processing. \f3\-proc:only\fP means that only annotation processing is done, without any subsequent compilation. |
|
182 .TP 3 |
|
183 \-processor class1[,class2,class3...] |
|
184 Names of the annotation processors to run. This bypasses the default discovery process. |
|
185 .TP 3 |
|
186 \-processorpath path |
|
187 Specify where to find annotation processors; if this option is not used, the classpath will be searched for processors. |
|
188 .TP 3 |
|
189 \-s dir |
|
190 Specify the directory where to place generated source files. The directory must already exist; \f3javac\fP will not create it. If a class is part of a package, the compiler puts the source file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify \f3\-s /home/mysrc\fP and the class is called \f2com.mypackage.MyClass\fP, then the source file will be placed in \f2/home/mysrc/com/mypackage/MyClass.java\fP. |
206 .TP 3 |
191 .TP 3 |
207 \-source release |
192 \-source release |
208 Specifies the version of source code accepted. The following values for \f2release\fP are allowed: |
193 Specifies the version of source code accepted. The following values for \f2release\fP are allowed: |
209 .RS 3 |
194 .RS 3 |
210 .TP 3 |
195 .TP 3 |
213 .TP 3 |
198 .TP 3 |
214 1.4 |
199 1.4 |
215 The compiler accepts code containing assertions, which were introduced in JDK 1.4. |
200 The compiler accepts code containing assertions, which were introduced in JDK 1.4. |
216 .TP 3 |
201 .TP 3 |
217 1.5 |
202 1.5 |
218 The compiler accepts code containing generics and other language features introduced in JDK 5. This is the default. |
203 The compiler accepts code containing generics and other language features introduced in JDK 5. |
219 .TP 3 |
204 .TP 3 |
220 5 |
205 5 |
221 Synonym for 1.5 |
206 Synonym for 1.5. |
222 .RE |
207 .TP 3 |
223 \f3Note:\fP No language changes were introduced in JDK 6, so the values \f31.6\fP and \f36\fP are not valid. |
208 1.6 |
|
209 This is the default value. No language changes were introduced in Java SE 6. However, encoding errors in source files are now reported as errors, instead of warnings, as previously. |
|
210 .TP 3 |
|
211 6 |
|
212 Synonym for 1.6. |
|
213 .TP 3 |
|
214 1.7 |
|
215 The compiler accepts code with features introduced in JDK 7. |
|
216 .TP 3 |
|
217 7 |
|
218 Synonym for 1.7. |
|
219 .RE |
224 .TP 3 |
220 .TP 3 |
225 \-sourcepath sourcepath |
221 \-sourcepath sourcepath |
226 Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by colons (\f3:\fP) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name. |
222 Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by colons (\f3:\fP) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name. |
227 .LP |
223 .LP |
228 \f3Note:\fP \ Classes found through the classpath are subject to automatic recompilation if their sources are found. |
224 \f3Note:\fP \ Classes found through the classpath may be subject to automatic recompilation if their sources are also found. See Searching For Types. |
229 .TP 3 |
225 .TP 3 |
230 \-verbose |
226 \-verbose |
231 Verbose output. This includes information about each class loaded and each source file compiled. |
227 Verbose output. This includes information about each class loaded and each source file compiled. |
|
228 .TP 3 |
|
229 \-version |
|
230 Print version information. |
232 .TP 3 |
231 .TP 3 |
233 \-X |
232 \-X |
234 Display information about non\-standard options and exit. |
233 Display information about non\-standard options and exit. |
235 .RE |
234 .RE |
236 |
235 |
246 By default, classes are compiled against the bootstrap and extension classes of the platform that \f3javac\fP shipped with. But \f3javac\fP also supports \f2cross\-compiling\fP, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is important to use \f3\-bootclasspath\fP and \f3\-extdirs\fP when cross\-compiling; see Cross\-Compilation Example below. |
245 By default, classes are compiled against the bootstrap and extension classes of the platform that \f3javac\fP shipped with. But \f3javac\fP also supports \f2cross\-compiling\fP, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is important to use \f3\-bootclasspath\fP and \f3\-extdirs\fP when cross\-compiling; see Cross\-Compilation Example below. |
247 .LP |
246 .LP |
248 .RS 3 |
247 .RS 3 |
249 .TP 3 |
248 .TP 3 |
250 \-target version |
249 \-target version |
251 Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM. Valid targets are \f31.1\fP \f31.2\fP \f31.3\fP \f31.4\fP \f31.5\fP (also \f35\fP) and \f31.6\fP (also \f36\fP). |
250 Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM. Valid targets are \f31.1\fP \f31.2\fP \f31.3\fP \f31.4\fP \f31.5\fP (also \f35\fP) \f31.6\fP (also \f36\fP) and \f31.7\fP (also \f37\fP). |
252 .LP |
251 .LP |
253 The default for \f3\-target\fP depends on the value of \f3\-source\fP: |
252 The default for \f3\-target\fP depends on the value of \f3\-source\fP: |
254 .RS 3 |
253 .RS 3 |
255 .TP 2 |
254 .TP 2 |
256 o |
255 o |
257 If \-source is \f3not specified\fP, the value of \-target is \f31.6\fP |
256 If \-source is \f3not specified\fP, the value of \-target is \f31.6\fP |
258 .TP 2 |
257 .TP 2 |
259 o |
258 o |
260 If \-source is \f31.3\fP, the value of \-target is \f31.1\fP |
259 If \-source is \f31.2\fP, the value of \-target is \f31.4\fP |
|
260 .TP 2 |
|
261 o |
|
262 If \-source is \f31.3\fP, the value of \-target is \f31.4\fP |
261 .TP 2 |
263 .TP 2 |
262 o |
264 o |
263 For \f3all other values\fP of \-source, the value of \-target is the value of \f3\-source\fP. |
265 For \f3all other values\fP of \-source, the value of \-target is the value of \f3\-source\fP. |
264 .RE |
266 .RE |
265 .TP 3 |
267 .TP 3 |
330 .fl |
332 .fl |
331 System.out.println("2"); |
333 System.out.println("2"); |
332 .fl |
334 .fl |
333 } |
335 } |
334 .fl |
336 .fl |
|
337 |
|
338 .fl |
335 \fP |
339 \fP |
336 .fi |
340 .fi |
337 .RE |
341 .RE |
338 If the \f2\-Xlint:fallthrough\fP flag were used when compiling this code, the compiler would emit a warning about "possible fall\-through into case," along with the line number of the case in question. |
342 If the \f2\-Xlint:fallthrough\fP flag were used when compiling this code, the compiler would emit a warning about "possible fall\-through into case," along with the line number of the case in question. |
339 .TP 3 |
343 .TP 3 |
340 \-Xmaxerrors number |
344 \-Xmaxerrs number |
341 Set the maximum number of errors to print. |
345 Set the maximum number of errors to print. |
342 .TP 3 |
346 .TP 3 |
343 \-Xmaxwarns number |
347 \-Xmaxwarns number |
344 Set the maximum number of warnings to print. |
348 Set the maximum number of warnings to print. |
345 .TP 3 |
349 .TP 3 |
346 \-Xstdout filename |
350 \-Xstdout filename |
347 Send compiler messages to the named file. By default, compiler messages go to \f2System.err\fP. |
351 Send compiler messages to the named file. By default, compiler messages go to \f2System.err\fP. |
|
352 .TP 3 |
|
353 \-Xprefer:{newer,source} |
|
354 Specify which file to read when both a source file and class file are found for a type. (See Searching For Types). If \f2\-Xprefer:newer\fP is used, it reads the newer of the source or class file for a type (default). If the \f2\-Xprefer:source\fP option is used, it reads source file. Use \f2\-Xprefer:source\fP when you want to be sure that any annotation processors can access annotations declared with a retention policy of \f2SOURCE\fP. |
|
355 .TP 3 |
|
356 \-Xprint |
|
357 Print out textual representation of specified types for debugging purposes; perform neither annotation processing nor compilation. The format of the output may change. |
|
358 .TP 3 |
|
359 \-XprintProcessorInfo |
|
360 Print information about which annotations a processor is asked to process. |
|
361 .TP 3 |
|
362 \-XprintRounds |
|
363 Print information about initial and subsequent annotation processing rounds. |
348 .RE |
364 .RE |
349 |
365 |
350 .LP |
366 .LP |
351 .RE |
367 .RE |
352 .SS |
368 .SS |
456 .nf |
480 .nf |
457 \f3 |
481 \f3 |
458 .fl |
482 .fl |
459 % \fP\f3javac @path1/options @path2/classes\fP |
483 % \fP\f3javac @path1/options @path2/classes\fP |
460 .fl |
484 .fl |
461 .fi |
485 |
462 |
486 .fl |
|
487 .fi |
|
488 |
|
489 .LP |
|
490 .SH "ANNOTATION PROCESSING" |
|
491 .LP |
|
492 |
|
493 .LP |
|
494 .LP |
|
495 \f3javac\fP provides direct support for annotation processing, superseding the need for the separate annotation processing tool, \f3apt\fP. |
|
496 .LP |
|
497 .LP |
|
498 The API for annotation processors is defined in the \f2javax.annotation.processing\fP and \f2javax.lang.model\fP packages and subpackages. |
|
499 .LP |
|
500 .SS |
|
501 Overview of annotation processing |
|
502 .LP |
|
503 .LP |
|
504 Unless annotation processing is disabled with the \f3\-proc:none\fP option, the compiler searches for any annotation processors that are available. The search path can be specified with the \f3\-processorpath\fP option; if it is not given, the user class path is used. Processors are located by means of service provider\-configuration files named |
|
505 .br |
|
506 \f2\ META\-INF/services/javax.annotation.processing.Processor\fP |
|
507 .br |
|
508 on the search path. Such files should contain the names of any annotation processors to be used, listed one per line. Alternatively, processors can be specified explicitly, using the \f3\-processor\fP option. |
|
509 .LP |
|
510 .LP |
|
511 After scanning the source files and classes on the command line to determine what annotations are present, the compiler queries the processors to determine what annotations they process. When a match is found, the processor will be invoked. A processor may "claim" the annotations it processes, in which case no further attempt is made to find any processors for those annotations. Once all annotations have been claimed, the compiler does not look for additional processors. |
|
512 .LP |
|
513 .LP |
|
514 If any processors generate any new source files, another round of annotation processing will occur: any newly generated source files will be scanned, and the annotations processed as before. Any processors invoked on previous rounds will also be invoked on all subsequent rounds. This continues until no new source files are generated. |
|
515 .LP |
|
516 .LP |
|
517 After a round occurs where no new source files are generated, the annotation processors will be invoked one last time, to give them a chance to complete any work they may need to do. Finally, unless the \f3\-proc:only\fP option is used, the compiler will compile the original and all the generated source files. |
|
518 .LP |
|
519 .SS |
|
520 Implicitly loaded source files |
|
521 .LP |
|
522 .LP |
|
523 To compile a set of source files, the compiler may need to implicitly load additional source files. (See Searching For Types). Such files are currently not subject to annotation processing. By default, the compiler will give a warning if annotation processing has occurred and any implicitly loaded source files are compiled. See the \-implicit option for ways to suppress the warning. |
|
524 .LP |
|
525 .SH "SEARCHING FOR TYPES" |
|
526 .LP |
|
527 |
|
528 .LP |
|
529 .LP |
|
530 When compiling a source file, the compiler often needs information about a type whose definition did not appear in the source files given on the command line. The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance. |
|
531 .LP |
|
532 .LP |
|
533 For example, when you subclass \f3java.applet.Applet\fP, you are also using \f3Applet's\fP ancestor classes: \f3java.awt.Panel\fP, \f3java.awt.Container\fP, \f3java.awt.Component\fP, and \f3java.lang.Object\fP. |
|
534 .LP |
|
535 .LP |
|
536 When the compiler needs type information, it looks for a source file or class file which defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the \f3CLASSPATH\fP environment variable or by using the \f3\-classpath\fP command line option. (For details, see |
|
537 .na |
|
538 \f2Setting the Class Path\fP @ |
|
539 .fi |
|
540 http://java.sun.com/javase/6/docs/technotes/tools/index.html#classpath). |
|
541 .LP |
|
542 .LP |
|
543 If you set the \-sourcepath option, the compiler searches the indicated path for source files; otherwise the compiler searches the user class path for both class files and source files. |
|
544 .LP |
|
545 .LP |
|
546 You can specify different bootstrap or extension classes with the \f3\-bootclasspath\fP and \f3\-extdirs\fP options; see Cross\-Compilation Options below. |
|
547 .LP |
|
548 .LP |
|
549 A successful type search may produce a class file, a source file, or both. If both are found, you can use the \-Xprefer option to instruct the compiler which to use. If \f3newer\fP is given, the compiler will use the newer of the two files. If \f3source\fP is given, it will use the source file. The default is \f3newer\fP. |
|
550 .LP |
|
551 .LP |
|
552 If a type search finds a source file for a required type, either by itself, or as a result of the setting for \f3\-Xprefer\fP, the compiler will read the source file to get the information it needs. In addition, it will by default compile the source file as well. You can use the \-implicit option to specify the behavior. If \f3none\fP is given, no class files will be generated for the source file. If \f3class\fP is given, class files will be generated for the source file. |
|
553 .LP |
|
554 .LP |
|
555 The compiler may not discover the need for some type information until after annotation processing is complete. If the type information is found in a source file and no \f3\-implicit\fP option is given, the compiler will give a warning that the file is being compiled without being subject to annotation processing. To disable the warning, either specify the file on the command line (so that it will be subject to annotation processing) or use the \f3\-implicit\fP option to specify whether or not class files should be generated for such source files. |
463 .LP |
556 .LP |
464 .SH "PROGRAMMATIC INTERFACE" |
557 .SH "PROGRAMMATIC INTERFACE" |
465 .LP |
558 .LP |
|
559 |
|
560 .LP |
|
561 .LP |
|
562 \f3javac\fP supports the new Java Compiler API defined by the classes and interfaces in the \f2javax.tools\fP package. |
|
563 .LP |
|
564 .SS |
|
565 Example |
|
566 .LP |
|
567 .LP |
|
568 To perform a compilation using arguments as you would give on the command line, you can use the following: |
|
569 .LP |
|
570 .nf |
|
571 \f3 |
|
572 .fl |
|
573 JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); |
|
574 .fl |
|
575 int rc = javac.run(null, null, null, args); |
|
576 .fl |
|
577 |
|
578 .fl |
|
579 \fP |
|
580 .fi |
|
581 |
|
582 .LP |
|
583 .LP |
|
584 This will write any diagnostics to the standard output stream, and return the exit code that \f3javac\fP would give when invoked from the command line. |
|
585 .LP |
|
586 .LP |
|
587 You can use other methods on the \f2javax.tools.JavaCompiler\fP interface to handle diagnostics, control where files are read from and written to, and so on. |
|
588 .LP |
|
589 .SS |
|
590 Old Interface |
|
591 .LP |
|
592 .RS 3 |
|
593 |
|
594 .LP |
|
595 .LP |
|
596 \f3Note:\fP \ This API is retained for backwards compatibility only; all new code should use the Java Compiler API, described above. |
|
597 .LP |
466 .LP |
598 .LP |
467 The \f2com.sun.tools.javac.Main\fP class provides two static methods to invoke the compiler from a program: |
599 The \f2com.sun.tools.javac.Main\fP class provides two static methods to invoke the compiler from a program: |
468 .LP |
600 .LP |
469 .nf |
601 .nf |
470 \f3 |
602 \f3 |
471 .fl |
603 .fl |
472 public static int compile(String[] args); |
604 public static int compile(String[] args); |
473 .fl |
605 .fl |
474 public static int compile(String[] args, PrintWriter out); |
606 public static int compile(String[] args, PrintWriter out); |
475 .fl |
607 .fl |
|
608 |
|
609 .fl |
476 \fP |
610 \fP |
477 .fi |
611 .fi |
478 |
612 |
479 .LP |
613 .LP |
480 .LP |
614 .LP |
724 .LP |
873 .LP |
725 .RS 3 |
874 .RS 3 |
726 |
875 |
727 .LP |
876 .LP |
728 .LP |
877 .LP |
729 Here we use \f3javac\fP to compile code that will run on a 1.4 VM. |
878 Here we use \f3javac\fP to compile code that will run on a 1.7 VM. |
730 .LP |
879 .LP |
731 .RS 3 |
880 .RS 3 |
732 |
881 |
733 .LP |
882 .LP |
734 .nf |
883 .nf |
735 \f3 |
884 \f3 |
736 .fl |
885 .fl |
737 % \fP\f3javac \-target 1.4 \-bootclasspath jdk1.4.2/lib/classes.zip \\ |
886 % \fP\f3javac \-target 1.7 \-bootclasspath jdk1.7.0/lib/rt.jar \\ |
738 .fl |
887 .fl |
739 \-extdirs "" OldCode.java\fP |
888 \-extdirs "" OldCode.java\fP |
740 .fl |
889 .fl |
741 .fi |
890 |
742 .RE |
891 .fl |
743 |
892 .fi |
744 .LP |
893 .RE |
745 .LP |
894 |
746 The \f3\-target 1.4\fP option ensures that the generated class files will be compatible with 1.4 VMs. By default, \f3javac\fP compiles for JDK 6. |
895 .LP |
747 .LP |
896 .LP |
748 .LP |
897 The \f3\-target 1.7\fP option ensures that the generated class files will be compatible with 1.7 VMs. By default, \f3javac\fP compiles for JDK 6. |
749 The Java Platform JDK's \f3javac\fP would also by default compile against its own bootstrap classes, so we need to tell \f3javac\fP to compile against JDK 1.4 bootstrap classes instead. We do this with \f3\-bootclasspath\fP and \f3\-extdirs\fP. Failing to do this might allow compilation against a Java Platform API that would not be present on a 1.4 VM and would fail at runtime. |
898 .LP |
|
899 .LP |
|
900 The Java Platform JDK's \f3javac\fP would also by default compile against its own bootstrap classes, so we need to tell \f3javac\fP to compile against JDK 1.7 bootstrap classes instead. We do this with \f3\-bootclasspath\fP and \f3\-extdirs\fP. Failing to do this might allow compilation against a Java Platform API that would not be present on a 1.7 VM and would fail at runtime. |
750 .LP |
901 .LP |
751 .RE |
902 .RE |
752 .SH "SEE ALSO" |
903 .SH "SEE ALSO" |
753 .LP |
904 .LP |
754 |
905 |
755 .LP |
906 .LP |
756 .RS 3 |
907 .RS 3 |
757 .TP 2 |
908 .TP 2 |
758 o |
909 o |
759 java \- the Java Application Launcher |
910 .na |
760 .TP 2 |
911 \f2The javac Guide\fP @ |
761 o |
912 .fi |
762 jdb \- Java Application Debugger |
913 http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html |
763 .TP 2 |
914 .TP 2 |
764 o |
915 o |
765 javah \- C Header and Stub File Generator |
916 java(1) \- the Java Application Launcher |
766 .TP 2 |
917 .TP 2 |
767 o |
918 o |
768 javap \- Class File Disassembler |
919 jdb(1) \- Java Application Debugger |
769 .TP 2 |
920 .TP 2 |
770 o |
921 o |
771 javadoc \- API Documentation Generator |
922 javah(1) \- C Header and Stub File Generator |
772 .TP 2 |
923 .TP 2 |
773 o |
924 o |
774 jar \- JAR Archive Tool |
925 javap(1) \- Class File Disassembler |
|
926 .TP 2 |
|
927 o |
|
928 javadoc(1) \- API Documentation Generator |
|
929 .TP 2 |
|
930 o |
|
931 jar(1) \- JAR Archive Tool |
775 .TP 2 |
932 .TP 2 |
776 o |
933 o |
777 .na |
934 .na |
778 \f2The Java Extensions Framework\fP @ |
935 \f2The Java Extensions Framework\fP @ |
779 .fi |
936 .fi |