Java Vert.x启动应用程序和配置文件的方式

Java Vert.x启动应用程序和配置文件的方式,java,vert.x,Java,Vert.x,我仍然对vertx部署/启动应用程序的方式有一些误解。还有两个问题,但对我来说几乎没有关系 问题1:我有办法让你的应用程序可以从命令行和IDEA两个方面启动吗 一方面,有一个类(由Vert.x提供)从命令行启动我们的应用程序。它为您提供main方法。但如果我从shell启动它,我就没有能力调试它,对吗 另一方面,若要在IDEA中使用你们的应用程序,你们需要手动创建main方法。也仅以命令行方式描述。即java-jar-target/my-first-app-1.0-SNAPSHOT-fat.ja

我仍然对vertx部署/启动应用程序的方式有一些误解。还有两个问题,但对我来说几乎没有关系

问题1:我有办法让你的应用程序可以从命令行和IDEA两个方面启动吗

一方面,有一个类(由Vert.x提供)从命令行启动我们的应用程序。它为您提供
main
方法。但如果我从shell启动它,我就没有能力调试它,对吗

另一方面,若要在IDEA中使用你们的应用程序,你们需要手动创建main方法。也仅以命令行方式描述。即
java-jar-target/my-first-app-1.0-SNAPSHOT-fat.jar-conf-src/main/conf/my-application-conf.json

问题2:如何以编程方式设置配置文件

我有一个
ServerVerticle
,所有问题都在那里:

public class ServerVerticle extends AbstractVerticle {

    //QUESTION 1: I need this method for IDEA debugging, but don't need when launch app from command line. How to be??
    public static void main(String[] args) {
        Consumer<Vertx> runner = vertx -> {
            try {
                vertx.deployVerticle("server.ServerVerticle", new DeploymentOptions());
            } catch (Throwable t) {
                t.printStackTrace();
            }
        };
        Vertx vertx = Vertx.vertx(new VertxOptions());
        runner.accept(vertx);
    }

    @Override
    public void start() {
        vertx.deployVerticle(...); //deploy another verticles
        //QUESTION 2: how to pass configuration file programmaticaly in vertx? I can parse json file with java I/O, but if some configs are used accross the whole app?
        vertx.createNetServer()
             .connectHandler(this::handleMessage)
             .listen(8080, "localhost");
    }
   

}
公共类ServerVerticle扩展了AbstractVerticle{
//问题1:我需要这个方法进行IDEA调试,但不需要在从命令行启动应用程序时使用。如何使用??
公共静态void main(字符串[]args){
消费者跑步者=顶点->{
试一试{
deployVerticle(“server.ServerVerticle”,newdeploymentoptions());
}捕获(可丢弃的t){
t、 printStackTrace();
}
};
Vertx Vertx=Vertx.Vertx(新的VertxOptions());
接受(vertx);
}
@凌驾
公开作废开始(){
vertx.deployVerticle(…);//部署另一个Verticle
//问题2:如何在vertx中传递配置文件ProgramMaticali?我可以用java I/O解析json文件,但是如果在整个应用程序中使用一些配置?
vertx.createNetServer()
.connectHandler(此::handleMessage)
.listen(8080,“本地主机”);
}
}

要从IntelliJ运行应用程序,只需添加一个运行配置,其中:

  • 主类:io.vertx.core.Launcher
  • 参数:运行ServerVerticle-conf/path/to/your/config.json
为了以编程方式设置配置,需要将Json对象传递给部署选项,如上所述