java -D 设置JVM系统属性

java -D

格式: java -D<name>=<value>
作用: Set a system property value. If value is a string that contains spaces, you must enclose the string in double quotes.
获取设置的值: System.getProperty(“name”)

示例:

package com.sheting.basic.utilities;

public class JavaD {

    public static void main(String[] args) {
        System.out.println("Hello World");
        System.out.println(System.getProperty("name"));
    }
}

输出所有的JVM属性

package com.sheting.basic.utilities;

import java.util.Properties;

public class PrintOutAllProperties {
    public static void main(String[] args) {
        Properties properties = System.getProperties();
        for (Object key : properties.keySet()) {
            System.out.println(key + " : " + properties.getProperty((String) key));
        }
    }
}

猜你喜欢

转载自blog.csdn.net/tb9125256/article/details/81427577