java命令行,无法从代码中检索命令行参数

时间:2018-05-25 08:42:43

标签: java

我想检索从命令行传递的一些参数。 问题是它没有按预期工作:

java -jar target/gs-rest-service-0.1.0.jar -Dhello=hello

System.out.println(System.getProperties()); // return a propertie obj with Dhello parameter inside.

所以现在,当我试图获得价值时:

  System.getProperties().getProperty("hello")); // return null
    System.getProperties().getProperty("-Dhello")); // return null 
    System.getProperty("hello"); // return null 
    System.getProperty("-Dhello")); // return null

我从2小时开始与之抗争。这开始令人生气。

注意: 这不起作用,因为Java cl不能将参数作为属性传递。所以不是给我一个键/值hello = hello,而是给我一个没有分离的完整命令:target / gs-rest-service-0.1.0.jar -Dhello = hello(我从" sun获得)。 java.command" key)。所以我无法检索我的参数。

0 个答案:

没有答案
相关问题