目录
Graalvm 打包
/        

Graalvm 打包

环境准备

Window

可以通过 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

下载地址可以下载:

https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-17.0.8/graalvm-community-jdk-17.0.8_windows-x64_bin.zip

https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.2/native-image-installable-svm-java17-windows-amd64-22.3.2.jar

配置环境变量 GRAALVM_HOME、JAVA_HOME

2、安装Visual Studio的C++桌面开发环境

https://visualstudio.microsoft.com/

  • 使用C++桌面开发

Linux

可以使用 sdkman 管理 jdk 多版本

Spring Boot 程序打包

Window 环境下打包

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

Linux 环境下打包

mvn clean compile

mvn spring-boot:process-aot

mvn -Pnative native:build

target 目录生成对应的可执行文件

Java项目打包

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、正常打包即可


标题:Graalvm 打包
作者:gitsilence
地址:http://blog.lacknb.cn/articles/2024/06/20/1718879023451.html