一、使用常见问题
问题一:mvnw
- 问题描述
执行打包命令时
bash
./mvnw package -Dnative -DskipTests
报以下错
arduino
'mvnw' 不是内部或外部命令,也不是可运行的程序或批处理文件。
- 解决方法
是因为没有安装 mvnw,mvnw 命令通过自动下载指定版本的 Maven 来隔离构建环境,可以通过以下命令生成 Maven Wrapper
mvn wrapper:wrapper
问题二:package -Dnative不成功
- 问题描述
执行打包命令时
bash
./mvnw package -Dnative -DskipTests
报以下错
csharp
Error: Failed to find 'vcvarsall.bat' in a Visual Studio installation.
Please make sure that Visual Studio 2022 version 17.1.0 or later is installed on your system. You can download it at https://visualstudio.microsoft.com/downloads/. If this error persists, please try and run GraalVM Native Image in an x64 Native Tools Command Prompt or file a ticket.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.855 s
[INFO] Finished at: 2024-12-31T17:23:15+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:3.17.5:build (default) on project quarkus-demo-mvn: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] [error]: Build step io.quarkus.deployment.pkg.steps.NativeImageBuildStep#build threw an exception: io.quarkus.deployment.pkg.steps.NativeImageBuildStep$ImageGenerationFailureException: Image generation failed. Exit code: 20
[ERROR] at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.imageGenerationFailed(NativeImageBuildStep.java:494)
[ERROR] at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:285)
[ERROR] at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
[ERROR] at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
[ERROR] at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
[ERROR] at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2654)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
[ERROR] at java.base/java.lang.Thread.run(Thread.java:1583)
[ERROR] at org.jboss.threads.JBossThread.run(JBossThread.java:499)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
关键内容:Please make sure that Visual Studio 2022 version 17.1.0 or later is installed on your system.
- 解决方法
这个错误表明在构建 Quarkus 原生镜像时,系统找不到 Visual Studio 的 vcvarsall.bat 文件。这是因为 GraalVM 的 native-image 工具在 Windows 上需要 Visual Studio 的 C++ 构建工具来编译原生镜像。
安装 Visual Studio 2022,确保已安装 Visual Studio 2022(版本 17.1.0 或更高),并且安装了 C++ 构建工具。

主要安装 MSVC 与 Windows 11 SDK 一般最新版本就可以,当时如果你是 windows11 系统就安装Windows 10 SDK。
还需要安装这些,安装完还需要配置 include、lib 环境变量。
p.s. 如果你是高版本的 graalvm 的话已经可以不用手动去配置这些环境变量了。
问题三:Cannot open include file: 'stdio.h'
- 问题描述
安装Visual Studio 2022 后还是报错,错误变成下面的
php
Error: Error compiling query code (in C:\Users\Administrator\AppData\Local\Temp\SVM-4568180597130067237\JNIHeaderDirectives.c). Compiler command ''C:\Program Files\Microsoft Visual
Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\HostX64\x64\cl.exe' /WX /W4 /wd4201 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '-IC:\install\Java\graalvm-jdk-21\include\win32' '/
FeC:\Users\Administrator\AppData\Local\Temp\SVM-4568180597130067237\JNIHeaderDirectives.exe' 'C:\Users\Administrator\AppData\Local\Temp\SVM-4568180597130067237\JNIHeaderDirectives.
c'' output included error: [JNIHeaderDirectives.c, C:\Users\Administrator\AppData\Local\Temp\SVM-4568180597130067237\JNIHeaderDirectives.c(1): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory]
com.oracle.svm.core.util.UserError$UserException: Error compiling query code (in C:\Users\Administrator\AppData\Local\Temp\SVM-4568180597130067237\JNIHeaderDirectives.c). Compiler
command ''C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\HostX64\x64\cl.exe' /WX /W4 /wd4201 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '-IC:\in
stall\Java\graalvm-jdk-21\include\win32' '/FeC:\Users\Administrator\AppData\Local\Temp\SVM-4568180597130067237\JNIHeaderDirectives.exe' 'C:\Users\Administrator\AppData\Local\Temp\S
VM-4568180597130067237\JNIHeaderDirectives.c'' output included error: [JNIHeaderDirectives.c, C:\Users\Administrator\AppData\Local\Temp\SVM-4568180597130067237\JNIHeaderDirectives.c(1): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory]
at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:126)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.c.NativeLibraries.reportErrors(NativeLibraries.java:380)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.processNativeLibraryImports(NativeImageGenerator.java:1753)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.setupNativeLibraries(NativeImageGenerator.java:1200)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:960)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:590)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:550)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:539)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:721)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.start(NativeImageGeneratorRunner.java:143)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:98)
关键内容:Cannot open include file: 'stdio.h': No such file or directory
- 解决方法
这个问题是 Windows 11 SDK 安装不成功,需要重新安装Windows 11 SDK。如果还不成功可以考虑使用 dokcer 中的 graalvm 方式也就是不依赖本地 GraalVM 这种就比较简单了。
把本地可远程 docker 启动后,在 idea 里配置好

