JVM 启动参数之 -D

最近在翻《java核心技术第十版》,看到第七章日志部分,说到java标准类库的logging日志时,说其配置文件可以指定成自己的配置文件,然后直接甩给我一串代码 -Djava.util.logging.config.file=configFile MainClass

???-D是什么?从来没用过!经过查找资料得知  -D是jvm启动时给系统参数赋值用的(可以是系统默认有的参数,也可以是自己定义的参数),这个过程会在jvm开始java应用程序之前执行。这个参数赋值也可以通过使用System.setProperty(key, value);来完成。

那么虚拟机默认的系统参数有哪些呢?可以通过如下方法来查看

package com.guangzhou.study.log;
 
import java.util.Properties;
import java.util.Set;
 
public class TestLogger {
 
    public static void main(String[] args) {
        Properties properties = System.getProperties();
        Set keys = properties.keySet();
        for (Object key : keys) {
            if (key instanceof String) {
                System.out.println("key :" + key + " and value  :" +   System.getProperty((String) key));
            }
        }
    }
 
}
执行结果如下:

key :java.runtime.name and value  :Java(TM) SE Runtime Environment
key :sun.boot.library.path and value  :C:\Program Files\Java\jdk1.8.0_181\jre\bin
key :java.vm.version and value  :25.181-b13
key :java.vm.vendor and value  :Oracle Corporation
key :java.vendor.url and value  :http://java.oracle.com/
key :path.separator and value  :;
key :java.vm.name and value  :Java HotSpot(TM) 64-Bit Server VM
key :file.encoding.pkg and value  :sun.io
key :user.country and value  :CN
key :user.script and value  :
key :sun.java.launcher and value  :SUN_STANDARD
key :sun.os.patch.level and value  :
key :java.vm.specification.name and value  :Java Virtual Machine Specification
key :user.dir and value  :E:\WorkSpaces\Study\Study
key :java.runtime.version and value  :1.8.0_181-b13
key :java.awt.graphicsenv and value  :sun.awt.Win32GraphicsEnvironment
key :java.endorsed.dirs and value  :C:\Program Files\Java\jdk1.8.0_181\jre\lib\endorsed
key :os.arch and value  :amd64
key :java.io.tmpdir and value  :C:\Users\ADMINI~1\AppData\Local\Temp\
key :line.separator and value  :
 
key :java.vm.specification.vendor and value  :Oracle Corporation
key :user.variant and value  :
key :os.name and value  :Windows 10
key :sun.jnu.encoding and value  :GBK
key :java.library.path and value  :C:\Program Files\Java\jdk1.8.0_181\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_181/bin/server;C:/Program Files/Java/jre1.8.0_181/bin;C:/Program Files/Java/jre1.8.0_181/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Java\jdk1.8.0_181\bin;C:\Program Files\Java\jdk1.8.0_181\jre\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;;E:\eclipse;;.
key :java.specification.name and value  :Java Platform API Specification
key :java.class.version and value  :52.0
key :sun.management.compiler and value  :HotSpot 64-Bit Tiered Compilers
key :os.version and value  :10.0
key :user.home and value  :C:\Users\Administrator
key :user.timezone and value  :
key :java.awt.printerjob and value  :sun.awt.windows.WPrinterJob
key :file.encoding and value  :UTF-8
key :java.specification.version and value  :1.8
key :java.class.path and value  :C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;E:\WorkSpaces\Study\Study\bin
key :user.name and value  :Administrator
key :java.vm.specification.version and value  :1.8
key :sun.java.command and value  :com.guangzhou.study.log.TestLogger
key :java.home and value  :C:\Program Files\Java\jdk1.8.0_181\jre
key :sun.arch.data.model and value  :64
key :user.language and value  :zh
key :java.specification.vendor and value  :Oracle Corporation
key :awt.toolkit and value  :sun.awt.windows.WToolkit
key :java.vm.info and value  :mixed mode
key :java.version and value  :1.8.0_181
key :java.ext.dirs and value  :C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
key :sun.boot.class.path and value  :C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\classes
key :java.vendor and value  :Oracle Corporation
key :file.separator and value  :\
key :java.vendor.url.bug and value  :http://bugreport.sun.com/bugreport/
key :sun.io.unicode.encoding and value  :UnicodeLittle
key :sun.cpu.endian and value  :little
key :sun.desktop and value  :windows
key :sun.cpu.isalist and value  :amd64
 

你可能感兴趣的:(jvm参数)