问题
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