Dropwizard 命令行输入 [英] Dropwizard command line input

查看:51
本文介绍了Dropwizard 命令行输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在使用 Dropwizard 创建 HTTP 服务.通常语法看起来像

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

java -jar {path_to_jar} server config.yml

使用 dropwizard 的 ServerCommand 在内部旋转 HTTP 服务器.但是,对于新要求,我们需要它支持另一个命令行输入,最好是运行的第一个输入.说,

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

我知道 dropwizard 支持像

I know dropwizard supports custom command input like

  java -jar {path_to_jar} hello -u world

这里的技巧是我们需要支持命令输入以及 HTTP 服务器,文档 未能满足此要求.甚至可以使用 dropwizard 吗?

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?.

注意:将此参数添加到 config.yml 不是一个选项.由于此参数是从外部提供的,我们不想将 yml 文件暴露给它.

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.

推荐答案

由于您可以完全控制 public void static main(String[] args) 方法,您可以进行任何额外的处理想要在那里并将其传递给应用程序.

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.

然而,在你走这条路之前,你的要求可以使用配置文件中的环境变量来解决吗?http://www.dropwizard.io/1.1.0/docs/manual/core.html#environment-variables

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

这篇关于Dropwizard 命令行输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