[英]What happens when I declare a custom system property in java?
Wondering what happens when I declare a custom property in java using -D command.想知道当我使用 -D 命令在 java 中声明自定义属性时会发生什么。 I came to know that other system properties are not stored, instead generated by JVM.我才知道其他系统属性没有存储,而是由 JVM 生成。 So what will happen to the property that I created?那么我创建的财产会发生什么? Can I use it next time while I compile the code without declaring again?下次编译代码时可以不用再声明吗?
example: java -D"custom_key"="custom_value" some_class例如:java -D"custom_key"="custom_value" some_class
System properties are evaluated at runtime only not at compilation time.系统属性仅在运行时评估,而不是在编译时评估。
public class SysProp {
public static void main(String[] args) {
System.out.println(System.getProperty("foo", "<foo not set>"));
}
}
java SysProp java SysProp
Output: <foo not set> Output:<foo 未设置>
java -Dfoo=bar java -Dfoo=bar
Output: bar Output:酒吧
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.