官方解析
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参数是用来设置一个系统属性,如果该值是一个字符串且包含空格,那么这个值需要包含到一对双引号中。
实例
代码如下,启动时加上JVM参数-Dcom.wenqi="12 空格 34"
public class TestJVMOptions {
public static void main(String[] args) {
System.out.println(System.getProperty("com.wenqi"));
}
}
输出
12 空格 34
经过简单的Demo我们就可以知道启动时加上-D的作用了。我们可以通过-D来设置系统的属性,代码中通过System.getProperty
方法就可以获取到这个属性,执行相应的业务代码了,这就很灵活方便了。
最后
以上就是纯情含羞草最近收集整理的关于为什么有的JVM启动参数加了-D的全部内容,更多相关为什么有内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复