2016-10-19 65 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