我对 vertx 假设您部署/启动应用程序的方式仍然有一些误解。还有两个问题,但它们与我几乎无关。
问题 1: 我有办法让您的应用程序可以从命令行和 IDEA 启动吗?
一方面,有一个Starter类(由 Vert.x 提供)可以从命令行启动我们的应用程序。它main为你提供了方法。但如果我从 shell 启动它,我将无法调试它,对吗?
另一方面,要在 IDEA 中启动您的应用程序,您需要手动创建 main 方法。此外,一些功能(例如配置文件)仅以命令行方式进行描述。IEjava -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");
}
}
Run Code Online (Sandbox Code Playgroud)