2016-10-28 50 views
1

我仍然对vertx假设您将部署/启动应用程序的方式存在一些误解。还有两个问题,但它们几乎与我无关。Vert.x启动应用程序和配置文件的方式

问题1:我有一个方法,使来自您的应用程序被启动的:命令行和想法?

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

另一方面,要在IDEA中使用您的应用程序,您需要手动创建主要方法。另外some features like configurations file仅用于命令行方式。即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"); 
    } 


} 

回答

1

为了逃离的IntelliJ您的应用程序的所有你需要做的是增加一个运行配置,其中:

  • 主类:io.vertx.core.Launcher
  • 参数:运行ServerVerticle -conf /path/to/your/config.json

为了以编程方式设置配置,您需要将一个Json对象传递给您的部署选项,如javadocs中所述。

+0

非常感谢你! –

相关问题