2016-10-28 80 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

非常感謝你! –

相關問題