javac命令详解(下)
摘自http://blog.csdn.net/hudashi/article/details/7058999
javac命令详解(下)
-verbose
冗长输出。开启该参数,你将看到编译器编译java源码的详细过程。
比如,示例13:
D:\project\test>javac -cp lib\Util.zip -sourcepath src -verbose -d classes src\c
om\robin\*.java
[parsing started src\com\robin\Hello.java]
[parsing completed 31ms]
[parsing started src\com\robin\People.java]
[parsing completed 0ms]
[search path for source files: src]
[search path for class files: C:\jdk1.6.0\jre\lib\resources.jar,C:\jdk1.6.0\jre\
lib\rt.jar,C:\jdk1.6.0\jre\lib\sunrsasign.jar,C:\jdk1.6.0\jre\lib\jsse.jar,C:\jd
k1.6.0\jre\lib\jce.jar,C:\jdk1.6.0\jre\lib\charsets.jar,C:\jdk1.6.0\jre\classes,
C:\jdk1.6.0\jre\lib\ext\dnsns.jar,C:\jdk1.6.0\jre\lib\ext\localedata.jar,C:\jdk1
.6.0\jre\lib\ext\sunjce_provider.jar,C:\jdk1.6.0\jre\lib\ext\sunmscapi.jar,C:\jd
k1.6.0\jre\lib\ext\sunpkcs11.jar,lib\Util.zip]
[loading src\com\hubin\Util.java]
[parsing started src\com\hubin\Util.java]
[parsing completed 0ms]
[loading java\lang\Object.class(java\lang:Object.class)]
[loading java\lang\String.class(java\lang:String.class)]
[checking com.robin.Hello]
[loading java\lang\Thread.class(java\lang:Thread.class)]
[wrote classes\com\robin\Hello.class]
[checking com.robin.People]
[wrote classes\com\robin\People.class]
[checking com.hubin.Util]
[wrote classes\com\hubin\Util.class]
[total 578ms]
D:\project\test>javac -cp lib\Util.zip -sourcepath src -verbose -d classes src\com\robin\*.java
[parsing started src\com\robin\Hello.java]
[parsing completed 16ms]
[parsing started src\com\robin\People.java]
[parsing completed 0ms]
[search path for source files: src]
[search path for class files: C:\jdk1.6.0\jre\lib\resources.jar,C:\jdk1.6.0\jre\
lib\rt.jar,C:\jdk1.6.0\jre\lib\sunrsasign.jar,C:\jdk1.6.0\jre\lib\jsse.jar,C:\jd
k1.6.0\jre\lib\jce.jar,C:\jdk1.6.0\jre\lib\charsets.jar,C:\jdk1.6.0\jre\classes,
C:\jdk1.6.0\jre\lib\ext\dnsns.jar,C:\jdk1.6.0\jre\lib\ext\localedata.jar,C:\jdk1
.6.0\jre\lib\ext\sunjce_provider.jar,C:\jdk1.6.0\jre\lib\ext\sunmscapi.jar,C:\jd
k1.6.0\jre\lib\ext\sunpkcs11.jar,lib\Util.zip]
[loading src\com\hubin\Util.java]
[parsing started src\com\hubin\Util.java]
[parsing completed 0ms]
[loading java\lang\Object.class(java\lang:Object.class)]
[loading java\lang\String.class(java\lang:String.class)]
[checking com.robin.Hello]
[wrote classes\com\robin\Hello.class]
[checking com.robin.People]
[wrote classes\com\robin\People.class]
[checking com.hubin.Util]
[wrote classes\com\hubin\Util.class]
[total 172ms]
D:\project\test>javac -cp lib-classes -sourcepath src -verbose -d classes src\com\robin\*.java
[parsing started src\com\robin\Hello.java]
[parsing completed 47ms]
[parsing started src\com\robin\People.java]
[parsing completed 0ms]
[search path for source files: src]
[search path for class files: C:\jdk1.6.0\jre\lib\resources.jar,C:\jdk1.6.0\jre\
lib\rt.jar,C:\jdk1.6.0\jre\lib\sunrsasign.jar,C:\jdk1.6.0\jre\lib\jsse.jar,C:\jd
k1.6.0\jre\lib\jce.jar,C:\jdk1.6.0\jre\lib\charsets.jar,C:\jdk1.6.0\jre\classes,
C:\jdk1.6.0\jre\lib\ext\dnsns.jar,C:\jdk1.6.0\jre\lib\ext\localedata.jar,C:\jdk1
.6.0\jre\lib\ext\sunjce_provider.jar,C:\jdk1.6.0\jre\lib\ext\sunmscapi.jar,C:\jd
k1.6.0\jre\lib\ext\sunpkcs11.jar,lib-classes]
[loading lib-classes\com\hubin\Util.class]
[loading java\lang\Object.class(java\lang:Object.class)]
[loading java\lang\String.class(java\lang:String.class)]
[checking com.robin.Hello]
[wrote classes\com\robin\Hello.class]
[checking com.robin.People]
[wrote classes\com\robin\People.class]
[total 656ms]
非标准选项
-X
使用该参数,可以显示所有的非标准选项的有关信息。
示例14:
C:\Documents and Settings\hubin>javac -X
-Xlint Enable recommended warnings
-Xlint:{all,cast,deprecation,divzero,empty,unchecked,fallthrough,path,serial,f
inally,overrides,-cast,-deprecation,-divzero,-empty,-unchecked,-fallthrough,-pat
h,-serial,-finally,-overrides,none}Enable or disable specific warnings
-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
-Djava.ext.dirs=<dirs> Override location of installed extensions
-Djava.endorsed.dirs=<dirs>Override location of endorsed standards path
-Xmaxerrs <number> Set the maximum number of errors to print
-Xmaxwarns <number> Set the maximum number of warnings to print
-Xstdout <filename> Redirect standard output
-Xprint Print out a textual representation of specified typ
es
-XprintRounds Print information about rounds of annotation proces
sing
-XprintProcessorInfo Print information about which annotations a process
or is asked to process
-Xprefer:{source,newer} Specify which file to read when both a source file
and class file are found for an implicitly compiled class
These options are non-standard and subject to change without notice.
-Xline:{关键字列表}
通过该命令我们将看到你java源码文件的一些危险代码,关键字有:{all,cast,deprecation,divzero,empty,unchecked,fallthrough,path,serial,f
inally,overrides,-cast,-deprecation,-divzero,-empty,-unchecked,-fallthrough,-path,-serial,-finally,-overrides,none},没有"-"前缀的表示开启,有的该前缀的表示关闭,all表示开启所有,none表示都不开启。
示例16:
D:\project\test>javac -cp lib\Util.zip -sourcepath src -Xlint:all -d classes src\com\robin\*.java
src\com\robin\Hello.java:11: warning: [deprecation] destroy() in java.lang.Threa
d has been deprecated
t.destroy();
^
src\com\robin\Hello.java:12: warning: [divzero] division by zero
int i=1/0;
^
2 warnings
-Xstdout <filename>
javac命令信息输出流的默认将在当前控制台进行显示,我们可以用该参数进行重新定义。
比如,示例17:
D:\project\test>javac -cp lib\Util.zip -sourcepath src -verbose -Xstdout 1.log -
d classes src\com\robin\*.java
这样我们在1.log文件中将看到;
[parsing started src\com\robin\Hello.java]
[parsing completed 16ms]
[parsing started src\com\robin\People.java]
[parsing completed 0ms]
[search path for source files: src]
[search path for class files: C:\jdk1.6.0\jre\lib\resources.jar,C:\jdk1.6.0\jre\lib\rt.jar,C:\jdk1.6.0\jre\lib\sunrsasign.jar,C:\jdk1.6.0\jre\lib\jsse.jar,C:\jdk1.6.0\jre\lib\jce.jar,C:\jdk1.6.0\jre\lib\charsets.jar,C:\jdk1.6.0\jre\classes,C:\jdk1.6.0\jre\lib\ext\dnsns.jar,C:\jdk1.6.0\jre\lib\ext\localedata.jar,C:\jdk1.6.0\jre\lib\ext\sunjce_provider.jar,C:\jdk1.6.0\jre\lib\ext\sunmscapi.jar,C:\jdk1.6.0\jre\lib\ext\sunpkcs11.jar,lib\Util.zip]
[loading com\hubin\Util.class(com\hubin:Util.class)]
[loading java\lang\Object.class(java\lang:Object.class)]
[loading java\lang\String.class(java\lang:String.class)]
[checking com.robin.Hello]
[wrote classes\com\robin\Hello.class]
[checking com.robin.People]
[wrote classes\com\robin\People.class]
[total 204ms]
-Xmaxerrs <number>
设置最多显示多少条编译错误
-Xmaxwarns <number>
设置最多显示多少条编译警告
其他一些Xlint选项暂时还不知道什么意思,一般也用得比较少,就打住了。
-J选项
将选项传给 javac 调用的 java 启动器。例如, -J-Xms48m 将启动内存设为 48 兆字节。虽然它不以 -X 开头,但它并不是 javac 的‘标准选项’。用 -J 将选项传给执行用 Java 编写的应用程序的虚拟机是一种公共约定。
其他一些javac命令选项暂时还不知道什么意思,一般也用得比较少,就打住了。
另外附前面的示例所用的java源码文件:
src\com\robin\Hello.java文件
package com.robin;
import com.hubin.Util;
public class Hello{
native String getHelloStringFromJni();
People p=new People();
final static String str=Util.getString();
Hello()
{
Thread t=null;
t.start();
t.destroy();
int i=1/0;
long l=10;
int n=(int)l;
}
}
src\com\robin\Peole.java文件
package com.robin;
public class People
{
String name;
}
src\com\hubin\Util.java文件
package com.hubin;
public class Util{
public final static String getString()
{
return "Hi";
}
}