You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot编译Native Image报错:找不到gu.cmd工具

解决Windows下Spring Boot Native Image编译找不到gu.cmd的问题

核心环境配置排查

  • 确保GraalVM环境变量优先级:Windows的PATH环境变量中,GraalVM安装目录下的bin文件夹必须排在系统默认JDK的bin目录之前。打开新命令行窗口,执行where java和where gu,确认输出的第一条路径是GraalVM对应的目录。
  • 验证JAVA_HOME指向:JAVA_HOME必须设置为GraalVM的安装根目录(而非普通JDK)。执行echo %JAVA_HOME%检查,示例正确路径:C:\graalvm-ce-java17-22.3.2。

Maven配置检查

打开项目的pom.xml,确认Native相关插件配置无误:

<!-- Spring Boot Native插件基础配置 -->
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <builder>paketobuildpacks/builder:tiny</builder>
            <env>
                <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
            </env>
        </image>
    </configuration>
</plugin>

<!-- Native Profile配置 -->
<profiles>
    <profile>
        <id>native</id>
        <properties>
            <native.maven.plugin.version>0.9.22</native.maven.plugin.version>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.graalvm.buildtools</groupId>
                    <artifactId>native-maven-plugin</artifactId>
                    <version>${native.maven.plugin.version}</version>
                    <extensions>true</extensions>
                    <executions>
                        <execution>
                            <id>build-native</id>
                            <goals>
                                <goal>compile-no-fork</goal>
                            </goals>
                            <phase>package</phase>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

命令行环境验证

  • 关闭所有已打开的命令行窗口,重新打开新窗口(避免环境变量缓存)。
  • 依次执行以下命令确认环境:
    1. java -version:输出需包含GraalVM标识,示例:openjdk version "17.0.7" 2023-04-18 OpenJDK Runtime Environment GraalVM CE 22.3.2 (build 17.0.7+7-jvmci-22.3-b13)
    2. gu list:需显示native-image插件已安装,示例输出:native-image 22.3.2 installed

额外排查项

  • 检查GraalVM安装目录权限:确保当前用户对GraalVM文件夹有读写权限,避免权限不足导致gu.cmd无法被调用。
  • 手动测试gu工具:直接在命令行执行gu.cmd version,若能正常输出版本,说明工具本身无问题,问题出在Maven调用时的环境变量传递。

内容的提问来源于stack exchange,提问作者ImaginativeGoldfish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 00:32:01