Reputation: 69
I've been trying to get a hello world project working for a Picocli/GraalVM project. I'm on an M1 Mac running Montery, Java 11, and GraalVM 22.3. I followed he Picocli documentation, but get "unmatched argument" errors when trying to run the native image.
The program works fine by calling:
java -cp "picocli-4.7.0.jar:FocusStackCLI.jar" FSCLI hello
My Java code:
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
@Command(name = "fscli", version = "fscli 1.0", mixinStandardHelpOptions = true)
public class FSCLI implements Runnable{
@Parameters(paramLabel = "directory", description = "Directory containing images to focus stack")
private String directory;
@Override
public void run(){
System.out.println(directory);
}
public static void main(String[] args) {
int exitCode = new CommandLine(new FSCLI()).execute(args);
System.exit(exitCode);
}
}
My pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>FocusStackCLI</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- annotationProcessorPaths requires maven-compiler-plugin version 3.5 or higher -->
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.7.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.7.0</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
Created the native image by calling: Note - It won't let me staticly compile on Mac.
native-image -cp picocli-4.6.3.jar -jar FocusStackCLI.jar
Now when I try to run either of these, with or without arguments,
./FocuStackerCLI hello
./FocuStackerCLI FSCLI hello
I get this error:
Unmatched argument at index 0: 'hello'
Usage: picocli.AutoComplete [-hV] [@<filename>...]
Generates a bash completion script for the specified command class.
[@<filename>...] One or more argument files containing options.
-h, --help Show this help message and exit.
-V, --version Print version information and exit.
Exit Codes:
0 Successful program execution
1 Usage error: user input for the command was incorrect, e.g., the wrong
number of arguments, a bad flag, a bad syntax in a parameter, etc.
2 The specified command script exists (Specify `--force` to overwrite).
3 The specified completion script exists (Specify `--force` to overwrite).
4 An exception occurred while generating the completion script.
System Properties:
Set the following system properties to control the exit code of this program:
* `"picocli.autocomplete.systemExitOnSuccess"`
call `System.exit(0)` when execution completes normally.
* `"picocli.autocomplete.systemExitOnError"`
call `System.exit(ERROR_CODE)` when an error occurs.
If these system properties are not defined or have value "false", this program
completes without terminating the JVM.
Example
-------
java -cp "myapp.jar;picocli-4.6.3.jar" \
picocli.AutoComplete my.pkg.MyClass
Am I not running this right or configuring GraalVM incorrectly?
Upvotes: 1
Views: 236
Reputation: 36834
I suspect you need to make the native image generator know that your FLCL class is the main application class. Without this information the native image generator will search the manifest files in all available jars and find that the picocli.Autocompletion
class is a main class in the picocli jar. If your jar doesn’t declare a main class in the manifest file you can specify it on the command line. I forgot what option that was, check the help for the native image generator tool.
Upvotes: 0