forked from shashankkumar/CodeRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
man.txt
executable file
·461 lines (305 loc) · 22.6 KB
/
man.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
javac(1) javac(1)
NAME
javac - Java programming language compiler
SYNOPSIS
javac [ options ] [ sourcefiles ] [ @argfiles ]
Arguments may be in any order.
options
Command-line options.
sourcefiles
One or more source files to be compiled (such as MyClass.java).
@argfiles
One or more files that lists options and source files. The -J options are not allowed in these files.
DESCRIPTION
The javac tool reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files.
There are two ways to pass source code filenames to javac:
o For a small number of source files, simply list the file names on the command line.
o For a large number of source files, list the file names in a file, separated by blanks or line breaks. Then use the list file name on the
javac command line, preceded by an @ character.
Source 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 MyClass would be written in a source file called MyClass.java and compiled into a bytecode
class file called MyClass.class.
Inner class definitions produce additional class files. These class files have names combining the inner and outer class names, such as
MyClass$MyInnerClass.class.
You should arrange source files in a directory tree that reflects their package tree. For example, if you keep all your source files in
/workspace, the source code for com.mysoft.mypack.MyClass should be in /workspace/com/mysoft/mypack/MyClass.java.
By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with -d
(see Options, below).
SEARCHING FOR TYPES
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.
For example, when you subclass java.applet.Applet, you are also using Applet's ancestor classes: java.awt.Panel, java.awt.Container,
java.awt.Component, and java.lang.Object.
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 CLASSPATH environment variable or by using the -classpath command line option. (For details, see Setting the Class Path).
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.
You can specify different bootstrap or extension classes with the -bootclasspath and -extdirs options; see Cross-Compilation Options below.
A successful type search may produce a class file, a source file, or both. Here is how javac handles each situation:
o Search produces a class file but no source file: javac uses the class file.
o Search produces a source file but no class file: javac compiles the source file and uses the resulting class file.
o Search produces both a source file and a class file: javac determines whether the class file is out of date. If the class file is out of
date, javac recompiles the source file and uses the updated class file. Otherwise, javac just uses the class file.
javac considers a class file out of date only if it is older than the source file.
Note: javac can silently compile source files not mentioned on the command line. Use the -verbose option to trace automatic compilation.
OPTIONS
The compiler has a set of standard options that are supported on the current development environment and will be supported in future releases. An
additional set of non-standard options are specific to the current virtual machine and compiler implementations and are subject to change in the
future. Non-standard options begin with -X.
Standard Options
-classpath classpath
Set the user class path, overriding the user class path in the CLASSPATH environment variable. If neither CLASSPATH or -classpath is
specified, the user class path consists of the current directory. See Setting the Class Path for more details.
If the -sourcepath option is not specified, the user class path is searched for both source files and class files.
As a special convenience, a class path element containing a basename of * is considered equivalent to specifying a list of all the files in
the directory with the extension .jar or .JAR (a java program cannot tell the difference between the two invocations).
For example, if directory foo contains a.jar and b.JAR, then the class path element foo/* is expanded to a A.jar:b.JAR, 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 * expands to a list of all the jar files in the current directory. The CLASSPATH 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 System.getenv("CLASSPATH").
-Djava.ext.dirs=directories
Override the location of installed extensions.
-Djava.endorsed.dirs=directories
Override the location of endorsed standards path.
-d directory
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, javac puts the class file in a subdirectory reflecting the package name, creating directo‐
ries as needed. For example, if you specify -d /home/myclasses and the class is called com.mypackage.MyClass, then the class file is
called /home/myclasses/com/mypackage/MyClass.class.
If -d is not specified, javac puts the class file in the same directory as the source file.
Note: The directory specified by -d is not automatically added to your user class path.
-deprecation
Show a description of each use or override of a deprecated member or class. Without -deprecation, javac shows the names of source files
that use or override deprecated members or classes. -deprecation is shorthand for -Xlint:deprecation.
-encoding encoding
Set the source file encoding name, such as EUC-JP and UTF-8.. If -encoding is not specified, the platform default converter is used.
-g Generate all debugging information, including local variables. By default, only line number and source file information is generated.
-g:none
Do not generate any debugging information.
-g:{keyword list}
Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
source
Source file debugging information
lines
Line number debugging information
vars
Local variable debugging information
-help
Print a synopsis of standard options.
-nowarn
Disable warning messages. This has the same meaning as -Xlint:none.
-source release
Specifies the version of source code accepted. The following values for release are allowed:
1.3
The compiler does not support assertions, generics, or other language features introduced after JDK 1.3.
1.4
The compiler accepts code containing assertions, which were introduced in JDK 1.4.
1.5
The compiler accepts code containing generics and other language features introduced in JDK 5. This is the default.
5 Synonym for 1.5
Note: No language changes were introduced in JDK 6, so the values 1.6 and 6 are not valid.
-sourcepath sourcepath
Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are sepa‐
rated by colons (:) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the direc‐
tory or archive must reflect the package name.
Note: Classes found through the classpath are subject to automatic recompilation if their sources are found.
-verbose
Verbose output. This includes information about each class loaded and each source file compiled.
-X Display information about non-standard options and exit.
Cross-Compilation Options
By default, classes are compiled against the bootstrap and extension classes of the platform that javac shipped with. But javac also supports
cross-compiling, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is
important to use -bootclasspath and -extdirs when cross-compiling; see Cross-Compilation Example below.
-target version
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 1.1 1.2 1.3 1.4 1.5 (also 5) and 1.6 (also 6).
The default for -target depends on the value of -source:
o If -source is not specified, the value of -target is 1.6
o If -source is 1.3, the value of -target is 1.1
o For all other values of -source, the value of -target is the value of -source.
-bootclasspath bootclasspath
Cross-compile 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.
-extdirs directories
Cross-compile against the specified extension directories. Directories is a colon-separated list of directories. Each JAR archive in the
specified directories is searched for class files.
Non-Standard Options
-Xbootclasspath/p:path
Prepend to the bootstrap class path.
-Xbootclasspath/a:path
Append to the bootstrap class path.
-Xbootclasspath/:path
Override location of bootstrap class files.
-Xlint
Enable all recommended warnings. In this release, all available warnings are recommended.
-Xlint:none
Disable all warnings not mandated by the Java Language Specification.
-Xlint:-xxx
Disable warning xxx, where xxx is one of the warning names supported for -Xlint:xxx, below
-Xlint:unchecked
Give more detail for unchecked conversion warnings that are mandated by the Java Language Specification.
-Xlint:path
Warn about nonexistent path (classpath, sourcepath, etc) directories.
-Xlint:serial
Warn about missing serialVersionUID definitions on serializable classes.
-Xlint:finally
Warn about finally clauses that cannot complete normally.
-Xlint:fallthrough
Check switch blocks for fall-through cases and provide 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 contain a break
statement:
switch (x) {
case 1:
System.out.println("1");
// No break; statement here.
case 2:
System.out.println("2");
}
If the -Xlint:fallthrough 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.
-Xmaxerrors number
Set the maximum number of errors to print.
-Xmaxwarns number
Set the maximum number of warnings to print.
-Xstdout filename
Send compiler messages to the named file. By default, compiler messages go to System.err.
The -J Option
-Joption
Pass option to the java launcher called by javac. For example, -J-Xms48m sets the startup memory to 48 megabytes. Although it does not
begin with -X, it is not a `standard option' of javac. It is a common convention for -J to pass options to the underlying VM executing
applications written in Java.
Note: CLASSPATH, -classpath, -bootclasspath, and -extdirs do not specify the classes used to run javac. Fiddling with the implementation
of the compiler in this way is usually pointless and always risky. If you do need to do this, use the -J option to pass through options to
the underlying java launcher.
COMMAND LINE ARGUMENT FILES
To shorten or simplify the javac command line, you can specify one or more files that themselves contain arguments to the javac command (except
-J options). This enables you to create javac commands of any length on any operating system.
An argument file can include javac options and source filenames in any combination. The arguments within a file can be space-separated or new‐
line-separated. If a filename contains embedded spaces, put the whole filename in double quotes.
Filenames within an argument file are relative to the current directory, not the location of the argument file. Wildcards (*) are not allowed in
these lists (such as for specifying *.java). Use of the '@' character to recursively interpret files is not supported. The -J options are not
supported because they are passed to the launcher, which does not support argument files.
When executing javac, pass in the path and name of each argument file with the '@' leading character. When javac encounters an argument beginning
with the character `@', it expands the contents of that file into the argument list.
Example - Single Arg File
You could use a single argument file named "argfile" to hold all javac arguments:
C:> javac @argfile
This argument file could contain the contents of both files shown in the next example.
Example - Two Arg Files
You can create two argument files -- one for the javac options and the other for the source filenames: (Notice the following lists have no
line-continuation characters.)
Create a file named "options" containing:
-d classes
-g
-sourcepath \java\pubs\ws\1.3\src\share\classes
Create a file named "classes" containing:
MyClass1.java
MyClass2.java
MyClass3.java
You would then run javac with:
% javac @options @classes
Example - Arg Files with Paths
The argument files can have paths, but any filenames inside the files are relative to the current working directory (not path1 or path2):
% javac @path1/options @path2/classes
PROGRAMMATIC INTERFACE
The com.sun.tools.javac.Main class provides two static methods to invoke the compiler from a program:
public static int compile(String[] args);
public static int compile(String[] args, PrintWriter out);
The args parameter represents any of the command line arguments that would normally be passed to the javac program and are outlined in the above
Synopsis section.
The out parameter indicates where the compiler's diagnostic output is directed.
The return value is equivalent to the exit value from javac.
Note that all other classes and methods found in a package whose name starts with com.sun.tools.javac (informally known as sub-packages of
com.sun.tools.javac) are strictly internal and subject to change at any time.
EXAMPLES
Compiling a Simple Program
One source file, Hello.java, defines a class called greetings.Hello. The greetings directory is the package directory both for the source file
and the class file and is off the current directory. This allows us to use the default user class path. It also makes it unnecessary to spec‐
ify a separate destination directory with -d.
% ls
greetings/
% ls greetings
Hello.java
% cat greetings/Hello.java
package greetings;
public class Hello {
public static void main(String[] args) {
for (int i=0; i < args.length; i++) {
System.out.println("Hello " + args[i]);
}
}
}
% javac greetings/Hello.java
% ls greetings
Hello.class Hello.java
% java greetings.Hello World Universe Everyone
Hello World
Hello Universe
Hello Everyone
Compiling Multiple Source Files
This example compiles all the source files in the package greetings.
% ls
greetings/
% ls greetings
Aloha.java GutenTag.java Hello.java Hi.java
% javac greetings/*.java
% ls greetings
Aloha.class GutenTag.class Hello.class Hi.class
Aloha.java GutenTag.java Hello.java Hi.java
Specifying a User Class Path
Having changed one of the source files in the previous example, we recompile it:
% pwd
/examples
% javac greetings/Hi.java
Since greetings.Hi refers to other classes in the greetings package, the compiler needs to find these other classes. The example above works,
because our default user class path happens to be the directory containing the package directory. But suppose we want to recompile this file
and not worry about which directory we're in? Then we need to add /examples to the user class path. We can do this by setting CLASSPATH, but
here we'll use the -classpath option.
% javac -classpath /examples /examples/greetings/Hi.java
If we change greetings.Hi again, to use a banner utility, that utility also needs to be accessible through the user class path.
% javac -classpath /examples:/lib/Banners.jar \
/examples/greetings/Hi.java
To execute a class in greetings, we need access both to greetings and to the classes it uses.
% java -classpath /examples:/lib/Banners.jar greetings.Hi
Separating Source Files and Class Files
It often makes sense to keep source files and class files in separate directories, especially on large projects. We use -d to indicate the
separate class file destination. Since the source files are not in the user class path, we use -sourcepath to help the compiler find them.
% ls
classes/ lib/ src/
% ls src
farewells/
% ls src/farewells
Base.java GoodBye.java
% ls lib
Banners.jar
% ls classes
% javac -sourcepath src -classpath classes:lib/Banners.jar \
src/farewells/GoodBye.java -d classes
% ls classes
farewells/
% ls classes/farewells
Base.class GoodBye.class
Note: The compiler compiled src/farewells/Base.java, even though we didn't specify it on the command line. To trace automatic compiles, use
the -verbose option.
Cross-Compilation Example
Here we use javac to compile code that will run on a 1.4 VM.
% javac -target 1.4 -bootclasspath jdk1.4.2/lib/classes.zip \
-extdirs "" OldCode.java
The -target 1.4 option ensures that the generated class files will be compatible with 1.4 VMs. By default, javac compiles for JDK 6.
The Java Platform JDK's javac would also by default compile against its own bootstrap classes, so we need to tell javac to compile against JDK
1.4 bootstrap classes instead. We do this with -bootclasspath and -extdirs. 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.
SEE ALSO
o java - the Java Application Launcher
o jdb - Java Application Debugger
o javah - C Header and Stub File Generator
o javap - Class File Disassembler
o javadoc - API Documentation Generator
o jar - JAR Archive Tool
o The Java Extensions Framework @
http://java.sun.com/javase/6/docs/technotes/guides/extensions/index.html
07 Aug 2006 javac(1)