我仍然对vertx假设您将部署/启动应用程序的方式有一些误解。仍然有两个问题,但它们对我来说几乎没有关系。
问题1: 我有办法让你的应用程序可以从命令行和IDEA中启动吗?
一方面,有一个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");
}
}
答案 0 :(得分:1)
为了从IntelliJ运行您的应用程序,您需要做的就是在以下位置添加运行配置:
为了以编程方式设置配置,您需要按照javadocs中的说明将Json对象传递给部署选项。