Java 程序命令行參數說明
啟動Java程序的方式有兩種:
# starts a Java virtual machine, loads the specified class, and invokes that class's main method java [options] class [arguments] # starts a Java virtual machine with a JAR file, which should contain a "Main-Class" attribute in the manifest file. # The "Main-Class" attribute defines the Java class to be launched java [options] -jar file [arguments]
Java 的標准參數
C:\Users\Mil>java Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) where options include: -d32 use a 32-bit data model if available -d64 use a 64-bit data model if available -server to select the "server" VM, the default VM is server. -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. 在linux下這個符號是 : -D<name>=<value> set a system property -verbose:[class|gc|jni] enable verbose output -version print product version and exit -version:<value> Warning: this feature is deprecated and will be removed in a future release. require the specified version to run -showversion print product version and continue (運行前輸出版本信息) -jre-restrict-search | -no-jre-restrict-search Warning: this feature is deprecated and will be removed in a future release. 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 with specified granularity 啟用斷言 -da[:<packagename>...|:<classname>] -disableassertions[:<packagename>...|:<classname>] disable assertions with specified granularity -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 -splash:<imagepath> show splash screen with specified image
關於-d32和-d64參數, 參考 http://www.oracle.com/technetwork/java/hotspotfaq-138619.html
The options -d32 and -d64 have been added to the Java launcher to specify whether the program is to be run in a 32 or 64-bit environment. On Solaris these correspond to the ILP32 and LP64 data models, respectively. Since Solaris has both a 32 and 64-bit J2SE implementation contained within the same installation of Java, you can specify either version. If neither -d32 nor -d64 is specified, the default is to run in a 32-bit environment.
Other Java commands (javac, javadoc, etc.) will rarely need to be executed in a 64-bit environment. However, the -d32/-d64 options may be passed to these commands and then on to the Java launcher using the established -J prefix option (eg: -J-d64).
All other platforms (Windows and Linux) contain separate 32 and 64-bit installation packages. If both packages are installed on a system, you select one or the other by adding the appropriate "bin" directory to your path. For consistency, the Java implementations on Linux accept the -d64 option.
Oracle Java 8 的擴展參數
C:\Users\M>java -X -Xmixed mixed mode execution (default) 設置-client模式虛擬機對使用頻率高的方式進行 Just-In-Time 編譯和執行,對其他方法使用解釋方式執行 -Xint interpreted mode execution only 設置-client模式下運行的虛擬機以解釋方式執行類的字節碼,不將字節碼編譯為本機碼 -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 -Xdiag show additional diagnostic messages -Xnoclassgc disable class garbage collection -Xincgc enable incremental garbage collection 啟動增量垃圾收集器,缺省是關閉的。增量垃圾收集器能減少偶然發生的長時間的垃圾回收造成的暫停時間。但增量垃圾收集器和應用程序並發執行,因此會占用部分CPU -Xloggc:<file> log GC status to a file with time stamps -Xbatch disable background compilation -Xms<size> set initial Java heap size 設置虛擬機可用內存堆的初始大小,缺省單位為字節,該大小為 1024 的整數倍並且要大於1MB,可用 k(K)或m(M)為單位來設置較大的內存數。初始堆大小為 2MB -Xmx<size> set maximum Java heap size 設置虛擬機內存堆的最大可用大小,缺省單位為字節。該值必須為 1024 整數倍,並且要大於 2MB。可用 k(K)或 m(M)為單位來設置較大的內存數。缺省堆最大值為 64MB -Xss<size> set java thread stack size 設置線程棧的大小,缺省單位為字節。與-Xmx 類似,也可用 K 或 M 來設置較大的值。通常操作系統分配給線程棧的缺省大小為 1MB -Xprof output cpu profiling data 輸出 CPU 運行時的診斷信息 -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. -XshowSettings show all settings and continue -XshowSettings:all show all settings and continue -XshowSettings:vm show all vm related settings and continue -XshowSettings:properties show all property settings and continue -XshowSettings:locale show all locale related settings and continue The -X options are non-standard and subject to change without notice.