Java命令行的执行参数

时间:2022-08-27 21:34:50

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.