Reputation: 45692
I still have some misunderstanding about the way vertx suppose you'll deploy/start yor app. Still there are two questions, but they are hardly related for me.
Question 1: I there a way to make your app launchable from both: command line and IDEA?
In one hand there is a Starter
class (provided by Vert.x) to launch our application from command line. It provides main
method for you. But if I launch it from shell I won't have an ability to debug it, right?
In other hand to lanch your app in IDEA you need to create main method manually. Also some features like configurations file are described only for command line way. I.e. java -jar target/my-first-app-1.0-SNAPSHOT-fat.jar -conf src/main/conf/my-application-conf.json
Question 2: How to set configuration file programmatically?
I have a ServerVerticle
, all questions there:
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");
}
}
Upvotes: 1
Views: 2156
Reputation: 5801
In order to run your application from IntelliJ all you need to do is to add a run configuration where:
In order to set the configuration programmatically you need to pass a Json object to your deployment options as explained on the javadocs.
Upvotes: 6