P. 1


|Views: 0|Likes:
Published by vvr777

More info:

Published by: vvr777 on Oct 28, 2013
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





javac - Java programming language compiler

1. oldal, összesen: 9

javac - Java programming language compiler
z z z z z z z

Synopsis Description Searching for Types Options Command Line Argument Files Examples See Also

javac [ options ] [ sourcefiles ] [ @argfiles ]

Arguments may be in any order.

Command-line options.

One or more source files to be compiled (such as MyClass.java).

One or more files that lists options and source files. The -J options are not allowed in these files.

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 file names to javac:

For a small number of source files, simply list the file names on the command line. 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).



If neither CLASSPATH or -classpath is specified. overriding the user class path in the CLASSPATH environment variable. then in the user class path (which by default is the current directory).Container. or both. OPTIONS The compiler has a set of standard options that are supported on the current development environment and will be supported in future releases. a source file.Component. when you subclass java. Otherwise. If the class file is out of date. see Cross-Compilation Options below. z z Note: javac can silently compile source files not mentioned on the command line. javac recompiles the source file and uses the updated class file. it looks for a source file or class file which defines the type.5. oldal.awt.11. the compiler searches the indicated path for source files. 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. Here is how javac handles each situation: z Search produces a class file but no source file: javac uses the class file. The compiler searches for class files first in the bootstrap and extension classes. The compiler needs type information for every class or interface used.Object.awt. összesen: 9 SEARCHING FOR TYPES When compiling a source file. java.javac . For example. (For details. see Setting the Class Path). Non-standard options begin with -X.lang. Search produces both a source file and a class file: javac determines whether the class file is out of date.Applet. javac considers a class file out of date only if it is older than the source file.awt.html 2010. javac just uses the class file. The user class path is defined by setting the CLASSPATH environment variable or by using the -classpath command line option.applet. the user class path consists of http://java. and java. you are also using Applet's ancestor classes: java.Java programming language compiler 2.sun. extended. the compiler often needs information about a type whose definition did not appear in the source files given on the command line. You can specify different bootstrap or extension classes with the -bootclasspath and -extdirs options. If you set the -sourcepath option. otherwise the compiler searches the user class path for both class files and source files. Use the verbose option to trace automatic compilation. Standard Options -classpath classpath Set the user class path.com/j2se/1. java. A successful type search may produce a class file.05. Search produces a source file but no class file: javac compiles the source file and uses the resulting class file. or implemented in the source file.0/docs/tooldocs/windows/javac. When the compiler needs type information. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance.Panel. .

Without deprecation. creating directories as needed. See Setting the Class Path for more details. -Djava. -g Generate all debugging information.Java programming language compiler 3. javac puts the class file in the same directory as the source file. oldal. then the class file is called c:\myclasses\com\mypackage\MyClass. including local variables. such as EUC-JP and UTF-8.html 2010. The destination directory must already exist. If -encoding is not specified. This has the same meaning as -Xlint:none. only line number and source file information is generated. -deprecation is shorthand for -Xlint:deprecation. For example. specified by a comma separated list of keywords.com/j2se/1. . the platform default converter is used.sun. javac will not create the destination directory. -Djava. -deprecation Show a description of each use or override of a deprecated member or class. javac shows the names of source files that use or override deprecated members or classes. -encoding encoding Set the source file encoding name. javac puts the class file in a subdirectory reflecting the package name. If a class is part of a package. If -d is not specified.dirs=directories Override the location of installed extensions. If the -sourcepath option is not specified.ext. the user class path is searched for both source files and class files.dirs=directories Override the location of endorsed standards path. összesen: 9 the current directory.MyClass.05. -d directory Set the destination directory for class files. -g:none Do not generate any debugging information.0/docs/tooldocs/windows/javac. 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.javac . Note: The directory specified by -d is not automatically added to your user class path. By default. if you specify -d c:\myclasses and the class is called com. http://java.5.endorsed.mypackage.class. -nowarn Disable warning messages. -g:{keyword list} Generate only some kinds of debugging information.11.

