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参数,注意看下图

Java 命令行 -D

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

相关文章:

  • 2021-11-26
  • 2022-02-11
  • 2021-09-14
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2021-04-23
  • 2021-11-30
猜你喜欢
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-11-30
  • 2021-11-13
相关资源
相似解决方案