Dowemo

The java c command uses and compiles the java source file, as follows:


javac [ options ] [ sourcefiles ] [ @files ]






Parameters can be arranged in any order.
Options option.
Sourcefiles one or more source files to compile ( for example, MyClass.java ).
A @ files one or more files to list a source file.
There are two ways to pass source code file names to javac:
One is through the sourcefiles parameter, directly given the source file to compile
If the number of source files is fewer, you can use this method to list the file names on the command line. Files and files aren't separated by spaces.
Instance 1


javac -d classes srccomrobinHello.java srccomrobinPeople.java srccomhubinUtil.java






In fact, the source file is a separate parameter, and if the file path includes spaces, you can enclose the file name in double quotation marks.
For example, the above command can be written as follows:
Example 2


javac -d classes"srccomrobinHello.java""srccomrobinPeople.java""srccomhubinUtil.java"






In cases where a semicolon isn't used, the java source file under the same path can be used by a string character, such as example 1.
Example 3


javac -d classes srccomrobin*.java srccomhubinUtil.java






One is through @ files.
To shorten or simplify the java c command, you can place the java source file that you want to compile in a file, with a space or a carriage return between the file names. In the java c command line, you can use the"@"character to include the file name to compile the java source file name to specify the java source file to compile. Because java c is encountered with a"`"character, it compiles all the java source files listed in the file after that word. This form applies to many cases of java source files.
For example, we include the source file name to compile for example 1 in the src. Txt file.
Example 4
Src. Txt file:


srccomrobinHello.java srccomrobinPeople.java


srccomhubinUtil.java






Then run the following java c command:


javac -d classes @src.txt






Of course, we can enclose a single java source file to be compiled with double quotes in src. Txt.
But in the way the path is,"""".
Example 5
Src. Txt file.


"srccomrobinHello.java""srccomrobinPeople.java"


"srccomhubinUtil.java"






At this point the java c command still has the same example 3.
Command option options
Path
-d directory
This option specifies the directory of the generated class target file. If a class is part of a package, javac places the class file in a subdirectory that reflects the package name and creates a directory if necessary. For example, the class target directory in example 1 is placed under classes, hello. Class and people. Class at classescomrobin, under, util is located under classescomhubin directory.
If the -d option isn't specified, javac places the class file in the same directory as the source file.
Note: the directory specified by the -d option isn't automatically added to the user class path.
-bootclasspath, -extdirs, classpath and cp
When the jdk compiles a java source file, the way to search for class files is as follows:
Class bootstrap, extension classes, user classes
By default, bootstrap is a jar or zip file that comes with the jdk, which includes files such as rt. Jar, and the jdk first searches for these files.
It can be set through bootclasspath. To divide between files.
Extension defaults to the jar file located under the jre"lib"ext directory, and the jdk searches for the jar files under the directory after bootstrap.
Can be set by extdirs. To split between files.
User classes search order is the current directory, environment variable classpath, -classpath.
-cp and -classpath are synonyms, and the meaning is the same. The classpath parameter is too long, so providing cp as an abbreviation
They're used to tell jdk to search for a directory name, jar document name, zip document name, semicolon &.
For example, when you develop a common common class and wrap it into a common. Jar package, you need to tell the jdk from common. Jar to tell the jdk from common. Jar, otherwise the jdk throws a java exception indicating that the class definition isn't found.
After using the classpath, jdk will no longer use the class search path in the classpath, if the classpath and classpath aren't set, the jdk uses the current path.
It's recommended that you use classpath to define the class path that jdk searches, rather than using the path of the environment variable classpath to reduce the potential conflicts that exist when multiple projects use the classpath at the same time. For example, use the class g in a1. 0. Jar to apply 2 to the class g, a2. 0. Jar in the a2.0. jar, which is an upgrade to a1. 0. When the a2.0. jar is in the classpath, the jdk will stop searching if the virtual machine is searched from the classpath, and if all the virtual machines that apply it from the classpath search from the classpath.
Example 6:


 javac -classpath libUtil.zip -d classes srccomrobin*.java


 或 javac -cp libUtil.zip -d classes srccomrobin*.java






Example 7:


 javac -classpath classes -d classes srccomrobin*.java


 或javac -cp classes -d classes srccomrobin*.java






If you need to specify a specific storage path for each jar file, there are multiple wildcards.
-sourcepath java source file path
At compile time, the jdk requires two aspects, one is the path to the java source file, and a path to the class ( class ) file.
The path to the class file has already been introduced before you can set it through bootclasspath, -extdirs, classpath, and cp. The path to the java source file can be passed through
Sourcepath is set, by default, the same path as the classpath. In the compilation process, if you need a related java class, look for and compile in the java source file listed in sourcefiles or @ files first, if not found, find the java source. If the java source file is found in the sourcepath, there's no related class found in the class path, or the class found is located in the package file ( jar or zip ).
Or the class you're looking for isn't in the package file, but the source file is compiled with the file, and the source file is compiled, and the generated class file. Otherwise, it's possible to load the related classes directly without finding the java source file and finding the related classes to compile them. So you need to specify at least one java source file to compile. It doesn't specify the root directory of the java source file specified in sourecfiles or @ files. Like the class path, the java source path is delimited by a semicolon (; ), which can be the root of the class file, the jar archive, or zip archive.
Example 8:


javac -sourcepath src -d classes srccomrobinHello.java






Example 9:


javac -cp libUtil.zip -sourcepath src -d classes srccomrobin*.java






For more detailed information about compiling java source code for compiler, open verbose for detailed information on verbose memory, please refer to"java c
Source and target
-source version
When you've installed a version of the jdk from sun, the jdk contains several versions of the compiler. The source parameter is the compiler that specifies which version of the compiler compiles. If your java source doesn't conform to the specification of the compiler, you can't compile.
-target version
This command specifies that the generated class file will be guaranteed to be compatible with which version of the virtual machine. We can ensure that the generated class files can run on 1. 2 virtual machines via target 1.2, but 1. 1 virtual machines can't be guaranteed. Because the forward compatibility line of the java virtual machine, 1.5 virtual machines can certainly run the generated class files via target 1.2.
The default target version of each version compiler isn't the same.
For example:
A jdk1. 2 ve ion compiler supports target 1.1, -target 1.2, -target 1.3, -target 1.4, -target xe, -target stringer, which defaults to 1, 1.
A jdk1. 4 version compiler supports only target 1.4 and target 1.5.
A jdk1. 5 version compiler supports only target 1.5.
Example 10


javac -cp libUtil.zip -sourcepath src -source 1.2 -target 1.1 -d classes srccomrobin*.java


javac -cp libUtil.zip -sourcepath src -source 1.2 -target 1.3 -d classes srccomrobin*.java


javac -cp libUtil.zip -sourcepath src -source 1.2 -target 1.4 -d classes srccomrobin*.java


javac -cp libUtil.zip -sourcepath src -source 1.2 -target 1.5 -d classes srccomrobin*.java


javac -cp libUtil.zip -sourcepath src -source 1.2 -target 1.6 -d classes srccomrobin*.java


示例11


javac -cp libUtil.zip -sourcepath src -source 1.4 -target 1.4 -d classes srccomrobin*.java


javac -cp libUtil.zip -sourcepath src -source 1.4 -target 1.5 -d classes srccomrobin*.java






-deprecation
If the method or class of the class or class of the class or class used in the java source is overridden, then if you use this parameter, the details about this will be displayed.
Example 12:


D:projecttest>javac -cp libUtil.zip -sourcepath src -source 1.2 -target 1.6 -


d classes srccomrobin*.java


Note: srccomrobinHello.java uses or overrides a deprecated API.


Note: Recompile with -Xlint:deprecation for details.



D:projecttest>javac -cp libUtil.zip -sourcepath src -deprecation -d classes s


rccomrobin*.java


srccomrobinHello.java:11: warning: [deprecation] destroy() in java.lang.Threa


d has been deprecated


 t.destroy();


 ^


1 warning






-encoding
Set the source file encoding name, such as 0 8. If the -encoding option isn't specified, the platform default encoding is used.
-g
Generate all debugging information, including local variables. By default, only line number and source file information are generated.
-g: none
Don't generate any debugging information.
-g: % 7b list %
Generates only certain types of debugging information that's specified by a keyword list. Valid keywords are:
source
Source file debugging information
lines
Line number debugging information
vars
Local variable debugging information
-nowarn
Disable warning information.




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs