Table of contents
1. Standard parameters (starting with -)
6. -XX:MaxPermSize (Java 7 and before) or -XX:MaxMetaspaceSize (Java 8 and after):
2. Non-standard parameters (starting with -D)
1. Standard parameters (starting with -
)
1. -cp or -classpath:
-
Function: Specifies the search path for Java classes, that is, the class path.
-
Example:
java -cp /path/to/classes:/path/to/lib/* com.example.Main
2. -Xms:
-
Function: Set the initial heap size.
-
Example:
java -Xms256m -jar your-application.jar
3. -Xmx:
-
Function: Set the maximum heap size.
-
Example:
java -Xmx512m -jar your-application.jar
4. -Xmn:
-
Function: Set the size of the young generation.
-
Example:
java -Xmn256m -jar your-application.jar
5. -Xss:
-
Function: Set the stack size of each thread.
-
Example:
java -Xss1m -jar your-application.jar
6. -XX:MaxPermSize (Java 7 and before) or -XX:MaxMetaspaceSize (Java 8 and after):
-
Function: Set the maximum size of the permanent generation or metaspace.
-
Example (Java 7):
java -XX:MaxPermSize=256m -jar your-application.jar
Example (Java 8 and later):
java -XX:MaxMetaspaceSize=256m -jar your-application.jar
2. Non-standard parameters (starting with -D
)
1. -Dproperty=value:
-
Function: Set system properties.
-
Example:
java -Duser.timezone=UTC -jar your-application.jar
2. -Dfile.encoding:
-
Function: Set the default file encoding.
-
Example:
java -Dfile.encoding=UTF-8 -jar your-application.jar
3. -Djava.library.path:
-
Function: Set the search path for Java native libraries.
-
Example:
java -Djava.library.path=/path/to/libs -jar your-application.jar
4. -Dsun.java.command:
-
Effect: Show Java instruction.
-
Example:
java -Dsun.java.command=custom-command -jar your-application.jar
The above examples provide some common usage of startup parameters, but in fact, the usage of parameters will vary according to specific application scenarios and requirements. The settings of startup parameters should be adjusted and optimized according to the specific situation.