'Quarkus - Start web server on demand
There is a CLI application written in Quarkus, it works as follows:
$ quarkus-app --input Hello
Output: olleH
Now there should also be the possibility to call this via a REST. However, this server should only be stared if the argument "--server" is passed:
$ quarkus-app --server &
Listening on '127.0.0.1:7070'
$ curl http://127.0.0.1:7070/api/reverse?input=Hello
Output: olleH
Now how do I get the WebServer to start only on "--server"?
My code currently looks like this:
@QuarkusMain
class CommandLine : QuarkusApplication {
override fun run(vararg args: String?): Int {
val options: Options = Options()
options.addOption("i", "input", false, "Input to reverse")
options.addOption("s", "server", false, "Start server")
val parser: CommandLineParser = DefaultParser()
val cmd: CommandLine = parser.parse(options, args)
if (cmd.hasOption("server")) {
// TODO: Start server
} else if (cmd.hasOption("input")) {
println("Output: ${cmd.getOptionValue("input").toString().reversed()}")
}
return 0
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
