java - 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 “ 钥匙)。所以我无法检索我的参数。
解决方案
推荐阅读
- python - Python: Nested List is not replacing values correctly
- vue.js - tailwindcss - 垂直和水平的 div
- android - android studio .xml 中 imageview 和 textView 的自动建议
- python - 如何从 html 数据列表中创建多个数据框?
- python - 在 Jinja2 3.0.1 中注册自定义测试
- react-native - 如何使用 Detox 定位 Android 的 TimePicker 列?
- android - 由于异常活动,我们已阻止来自此设备的所有请求 - Flutter 应用上的 Firebase
- reactjs - React jsx没有在异步函数中返回我的按钮
- javascript - 如何更改 Electron 中使用的 html 文件?
- javascript - 当本地构建工作正常时heroku部署不起作用 - NodeJS超时