我一直试图让hello world项目为Picocli/GraalVM项目工作。我使用的是运行Montery、Java11和GraalVM 22.3的GraalVM Mac。我跟踪了he文档,但是在尝试运行本机映像时得到了“无与伦比的参数”错误。
该程序运行良好,调用:
java -cp "picocli-4.7.0.jar:FocusStackCLI.jar" FSCLI hello我的Java代码:
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);
}
}我的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>通过调用: Note创建本机映像-它不会让我在Mac上静态编译。
native-image -cp picocli-4.6.3.jar -jar FocusStackCLI.jar现在,当我试图运行这两种方法中的任何一种时,不管有没有争论,
./FocuStackerCLI hello./FocuStackerCLI FSCLI hello我知道这个错误:
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我是不是没有正确地运行这个程序或者不正确地配置GraalVM?
发布于 2022-11-03 03:48:42
我怀疑您需要让本机图像生成器知道您的FLCL类是主要的应用程序类。没有这些信息,本机图像生成器将在所有可用的jar中搜索清单文件,并发现picocli.Autocompletion类是picocli中的一个主类。如果jar没有在清单文件中声明主类,则可以在命令行中指定它。我忘记了这是什么选项,请检查本机图像生成器工具的帮助。
https://stackoverflow.com/questions/74282203
复制相似问题