java程序启动参数 -D是用来做什么的呢?去查询了一下官方解释:

Set a system property value. If  value  is a string that contains spaces, you must enclose the string in double quotes:

java -Dfoo="some string" SomeClass

也就是说-D是用来在启动一个java程序时设置系统属性值的。如果该值是一个字符串且包含空格,那么需要包在一对双引号中。

何为系统属性值呢?也就是在System类中通过getProperties()得到的一串系统属性。

下面我们来写个测试方法就知道了!

/**
 * @author lmfeng
 * @date 2018/05/30
 */
public class SystemProperty {

    public static void main(String[] args){
        System.out.print(System.getProperty("dubbo.token"));
    }

}

在运行改程序时加上JVM参数-Ddubbo.token="666" 或者 -Ddubbo.token=666,那么运行之后你可以看到控制台输出了666!

一点值得注意的是,需要设置的是JVM参数而不是program参数,注意看下图

Logo

脑启社区是一个专注类脑智能领域的开发者社区。欢迎加入社区,共建类脑智能生态。社区为开发者提供了丰富的开源类脑工具软件、类脑算法模型及数据集、类脑知识库、类脑技术培训课程以及类脑应用案例等资源。

更多推荐