Dropwizard command line input

心已入冬 提交于 2021-01-27 20:07:27

问题


We have been using Dropwizard to create HTTP service. Usually the syntax would look like

java -jar {path_to_jar} server config.yml

This spins of HTTP server internally using ServerCommand of dropwizard. But, as for the new requirement we need it to support another command line input preferrably the first input of the run. Say,

java -jar {path_to_jar} path_to_file server config.yml
                    (or at least)
java -jar {path_to_jar} server config.yml path_to_file

I know dropwizard supports custom command input like

  java -jar {path_to_jar} hello -u world

The trick here is we need to support command input along with HTTP server, the documents fails to address this requirement. Is it even possible with dropwizard?.

Note: Adding this parameter to config.yml is not an option. As this parameter is supplied from outside to which we don't want to expose our yml file.


回答1:


Since you have full control over the public void static main(String[] args) method, you can do whatever additional processing you want there and pass it to the application.

Before you go down that route however, can your requirement be addressed using environmental variables in the config file? http://www.dropwizard.io/1.1.0/docs/manual/core.html#environment-variables



来源:https://stackoverflow.com/questions/43692751/dropwizard-command-line-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!