问题描述
我用 gradle 构建的应用程序无法用 graal 的原生镜像命令打包。
我使用以下方法构建组合 jar:
gradlew --no-daemon assemble
然后,我使用以下命令测试我的 cli 应用程序:
java -jar build/libs/stackoverflow-cli-0.1-all.jar search -q "merge maps" -t java
输出是我所期望的,所以很好。但是,然后我想使用 graalvm 创建本机二进制文件。所以我运行这个命令:
native-image --no-server -cp build/libs/stackoverflow-cli-0.1-all.jar
它立即失败并出现以下错误:
Warning: Ignoring server-mode native-image argument --no-server.
Error: Please specify class containing the main entry point method. (see --help)
我觉得这很奇怪。我尝试的下一件事是按照错误提示指定主类:
native-image --no-server -cp build/libs/stackoverflow-cli-0.1-all.jar com.eddie.StackoverflowCliCommand
这给了我一个不同的错误:
Warning: Ignoring server-mode native-image argument --no-server.
[com.ivansinsurance.stackoverflowclicommand:1544] classlist: 3,060.25 ms,0.96 GB
[com.ivansinsurance.stackoverflowclicommand:1544] setup: 809.46 ms,0.96 GB
Error: Default native-compiler executable 'cl.exe' not found via environment variable PATH
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1
我不知道这个错误是什么意思。这是我正在使用的 Java 版本:
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02)
OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02,mixed mode,sharing)
非常感谢任何帮助!
解决方法
-
我安装了 Visual Studio 2019。
-
然后我为 VS 2019 启动了 x64 Native Tools Command Prompt
-
然后我跑了:
'native-image --no-server -cp build/libs/stackoverflow-cli-0.1-all.jar com.eddie.StackoverflowCliCommand'
效果很好!