可以通过 jvms 管理多版本的jdk
1、下载专属的JDK
graalvm: https://github.com/graalvm/graalvm-ce-builds/releases/tag/jdk-17.0.8
native-image: https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-22.3.2
gu install --file native-image-xx.jar
gu list
下载地址可以下载:
配置环境变量 GRAALVM_HOME、JAVA_HOME
2、安装Visual Studio的C++桌面开发环境
https://visualstudio.microsoft.com/
可以使用 sdkman 管理 jdk 多版本
1、项目pom.xml配置
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<version>21.2.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>build-native</id>
<phase>package</phase>
<goals>
<goal>native-image</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>false</skip>
<imageName>dataplat-devOps</imageName>
<buildArgs>
</buildArgs>
<mainClass>Your Main Class</mainClass>
</configuration>
</plugin>
2、打包
先 clean compile
然后执行 springboot:process-aot
然后打开 x64 Native Tools Command Prompt 终端
到项目目录执行,mvn -Pnative native:build
参考地址:http://luoma.pro/Content/Detail/957?parentId=5
mvn clean compile
mvn spring-boot:process-aot
mvn -Pnative native:build
target 目录生成对应的可执行文件
1、配置pom.xml
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.13</version> <!-- 使用 GraalVM 相应版本 -->
<extensions>true</extensions>
<configuration>
<mainClass>cn.lacknb.App</mainClass>
<!-- 配置项 -->
</configuration>
<executions>
<execution>
<id>build-native</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
2、正常打包即可