boot class path entries are separated by semicolons (. JAR archives. But javac also supports cross-compiling. the local path name within the directory or archive must reflect the package name. 1. which were introduced in JDK 1. 1. classes are compiled against the bootstrap and extension classes of the platform that javac shipped with.2 VMs. the default target is 1.3 VMs. http://java.1 or 1. see Cross-Compilation Example below.3 the compiler does not support assertions. 1.3. It is important to use bootclasspath and -extdirs when cross-compiling.4 and later.javac . Cross-Compilation Options By default. 1.4 Generate class files that will run on VMs in JDK 1.com/j2se/1. összesen: 9 -source release Specifies the version of source code accepted. Note: Classes found through the classpath are subject to automatic recompilation if their sources are found.5 the compiler accepts code containing generics and other language features introduced in JDK 5.2 Generate class files that will run on VMs in JDK 1.5.html 2010.1.1 VMs.4 the compiler accepts code containing assertions.2 and later. The compiler defaults to the version 5 behavior if the -source flag is not used. The default is to generate class files to be compatible with the JDK 5 VM. where classes are compiled against a bootstrap and extension classes of a different Java platform implementation.Java programming language compiler 4. -verbose Verbose output.5 -sourcepath sourcepath Specify the source code path to search for class or interface definitions.) and can be directories.11. 5 Synonym for 1. As with the user class path. but will not run on 1. 1. source path entries are separated by semicolons (.1 and later. -target version Generate class files that will work on VMs with the specified version.5 -bootclasspath bootclasspath Cross-compile against the specified set of boot classes.0/docs/tooldocs/windows/javac.3 Generate class files that will run on VMs in JDK 1. or ZIP archives. but will not run on 1.4. If packages are used.5 Generate class files that are compatible only with JDK 5 VMs. When the -source 1.3 and later. but will not run on 1.2 or 1. 1.sun.4 or lower option is used. JAR archives. . The versions supported by javac are: 1.4. or other language features introduced after JDK 1. or ZIP archives. This includes information about each class loaded and each source file compiled. 5 Synonym for 1. The following values for release are allowed: 1. oldal.1 Generate class files that will run on VMs in JDK 1. -X Display information about non-standard options and exit. generics. 1. As with the user class path.05.) and can be directories.

case 2: System. etc) directories. In this release.println("2"). -Xlint:-xxx Disable warning xxx.out. // No break.11. Fall-through cases are cases in a switch block. sourcepath. Directories is a semicolonseparated list of directories. all available warnings are recommended.println("1").0/docs/tooldocs/windows/javac. -Xlint:none Disable all warnings not mandated by the Java Language Specification.out. } http://java.javac . whose code does not include a break statement. -Xlint:path Warn about nonexistent path (classpath.html 2010. -Xbootclasspath/:path Override location of bootstrap class files.com/j2se/1. statement here. -Xlint:serial Warn about missing serialVersionUID definitions on serializable classes.sun. other than the last case in the block. allowing code execution to "fall through" from that case to the next case. -Xlint:fallthrough Check switch blocks for fall-through cases and provide a warning message for any that are found. below -Xlint:unchecked Give more detail for unchecked conversion warnings that are mandated by the Java Language Specification. Each JAR archive in the specified directories is searched for class files. összesen: 9 -extdirs directories Cross-compile against the specified extension directories. where xxx is one of the warning names supported for -Xlint:xxx. the code following the case 1 label in this switch block does not contain a break statement: switch (x) { case 1: System. -Xbootclasspath/a:path Append to the bootstrap class path.Java programming language compiler 5. -Xlint Enable all recommended warnings.05. .5. oldal. For example. Non-Standard Options -Xbootclasspath/p:path Prepend to the bootstrap class path. -Xlint:finally Warn about finally clauses that cannot complete normally.

Example . -Xmaxerrors number Set the maximum number of errors to print. The -J Option -Joption Pass option to the java launcher called by javac. When executing javac. For example. you can specify one or more files that themselves contain arguments to the javac command (except -J options). Fiddling with the implementation of the compiler in this way is usually pointless and always risky.Java programming language compiler 6. összesen: 9 If the -Xlint:fallthrough flag were used when compiling this code. it expands the contents of that file into the argument list. -classpath.5.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.sun. Use of the '@' character to recursively interpret files is not supported. not the location of the argument file. Example . Wildcards (*) are not allowed in these lists (such as for specifying *. The arguments within a file can be space-separated or newline-separated.05. Filenames within an argument file are relative to the current directory. -Xstdout filename Send compiler messages to the named file. The -J options are not supported because they are passed to the launcher. An argument file can include javac options and source filenames in any combination.11. COMMAND LINE ARGUMENT FILES To shorten or simplify the javac command line. pass in the path and name of each argument file with the '@' leading character. -bootclasspath. Although it does not begin with -X. the compiler would emit a warning about "possible fall-through into case. If you do need to do this. -J-Xms48m sets the startup memory to 48 megabytes. which does not support argument files. it is not a `standard option' of javac.com/j2se/1.html 2010. compiler messages go to System. It is a common convention for -J to pass options to the underlying VM executing applications written in Java.err.Two Arg Files http://java.javac . When javac encounters an argument beginning with the character `@'. Note: CLASSPATH. This enables you to create javac commands of any length on any operating system.java). . and -extdirs do not specify the classes used to run javac." along with the line number of the case in question. use the -J option to pass through options to the underlying java launcher. -Xmaxwarns number Set the maximum number of warnings to print. oldal.0/docs/tooldocs/windows/javac. By default.

java You would then run javac with: C:> javac @options @classes Example .java.com/j2se/1. i < args. } } } C:> javac greetings\Hello.) Create a file named "options" containing: -d classes -g -sourcepath \java\pubs\ws\1.java C:> dir greetings Hello.5.out.3\src\share\classes Create a file named "classes" containing: MyClass1. összesen: 9 You can create two argument files -.05. This allows us to use the default user class path.javac .Java programming language compiler 7.Hello World Universe Everyone Hello World Hello Universe Hello Everyone http://java.11. i++) { System. but any filenames inside the files are relative to the current working directory (not path1 or path2): C:> javac @path1\options @path2\classes EXAMPLES Compiling a Simple Program One source file.html 2010. defines a class called greetings. oldal.Hello.one for the javac options and the other for the source filenames: (Notice the following lists have no line-continuation characters. public class Hello { public static void main(String[] args) { for (int i=0.java package greetings.println("Hello " + args[i]).java MyClass3. C:> dir greetings/ C:> dir greetings Hello.java MyClass2. The greetings directory is the package directory both for the source file and the class file and is off the current directory. It also makes it unnecessary to specify a separate destination directory with -d.0/docs/tooldocs/windows/javac.length.Arg Files with Paths The argument files can have paths.java C:> java greetings. Hello.sun. .java C:> cat greetings\Hello.class Hello.

The example above works.11.java Since greetings.Java programming language compiler 8.jar \ src\farewells\GoodBye.java -d classes http://java.Hi refers to other classes in the greetings package.java C:> javac greetings\*.sun.jar \ \examples\greetings\Hi. especially on large projects.Hi again.class Aloha.java C:> dir lib Banners.lib\Banners. We use -d to indicate the separate class file destination.html 2010.05. C:>java -classpath \examples. that utility also needs to be accessible through the user class path.java GutenTag.Hi Separating Source Files and Class Files It often makes sense to keep source files and class files in separate directories.java C:> dir greetings Aloha.javac .class Hi.java Hi.java Hi.java Specifying a User Class Path Having changed one of the source files in the previous example. we recompile it: C:> cd \examples C:> javac greetings\Hi.\lib\Banners. C:> dir classes\ lib\ src\ C:> dir src farewells\ C:> dir src\farewells Base.jar C:> dir classes C:> javac -sourcepath src -classpath classes. Since the source files are not in the user class path. We can do this by setting CLASSPATH. 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. oldal. C:>javac -classpath \examples. .\lib\Banners. but here we'll use the -classpath option. C:>javac -classpath \examples \examples\greetings\Hi. we use -sourcepath to help the compiler find them.java If we change greetings. to use a banner utility.jar greetings. C:> dir greetings\ C:> dir greetings Aloha.java Hello.java Hello. összesen: 9 Compiling Multiple Source Files This example compiles all the source files in the package greetings.java To execute a class in greetings. we need access both to greetings and to the classes it uses. the compiler needs to find these other classes.java GoodBye.class Hello.5.class GutenTag.com/j2se/1.java GutenTag. because our default user class path happens to be the directory containing the package directory.0/docs/tooldocs/windows/javac.

oldal. even though we didn't specify it on the command line.class Note: The compiler compiled src\farewells\Base. SEE ALSO z z z z z z z java .zip \ -extdirs "" OldCode. The Java 2 SDK's javac would also by default compile against its own bootstrap classes.java.0/docs/tooldocs/windows/javac. % javac -target 1.API Documentation Generator jar . összesen: 9 C:> dir classes farewells\ C:> dir classes\farewells Base.the Java Application Launcher jdb .JAR Archive Tool The Java Extensions Framework Copyright © 2004 Sun Microsystems. so we need to tell javac to compile against JDK 1. Cross-Compilation Example Here we use javac to compile code that will run on a 1.4 bootstrap classes instead. .Java Application Debugger javah . By default.Java programming language compiler 9. To trace automatic compiles. All Rights Reserved. use the -verbose option. We do this with bootclasspath and -extdirs.4 VMs. javac compiles for JDK 5.11.4 option ensures that the generated class files will be compatible with 1.4.C Header and Stub File Generator javap .4 VM and would fail at runtime. Inc.html 2010.Class File Disassembler javadoc . Failing to do this might allow compilation against a Java 2 Platform API that would not be present on a 1.4 VM.com/j2se/1.05.4 -bootclasspath jdk1.java The -target 1.sun.5.2/lib/classes.javac .class GoodBye. Java Software http://java.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->