我想先说一下我是如何对Sping Boot 和GraalVM相对较新的,并且一直存在问题。(我使用spring intializer设置它)。每当我尝试使用Sping Boot 本机映像将我的程序转换为本机映像时,它都会给我以下错误(当运行mvn clean package -Pnative
时):
'gu.cmd' tool wasn't found. This probably means that JDK at isn't a GraalVM distribution.
此外,如果这有帮助的话,我希望生成一个本地映像,以便能够在本地或部署服务器上运行,因为我正在构建一个API。
到目前为止,我已经尝试重新安装GraalVM和所需的插件(我在Windows上)。我已经使用gu在GraalVM中安装了native-image,并使用Spring Initializer设置了我的项目。以下是一些您可能会发现有用的输出:
下面是java版本:
openjdk 19.0.2 2023-01-17
OpenJDK Runtime Environment GraalVM CE 22.3.1 (build 19.0.2+7-jvmci-22.3-b12)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.1 (build 19.0.2+7-jvmci-22.3-b12, mixed mode, sharing)
下面是运行native-image --version
时的输出
GraalVM 22.3.1 Java 19 CE (Java Version 19.0.2+7-jvmci-22.3-b12)
这是我的绒球联系我们
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.example</groupId>
<artifactId>peoplegeneratorapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>peoplegeneratorapi</name>
<description>People generator API with Spring Boot</description>
<properties>
<java.version>19</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.7.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>${spring-restdocs.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
这里有一个工作mvn spring-boot:start
,如果这有帮助的话:
C:\Users\XX\.jdks\graalvm-ce-19\bin\java.exe -Dmaven.multiModuleProjectDirectory=C:\Users\XX\Documents\Code\peoplegeneratorapi -Djansi.passthrough=true -Dmaven.home=C:\Users\XX\.m2\wrapper\dists\apache-maven-3.8.7-bin\1ktonn2lleg549uah6ngl1r74r\apache-maven-3.8.7 -Dclassworlds.conf=C:\Users\XX\.m2\wrapper\dists\apache-maven-3.8.7-bin\1ktonn2lleg549uah6ngl1r74r\apache-maven-3.8.7\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2022.3.2\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2022.3.2\lib\idea_rt.jar=65445:C:\Program Files\JetBrains\IntelliJ IDEA 2022.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\XX\.m2\wrapper\dists\apache-maven-3.8.7-bin\1ktonn2lleg549uah6ngl1r74r\apache-maven-3.8.7\boot\plexus-classworlds-2.6.0.jar;C:\Users\XX\.m2\wrapper\dists\apache-maven-3.8.7-bin\1ktonn2lleg549uah6ngl1r74r\apache-maven-3.8.7\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2022.3.2 spring-boot:start
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< org.example:peoplegeneratorapi >---------------
[INFO] Building peoplegeneratorapi 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- spring-boot-maven-plugin:3.0.4:start (default-cli) @ peoplegeneratorapi ---
[INFO] Attaching agents: []
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.4)
2023-03-04T12:15:52.890+05:30 INFO 12652 --- [ restartedMain] o.example.peoplegenerator.Main : Starting Main using Java 19.0.2 with PID 12652 (C:\Users\XX\Documents\Code\peoplegeneratorapi\target\classes started by XX in C:\Users\XX\Documents\Code\peoplegeneratorapi)
2023-03-04T12:15:52.893+05:30 INFO 12652 --- [ restartedMain] o.example.peoplegenerator.Main : No active profile set, falling back to 1 default profile: "default"
2023-03-04T12:15:52.959+05:30 INFO 12652 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-03-04T12:15:52.959+05:30 INFO 12652 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-03-04T12:15:53.826+05:30 INFO 12652 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-03-04T12:15:53.835+05:30 INFO 12652 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-03-04T12:15:53.835+05:30 INFO 12652 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.5]
2023-03-04T12:15:53.889+05:30 INFO 12652 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-03-04T12:15:53.889+05:30 INFO 12652 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 929 ms
2023-03-04T12:15:54.229+05:30 INFO 12652 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-03-04T12:15:54.254+05:30 INFO 12652 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-03-04T12:15:54.263+05:30 INFO 12652 --- [ restartedMain] o.example.peoplegenerator.Main : Started Main in 1.741 seconds (process running for 21.409)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.047 s
[INFO] Finished at: 2023-03-04T12:15:54+05:30
[INFO] ------------------------------------------------------------------------
运行mvn clean package -Pnative
时的输出:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.665 s
[INFO] Finished at: 2023-03-04T12:40:38+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.9.20:compile-no-fork (build-native) on project peoplegeneratorapi: 'gu.cmd' tool wasn't found. This probably means that JDK at isn't a GraalVM distribution. -> [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
编辑:我不太确定我如何能给予一个最小的可重复的例子,所以我尽我最大的努力来描述这个问题。
1条答案
按热度按时间nfs0ujit1#
gu.cmd
必须在PATH
环境变量中。为此,您需要将
GRAALVM_HOME/bin
文件夹添加到PATH
变量。