Thomas
Thomas

Reputation: 903

Picocli with long running Javalin Thread

I want to build a simple Javalin API and configure the HTTP port with a command line arg with Picocli. It looks a bit like this:

public class Main implements Runnable {

    @CommandLine.Option(names = {"-p", "--port"})
    int httpPort = 9080;

    public static void main(String... args) {
        int exitCode = new CommandLine(new Main()).execute(args);
        System.exit(exitCode);
    }

    @Override
    public void run() {
        Javalin.create()
            .get("/some/endpoint", new EndpointHandler())
            .start("0.0.0.0", httpPort);
    }
}

The problem is, that Picocli seems to start the Javalin thread and returns or exits immediatly. How can I either get Picocli to wait for Javalin or have Javalin block in such a way that my app does not exit instantly?

Upvotes: 0

Views: 164

Answers (1)

Thomas
Thomas

Reputation: 903

I think I found a solution. I just had to not exit the app after starting the Runnable/Callable. Like so:

public static void main(String... args) {
    new CommandLine(new Main()).execute(args);
}

Upvotes: 1

Related Questions