Java命令引數 -D -classpath
阿新 • • 發佈:2019-02-07
比如下面的命令:
java -Dfile.encoding=UTF-8 -classpath /lib/* com.zhclab.web.Launcher file:/configuration/application-config.xml
-Dname=value
可以通過System.getProperty("file.encoding")得到UTF-8
而System的property是指Java虛擬機器的引數。
其中有一些standard的屬性:
Key | Meaning |
---|---|
"file.separator" |
Character that separates components of a file path. This is "/ \ " on Windows. |
"java.class.path" |
Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the path.separator property. |
"java.home" |
Installation directory for Java Runtime Environment (JRE) |
"java.vendor" |
JRE vendor name |
"java.vendor.url" |
JRE vender URL |
"java.version" |
JRE version number |
"line.separator" |
Sequence used by operating system to separate lines in text files |
"os.arch" |
Operating system architecture |
"os.name" |
Operating system name |
"os.version" |
Operating system version |
"path.separator" |
Path separator character used in java.class.path |
"user.dir" |
User working directory |
"user.home" |
User home directory |
"user.name" |
User account name |
-classpath
(1).何時需要使用-classpath:當你要編譯或執行的類引用了其它的類,但被引用類的.class檔案不在當前目錄下時,就需要通過-classpath來引入類(2).何時需要指定路徑:當你要編譯的類所在的目錄和你執行javac命令的目錄不是同一個目錄時,就需要指定原始檔的路徑(CLASSPATH是用來指定.class路徑的,不是用來指定.java檔案的路徑的)
-cp 是classpath的縮寫,也是用來設定搜尋class檔案的路徑。
最後的file:/configuration/application-config.xml是程式的命令列引數,在com.zhclab.web.Launcher類的main函式中可以用args[0]得到。
java啟動時還可以使用-Xss256K, -Xms768m, -Xdebug等引數配置JVM的屬性。-X開頭的是非標準的選項,各個虛擬機器廠商可以擁有自己獨有的選項。
作者:hongchangfirst