首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用GraaVM本地映像成功构建Picocli项目,但无法运行

使用GraaVM本地映像成功构建Picocli项目,但无法运行
EN

Stack Overflow用户
提问于 2022-11-01 21:52:22
回答 1查看 35关注 0票数 1

我一直试图让hello world项目为Picocli/GraalVM项目工作。我使用的是运行Montery、Java11和GraalVM 22.3的GraalVM Mac。我跟踪了he文档,但是在尝试运行本机映像时得到了“无与伦比的参数”错误。

该程序运行良好,调用:

代码语言:javascript
复制
java -cp "picocli-4.7.0.jar:FocusStackCLI.jar" FSCLI hello

我的Java代码:

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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上静态编译。

代码语言:javascript
复制
native-image -cp picocli-4.6.3.jar -jar FocusStackCLI.jar

现在,当我试图运行这两种方法中的任何一种时,不管有没有争论,

代码语言:javascript
复制
./FocuStackerCLI hello
代码语言:javascript
复制
./FocuStackerCLI FSCLI hello

我知道这个错误:

代码语言:javascript
复制
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?

EN

回答 1

Stack Overflow用户

发布于 2022-11-03 03:48:42

我怀疑您需要让本机图像生成器知道您的FLCL类是主要的应用程序类。没有这些信息,本机图像生成器将在所有可用的jar中搜索清单文件,并发现picocli.Autocompletion类是picocli中的一个主类。如果jar没有在清单文件中声明主类,则可以在命令行中指定它。我忘记了这是什么选项,请检查本机图像生成器工具的帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74282203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档