1. Java代码:
public class TestDPara { public static void main(String[] args) { String flag = System.getProperty("Para"); System.err.println(flag); } }
2. cmd命令:
java -DPara=sdfdsfdsfdsfsd TestDPara
执行命令后输出:sdfdsfdsfdsfsd
注意:-D和Para之间不能有空格
3. 使用多个参数,如Para、Para1
public class TestDPara { public static void main(String[] args) { String flag = System.getProperty("Para"); System.out.println(flag); String flag1 = System.getProperty("Para1"); System.out.println(flag1); } }
java -DPara=sdfdsfdsfdsfsd -DPara1=3434 TestDPara
执行命令后输出:
sdfdsfdsfdsfsd
3434