注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

民主与科学

独立之人格,自由之思想

 
 
 

日志

 
 

javac命令详解(下)  

2011-06-18 15:59:08|  分类: JDK命令 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

-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";
}
}
  评论这张
 
阅读(1133)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017