通过命令行
ini
./mvnw package -Dquarkus.container-image.build=true
如果你不想用命令行的话也可以选择使用 idea 来打包,就是直接使用生命周期中的 package

至于-Dquarkus.container-image.build=true 这个参数就可以放到项目中的 pom.xml 中去

pom.xml
xml
<properties>
<skipITs>true</skipITs>
<quarkus.native.container-build>true</quarkus.native.container-build>
<quarkus.native.enabled>true</quarkus.native.enabled>
</properties>
就可以直接打包好了

可以看到我已经打包完成,就是这个文件。看到这个 xx-runner 文件就说明已经成功了

问题四:未启动 docker
- 问题描述
less
[WARNING] [io.quarkus.deployment.util.ContainerRuntimeUtil] Command "docker info" exited with error code 1. Rootless container runtime detection might not be reliable or the container service is not running at all.
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building native image source jar: D:\code\local\java\quarkus-demo-mvn\target\quarkus-demo-mvn-1.0-SNAPSHOT-native-image-source-jar\quarkus-demo-mvn-1.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Building native image from D:\code\local\java\quarkus-demo-mvn\target\quarkus-demo-mvn-1.0-SNAPSHOT-native-image-source-jar\quarkus-demo-mvn-1.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner] Using docker to run the native image builder
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner] Pulling builder image 'quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21'
error during connect: Post "http://%2F%2F.%2Fpipe%2FdockerDesktopLinuxEngine/v1.47/images/create?fromImage=quay.io%2Fquarkus%2Fubi-quarkus-mandrel-builder-image&tag=jdk-21": open //./pipe/dockerDesktopLinuxEngine: The system cannot find the file specified.
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner] Retrying in 5 seconds
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner] Pulling builder image 'quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21' (take 2)
error during connect: Post "http://%2F%2F.%2Fpipe%2FdockerDesktopLinuxEngine/v1.47/images/create?fromImage=quay.io%2Fquarkus%2Fubi-quarkus-mandrel-builder-image&tag=jdk-21": open //./pipe/dockerDesktopLinuxEngine: The system cannot find the file specified.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.342 s
[INFO] Finished at: 2025-01-03T18:50:19+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:3.17.5:build (default) on project quarkus-demo-mvn: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] [error]: Build step io.quarkus.deployment.pkg.steps.NativeImageBuildStep#build threw an exception: java.lang.RuntimeException: Failed to pull builder image 'quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21'
[ERROR] at io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner.pull(NativeImageBuildContainerRunner.java:109)
[ERROR] at io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner.setup(NativeImageBuildContainerRunner.java:97)
[ERROR] at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:241)
[ERROR] at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
[ERROR] at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
[ERROR] at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
[ERROR] at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2654)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
[ERROR] at java.base/java.lang.Thread.run(Thread.java:833)
[ERROR] at org.jboss.threads.JBossThread.run(JBossThread.java:499)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
关键内容:error during connect: Post
- 解决方法
启动 docker
二、基础概念问题
SpringBoot 能不能打成原生镜像?
Spring Boot 可以打成原生镜像,通过集成 GraalVM 原生镜像(Native Image)技术,支持将 Spring Boot 应用编译为原生可执行文件。原生镜像可以显著减少应用的启动时间和内存占用,特别适合云原生场景。
SpringBoot 原生与 Quarkus 原生区别?

Spring Boot 原生镜像和 Quarkus 原生镜像都基于 GraalVM 技术,但 Spring Boot 更注重对现有应用的兼容性,适合迁移传统 Spring 项目,而 Quarkus 则是为云原生场景设计,提供极快的启动速度和低内存占用,适合全新开发。Spring Boot 原生镜像需要更多手动配置,而 Quarkus 开箱即用,开发体验更流畅。

图片来源:ualterazambuja.com
我是栈江湖,如果你喜欢此文章,不要忘记点赞+关注!