/**
* 运行参数Program arguments, VM/系统变量arguments, 环境变量Environment variables示例
*/
public class ArgsDemoApp {
public static void main(String[] args) {
// 运行参数Program arguments
int len = args.length;
for (int i=0; i<len; i++) {
System.out.println(String.format( "args第%d参数值: %s", i+1, args[i]));
}
// args第1参数值: arg1_val11
// args第2参数值: arg2_val22
// VM/系统变量VM arguments
String vmarg1 = System.getProperty("vmarg1");
String vmarg2 = System.getProperty("vmarg2");
System.out.println("vmarg1: "+ vmarg1); // vmarg1: vmarg_val11
System.out.println("vmarg2: "+ vmarg2); // vmarg2: vmarg_val22
// 环境变量Environment variables
String env1 = System.getenv("env1"); // env1: val_11
String env2 = System.getenv("env2"); // env2: val_22
System.out.println("env1: "+ env1);
System.out.println("env2: "+ env2);
SpringApplication.run(ArgsDemoApp.class, args);
}
}
Eclipse运行参数Program arguments, VM/系统变量arguments, 环境变量Environment variables区别和使用(Idea同理)