参考资料
java
命令用于启动 1 个 Java 应用,即启动一个 JVM 进程。
1 语法
java [_options_] _classname_ [_args_]
java [_options_] -jar _filename_ [_args_]
- options - 空格分隔的命令行选项详见 Options 部分.
- classname - 启动的类名(完整类型,例如: com.black.app.Bootstrap)
- filename - 启动 jar 包名,仅和
-jar
共同使用(jar 包中必须声名Main-Class
manifest header )。 - args - 启动类 main 方法参数,空格分隔
2 启动 Java 应用过程
java
命令启动 java 应用的过程:
- 启动 Java 运行环境(JRE)
- 加载声名的 class
- 调用声名的 class 的 main 方法,main 方法如下:
public static void main(String[] args)
java
命令也可以通过以下方式启动 JavaFx 应用:
- 要么加载一个启动类的 main 方法
- 要么加载继承
javafx.application.Application
的类:- 构建
javafx.application.Application
类的实例 - 调用该实例的 init() 方法
- 调用
start(javafx.stage.Stage)
方法
- 构建
3 选项
The java
command supports a wide range of options that can be divided into the following categories:
- Standard Options - JVM 实现必须支持的选项。
- Non-Standard Options - HotSpot VM 专有,以
-X
开头。 - Advanced Runtime Options - 开发者选项,用于调整 HotSpot VM,以
-XX
开头 - Advanced JIT Compiler Options - HotSpot VM 即时编译器选项
- Advanced Serviceability Options - 收集系统信息和执行调试
- Advanced Garbage Collection Options - 垃圾回收器选项
3.1 生产常用选项
java -cp /jdk/lib/*.jar;/jdk/jre/lib/* -Xms512m -Xmx1024m -Dspring.profiles.active=dev -XX:ErrorFile=/var/log/java/java_error.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/java/java_heapdump.hprof -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintCommandLineFlags -XX:+PrintTenuringDistribution -jar hello.jar
分类 | 选项 | 说明 |
---|---|---|
Standard Options | -cp <目录和 zip/jar 文件的类搜索路径> -classpath <目录和 zip/jar 文件的类搜索路径> |
指定加载的 zip或jar类搜索路径,用于查找加载的类 |
Standard Options | -D_property_=value | 代码里可通过 System.getProperties() 或System.getProperty(String key) 用例: -Dfoo="foo bar" |
Standard Options | -jar filename | 启动 jar 包,jar包内需包含声名 Main-Class manifest header |
Non-Standard Options | -Xms | jvm 堆最小内存 |
Non-Standard Options | -Xmx | jvm 堆最大内存 |
Non-Standard Options | -Xmn | jvm 堆年轻代大小 |
Advanced Runtime Options | -XX:ErrorFile=filename | 如果不指定会使用 TMP 环境变量目录,示例:-XX:ErrorFile=./hs_err_pid%p.log |
Advanced Serviceability Options | -XX:+HeapDumpOnOutOfMemoryError | 开启 oom dump |
Advanced Serviceability Options | -XX:HeapDumpPath=path | -XX:HeapDumpPath=/var/log/java/java_heapdump.hprof |
Advanced Garbage Collection Options | -XX:+PrintGC -XX:+PrintGCDetails |
打印每次 GC 详细信息 |
Advanced Runtime Options | -XX:+PrintCommandLineFlags | 打印命令行参数 |
Advanced Garbage Collection Options | -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps |
打印每次 GC的日期和时间 |
Advanced Garbage Collection Options | -XX:+PrintTenuringDistribution | 打印 tenuring age 信息 |
3.2 Standard Options
选项&默认值 | 说明 |
---|---|
-agentlib:libname[=options] | Loads the specified native agent library. After the library name, a comma-separated list of options specific to the library can be used. If the option -agentlib:foo is specified, then the JVM attempts to load the library named libfoo.so in the location specified by the LD_LIBRARY_PATH system variable (on OS X this variable is DYLD_LIBRARY_PATH ).The following example shows how to load the heap profiling tool (HPROF) library and get sample CPU information every 20 ms, with a stack depth of 3: -agentlib:hprof=cpu=samples,interval=20,depth=3 The following example shows how to load the Java Debug Wire Protocol (JDWP) library and listen for the socket connection on port 8000, suspending the JVM before the main class loads: -agentlib:jdwp=transport=dt_socket,server=y,address=8000 For more information about the native agent libraries, refer to the following: - The java.lang.instrument package description at [http://docs.oracle.com/javase/8/docs/api/java/lang/instrument/package-summary.html](http://docs.oracle.com/javase/8/docs/api/java/lang/instrument/package-summary.html) - Agent Command Line Options in the JVM Tools Interface guide at [http://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#starting](http://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#starting) |
-agentpath:pathname[=options] | Loads the native agent library specified by the absolute path name. This option is equivalent to -agentlib but uses the full path and file name of the library. |
-client | Selects the Java HotSpot Client VM. The 64-bit version of the Java SE Development Kit (JDK) currently ignores this option and instead uses the Server JVM. For default JVM selection, see Server-Class Machine Detection at [http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html](http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html) |
-D_property_=value |
Sets a system property value. The property variable is a string with no spaces that represents the name of the property. The value variable is a string that represents the value of the property. If value is a string with spaces, then enclose it in quotation marks (for example -Dfoo="foo bar" ). |
-d32 | Runs the application in a 32-bit environment. If a 32-bit environment is not installed or is not supported, then an error will be reported. By default, the application is run in a 32-bit environment unless a 64-bit system is used. |
-d64 | Runs the application in a 64-bit environment. If a 64-bit environment is not installed or is not supported, then an error will be reported. By default, the application is run in a 32-bit environment unless a 64-bit system is used. Currently only the Java HotSpot Server VM supports 64-bit operation, and the -server option is implicit with the use of -d64 . The -client option is ignored with the use of -d64 . This is subject to change in a future release. |
-disableassertions[:[packagename]...|:classname]或 -da[:[packagename]...|:classname] |
Disables assertions. By default, assertions are disabled in all packages and classes. With no arguments, -disableassertions (-da ) disables assertions in all packages and classes. With the packagename argument ending in ... , the switch disables assertions in the specified package and any subpackages. If the argument is simply ... , then the switch disables assertions in the unnamed package in the current working directory. With the classname argument, the switch disables assertions in the specified class.The -disableassertions (-da ) option applies to all class loaders and to system classes (which do not have a class loader). There is one exception to this rule: if the option is provided with no arguments, then it does not apply to system classes. This makes it easy to disable assertions in all classes except for system classes. The -disablesystemassertions option enables you to disable assertions in all system classes.To explicitly enable assertions in specific packages or classes, use the -enableassertions (-ea ) option. Both options can be used at the same time. For example, to run the MyClass application with assertions enabled in package com.wombat.fruitbat (and any subpackages) but disabled in class com.wombat.fruitbat.Brickbat , use the following command:java -ea:com.wombat.fruitbat... -da:com.wombat.fruitbat.Brickbat MyClass |
-disablesystemassertions -dsa |
Disables assertions in all system classes. |
-enableassertions[:[packagename]...|:classname] -ea[:[packagename]...|:classname] |
Enables assertions. By default, assertions are disabled in all packages and classes. With no arguments, -enableassertions (-ea ) enables assertions in all packages and classes. With the packagename argument ending in ... , the switch enables assertions in the specified package and any subpackages. If the argument is simply ... , then the switch enables assertions in the unnamed package in the current working directory. With the classname argument, the switch enables assertions in the specified class.The -enableassertions (-ea ) option applies to all class loaders and to system classes (which do not have a class loader). There is one exception to this rule: if the option is provided with no arguments, then it does not apply to system classes. This makes it easy to enable assertions in all classes except for system classes. The -enablesystemassertions option provides a separate switch to enable assertions in all system classes.To explicitly disable assertions in specific packages or classes, use the -disableassertions (-da ) option. If a single command contains multiple instances of these switches, then they are processed in order before loading any classes. For example, to run the MyClass application with assertions enabled only in package com.wombat.fruitbat (and any subpackages) but disabled in class com.wombat.fruitbat.Brickbat , use the following command:java -ea:com.wombat.fruitbat... -da:com.wombat.fruitbat.Brickbat MyClass |
-enablesystemassertions -esa |
Enables assertions in all system classes. |
-help -? |
Displays usage information for the java command without actually running the JVM. |
-jar filename | Executes a program encapsulated in a JAR file. The filename argument is the name of a JAR file with a manifest that contains a line in the form Main-Class:``classname that defines the class with the public static void main(String[] args) method that serves as your application's starting point.When you use the -jar option, the specified JAR file is the source of all user classes, and other class path settings are ignored.For more information about JAR files, see the following resources: - jar (1)- The Java Archive (JAR) Files guide at [http://docs.oracle.com/javase/8/docs/technotes/guides/jar/index.html](http://docs.oracle.com/javase/8/docs/technotes/guides/jar/index.html) - Lesson: Packaging Programs in JAR Files at [http://docs.oracle.com/javase/tutorial/deployment/jar/index.html](http://docs.oracle.com/javase/tutorial/deployment/jar/index.html) |
-javaagent:jarpath[=options] | Loads the specified Java programming language agent. For more information about instrumenting Java applications, see the java.lang.instrument package description in the Java API documentation at [http://docs.oracle.com/javase/8/docs/api/java/lang/instrument/package-summary.html](http://docs.oracle.com/javase/8/docs/api/java/lang/instrument/package-summary.html) |
-jre-restrict-search |
Includes user-private JREs in the version search. |
-no-jre-restrict-search | Excludes user-private JREs from the version search. |
-server | Selects the Java HotSpot Server VM. The 64-bit version of the JDK supports only the Server VM, so in that case the option is implicit. For default JVM selection, see Server-Class Machine Detection at [http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html](http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html) |
-showversion | Displays version information and continues execution of the application. This option is equivalent to the -version option except that the latter instructs the JVM to exit after displaying version information. |
-splash:imgname | Shows the splash screen with the image specified by imgname. For example, to show the splash.gif file from the images directory when starting your application, use the following option:<br>-splash:images/splash.gif<br> |
-verbose:class | Displays information about each loaded class. |
-verbose:gc | Displays information about each garbage collection (GC) event. |
-verbose:jni | Displays information about the use of native methods and other Java Native Interface (JNI) activity. |
-version | Displays version information and then exits. This option is equivalent to the -showversion option except that the latter does not instruct the JVM to exit after displaying version information. |
-version:release | Specifies the release version to be used for running the application. If the version of the java command called does not meet this specification and an appropriate implementation is found on the system, then the appropriate implementation will be used.The release argument specifies either the exact version string, or a list of version strings and ranges separated by spaces. A version string is the developer designation of the version number in the following form: 1. x.0_ u (where x is the major version number, and u is the update version number). A version range is made up of a version string followed by a plus sign (+ ) to designate this version or later, or a part of a version string followed by an asterisk (* ) to designate any version string with a matching prefix. Version strings and ranges can be combined using a space for a logical OR combination, or an ampersand (& ) for a logical AND combination of two version strings/ranges. For example, if running the class or JAR file requires either JRE 6u13 (1.6.0_13), or any JRE 6 starting from 6u10 (1.6.0_10), specify the following:-version:"1.6.0_13 1.6* & 1.6.0_10+" Quotation marks are necessary only if there are spaces in the release parameter. For JAR files, the preference is to specify version requirements in the JAR file manifest rather than on the command line. |
3.3 Non-Standard Options
选项 | 说明 |
---|---|
-X | Displays help for all available -X options. |
-Xbatch | Disables background compilation. By default, the JVM compiles the method as a background task, running the method in interpreter mode until the background compilation is finished. The -Xbatch flag disables background compilation so that compilation of all methods proceeds as a foreground task until completed.This option is equivalent to -XX:-BackgroundCompilation . |
-Xbootclasspath:path | Specifies a list of directories, JAR files, and ZIP archives separated by colons (
标签:set,Java,option,default,Tool,XX,java,size
From: https://www.cnblogs.com/lihw-study/p/18239235
相关文章
|