jbang
jbang copied to clipboard
Quarkus integration ignores command line args.
I want to be able to run a Quarkus application from either an IDE or JBang.
For example, this is runnable from an IDE, taking in my args into consideration, i.e. as ways of configuring the application:
//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.quarkus:quarkus-resteasy-jackson:2.0.1.Final
package com.example;
import io.quarkus.runtime.Quarkus;
import java.util.Arrays;
public class ExampleResource {
public static void main(String[] args) {
if (args == null || args.length == 0) {
throw new RuntimeException("No args present");
} else {
Arrays.stream(args).forEach(System.out::println);
}
Quarkus.run(args);
}
}
However, when running jbang ExampleResource.java quarkus.neo4j.uri=bolt://foo:7687 it completely goes around the main method and uses another launcher, and in the process, my arguments are lost.
so this is a leaky abstraction where jbang technically don't know what is the right Quarkus main class - you'll want to do what is explained in https://quarkus.io/guides/command-mode-reference
basically, add @QuarkusMain and implement QuarkusApplication ...
I'll try and see if I can somehow "convince " quarkus to use another main but at the moment you'll follow Quarks command mode.
actually you might want this:
@QuarkusMain
public class JavaMain {
public static void main(String... args) {
Quarkus.run(HelloWorldMain.class, args);
}
}
you will need a QuarkusApplication somehow?
If it is enough to add @QuarkusMain I'm fine with things. I don't want to implement or extend something.
I was just caught by surprise that when I run main like with plain Java in the end, I get what I want (Starting Quarkus and arguments), but not through JBang.
yeah atm the quarkus integration rewires the main method in the jar to the Quarkus default generated main - I might be able to pass this main class into quarkus and have it use that - so i'm not closing this issue just yet :)
Making the above implement QuarkusApplication will end with main in the end, not starting the Webserver or keeping it alive, haven't checked. That's suboptimal. Also arguments are not passed into Quarkus.run, neither when doing -Dquarkus.args=quarkus.neo4j.uri=bolt://foo:7687 or without the quarkus.args dance.
What I am after is a script that would bring a Quarkus REST application up, much like when running a packaged jar.
Not at computer atm but try "jbang init -t qrest myapp.java" does that generate what you are after ?
@michael-simons did you get what you needed?