-
Notifications
You must be signed in to change notification settings - Fork 441
Closed
Labels
theme: codegenAn issue or change related to the picocli-codegen moduleAn issue or change related to the picocli-codegen moduletype: enhancement ✨
Milestone
Description
I have tried to use the AOT compilation with the GraalVM' native-image tool. I tried something similar to the example from the picocli documentation first, i.e.
public static void main(String[] args) {
CommandLine.run(new Example(), System.out, args);
}
This was unsuccessful as the compiled native executable did not seem to parse and bind the arguments to the commands fields. What did work though was to let picocli do the annotation processing in the JVM which generated the image, i.e. in a static field initializer:
private static final CommandLine CMD = new CommandLine(new Example());
public static void main(String[] args) {
CMD.parseWithHandlers(new CommandLine.RunLast(),
new CommandLine.DefaultExceptionHandler<List<Object>>(),
args);
}
I am posting this here so that others can benefit from it. It would be nice if you included instructions for using native-image with picocli into the documentation. :)
kravemir
Metadata
Metadata
Assignees
Labels
theme: codegenAn issue or change related to the picocli-codegen moduleAn issue or change related to the picocli-codegen moduletype: enhancement ✨