JDK工具 java命令詳解
一、查看用法
C:\>java -help
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
這個命令幫助是英文的,不知道JDK咋搞的,也不妨礙使用。
另外,這個命令的非標準選項也是很重要的,常常在JVM優(yōu)化配置方面很關鍵,可以參看本人的JVM參數配置文章。
C:\myproject>java -X
-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc:<file> log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs reduce use of OS signals by Java/VM (see documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.
二、實踐
老規(guī)矩,主要看看里面的參數(也叫開關)的使用。環(huán)境接著上篇javac的環(huán)境。
1、無參數情況
2、-cp
運行Java要使用類的全名來運行。如果遇到文件夾,則需要-cp設置到頂級包下面,例如
3、-D
設置一個系統(tǒng)屬性,在運行時候,可以通過System.getProperties()來獲取到。例如寫一段代碼:
package com.lavasoft;
import java.util.Properties;
/**
* 列舉系統(tǒng)的屬性
* User: leizhimin
* Date: 2008-11-12 21:25:08
*/
public class TestProperty {
public static void main(String[] args) {
//獲取系統(tǒng)屬性
Properties prop = System.getProperties();
//輸出所有到一個流上,
prop.list(System.out);
}
}
如果在運行的時候加上一個參數-DmyProp=999999999,注意,中間不要添加任何空格。這樣就相當于設置了一個系統(tǒng)屬性myProp,其值為999999999。
一旦通過-DmyProp=999999999設置了這個系統(tǒng)屬性,在程序中就可以獲取到這個屬性。
3、程序入參
是在運行的時候,給main方法傳遞參數。為了測試先寫一個測試類。
package com.lavasoft;
/**
* 測試main方法的入參
* User: leizhimin
* Date: 2008-11-12 21:46:21
*/
public class TestMainVar {
public static void main(String[] args) {
System.out.println("入參列表如下:");
for(String arg:args){
System.out.println(arg);
}
}
}
4、其他的選項
有關選擇 客戶端/服務端VM、版本、運行在哪個版本下、是否使用斷言等一些不常用的選項。還可以查看
5、-verbose[:class|gc|jni]
查看虛擬機內部動作。
posted on 2009-12-04 17:15
xzc 閱讀(18006)
評論(4) 編輯 收藏 所屬分類:
Java