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

读取方法

public class TestSystem {
	public static void main(String args[]) {
		System.out.println(System.getProperty("a.b.c"));
	}
}

在运行改程序时加上JVM参数-Da.b.c="1234",那么运行之后你可以看到控制台输出了1234!

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

这里的program arguments指的是main方法中的args数组~

posted @ 2019-03-01 16:19  guoruiak  阅读(1403)  评论(0编辑  收藏  举报