简体   繁体   中英

How to read command line arguments in Vertx

I am trying to read command line arguments in vert.x with javascript as language. Could you please help me on this. For example how to read

arguments(arg1, arg2, arg3)

vertx run example.js arg1 arg2 arg3

If you start your verticle with with vertx run example.js then the verticle will be deployed by this class: https://github.com/eclipse/vert.x/blob/master/src/main/java/io/vertx/core/Starter.java

Starter.java will also parse your command line arguments and deploy your verticle. It is not supported from Starter.java that the commandline arguments are passed through to the verticle. The supported command line arguments can be seen with vertx run --help

The supported way to pass configuration params to the verticle is the the commandline switch --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.

The config params can be accessed like this Vertx.currentContext().config().arg1

The documentation how to handle config in javascript is here: http://vertx.io/docs/vertx-core/js/#_passing_configuration_to_a_verticle

Looking for the same solution, I ended up to setting environment variables. I run the verticle with

VXPORT="4444" vertx run -cp xxxxx.jar path.to.MyClass

This is how I achieve: https://mihamina.rktmb.org/2019/06/vertx-command-line-parameters.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM