1. 程式人生 > >javac命令詳解(下)

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"; } }