作者:david_zhang@sh 【转载时请以超链接形式标明文章】
https://www.cnblogs.com/david-zhang-index/p/16846493.html
参数太多,傻傻分不清楚,简单说
1,program arguments是main函数args[]参数
2,vm arguments是java环境变量
3,environment variable是jvm环境变量
看代码如何获取这些参数:
public class TestProgram { public static void main(String[] args) { // program arguments对应的args参数 for (String arg : args) { System.out.println(arg); } System.out.println("==============program arguments对应的args参数==============="); System.out.println(); // getProperty()获取java的环境变量 String value1 = System.getProperty("key1"); String value2 = System.getProperty("key2"); System.out.println("System.getProperty(\"key1\")----->" + value1); System.out.println("System.getProperty(\"key2\")----->" + value2); Properties properties = System.getProperties(); System.out.println("System.getProperties():=======>" + properties); System.out.println("==============getProperty()获取java的环境变量==============="); System.out.println(); // 获取运行jvm环境变量 System.getenv(); Map<String, String> getenv = System.getenv(); System.out.println("System.getenv():----->" + getenv); String env1 = System.getenv("env1"); String env2 = System.getenv("env2"); System.out.println("System.getenv(\"env1\")=======>" + env1); System.out.println("System.getenv(\"env2\")=======>" + env2); System.out.println("===============获取运行jvm环境变量==============="); System.out.println(); } }
-argu=111
-arge=222
==============program arguments对应的args参数===============
System.getProperty("key1")----->v1
System.getProperty("key2")----->v2
==============getProperty()获取java的环境变量===============
System.getenv("env1")=======>test
System.getenv("env2")=======>prod
==============获取运行jvm环境变量===============
参数设置
总结:
System.getProperty();
System.getProperties();
System.getenv();
标签:getProperty,System,getenv,environment,println,arguments,variable,out From: https://www.cnblogs.com/david-zhang-index/p/16846493.html