Using picocli with GraalVM's native-image tool
See original GitHub issueI 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. 😃
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:22 (15 by maintainers)
Top Results From Across the Web
Picocli on GraalVM: Blazingly Fast Command Line Apps
To build a native image of the program use the native-image utility located in the bin directory of the GraalVM distribution.
Read more >Build Great Native CLI Apps in Java with Graalvm and ... - InfoQ
Creating a Native Image. The native-image utility can take a Java application and compile it to a native image that can run as...
Read more >GitHub - remkop/picocli-native-image-demo
Windows Compiler Toolchain for Java 11. To build native images using the Java 11 version of GraalVM (19.3.0 and greater), install the Visual...
Read more >Native CLI with Picocli and GraalVM - DEV Community
It comes with the native-image tool can be installed on top of GraalVM to build natives executables from java bytecode. For this purpose, ......
Read more >How to build native CLI apps using Java, Maven, GraalVM ...
GraalVM Native Image. While this gives me a good command line utility built using Java and Picocli, Java applications are generally hard to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
An article that describes how to use the tool is here: https://github.com/remkop/picocli/wiki/Picocli-on-GraalVM:-Blazingly-Fast-Command-Line-Apps
Feedback welcome!
Another idea is to create an annotation processor that generates code (either java source code or byte code) for a class with picocli annotations such that the
CommandSpec
for the command(s) is created at compile time instead of with reflection at runtime.