2016-10-19 23 views
1

我想用javascript作为语言读取vert.x中的命令行参数。你能帮我解决这个问题吗?例如如何阅读如何读取Vertx中的命令行参数

arguments(arg1, arg2, arg3) 

vertx run example.js arg1 arg2 arg3 

回答

1

如果你用vertx run example.js那么verticle将被该类部署启动verticle:https://github.com/eclipse/vert.x/blob/master/src/main/java/io/vertx/core/Starter.java

Starter.java也将解析您的命令行参数和部署verticle。从Starter.java不支持命令行参数传递到Verticle。支持的命令行参数可以通过vertx run --help

将配置参数传递给Verticle的支持方式是命令行开关--conf

--conf <config> Specifies configuration that should be provided to the verticle. <config> should reference either a text file containing a valid JSON object which represents the configuration OR be a JSON string.

的配置PARAMS可以这样Vertx.currentContext().config().arg1

如何处理JavaScript的配置文档访问是在这里:http://vertx.io/docs/vertx-core/js/#_passing_configuration_to_a_verticle

+0

在java中它工作正常,但在使用中的JavaScript配置()抛出异常为未定义? – madz

+0

更改了javascript的答案 – haschibaschi