question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using picocli with GraalVM's native-image tool

See original GitHub issue

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. 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:22 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
remkopcommented, Oct 4, 2018

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!

2reactions
remkopcommented, Sep 26, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found