简体   繁体   English

当我在 java 中声明自定义系统属性时会发生什么?

[英]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.

相关问题 操作系统(linux)如何杀死Java程序? 当我硬杀死一个Java进程时,jvm会怎样? - how operating system(linux) kills java program ? What happens to the jvm when I hard kill a java process? 如果我们只是在java中声明一个没有初始化的变量,会在内存中发生什么? - What happens in memory if we just declare a variable without initialization in java? Java:当我创建与API相同的程序包时会发生什么 - Java: What happens when I create the same package as API Java在构造函数中为成员分配数组参数时会发生什么? - Java what happens when I assign an array argument to a member in constructor? java-更改类时实例会发生什么? - java - what happens to instances when I change the class? java-当我在构造函数中调用方法时会发生什么? - java-What happens when I call a method in constructor? 当你声明一个对象时,堆上到底发生了什么? - What exactly happens on the heap when you declare an object? 当多个线程在Java中使用System.in上的Scanners时,stdin数据会发生什么? - What happens to stdin data when multiple threads are using Scanners on System.in in Java? 当Java系统检测到抛出Exception时会发生什么? - What's happens when Java system detects that Exception has been thrown? 在Java中使用System.set属性有什么问题? - What is wrong when using System.set property in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM