GraalVM打包Native应用

GraalVM 打包 Native 应用

安装 GraalVM

  1. 下载 GraalVM

  2. 添加环境变量

1
2
JAVA_HOME=D://graalvm
PATH=%JAVA_HOME%/bin
  1. 校验是否安装成功
1
2
3
4
5
6
7
8
9
10
C:\Users\chenkaixin12121>java -version
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment GraalVM CE 17.0.9+9.1 (build 17.0.9+9-jvmci-23.0-b22)
OpenJDK 64-Bit Server VM GraalVM CE 17.0.9+9.1 (build 17.0.9+9-jvmci-23.0-b22, mixed mode, sharing)

C:\Users\chenkaixin12121>gu list
ComponentId Version Component name Stability Origin
---------------------------------------------------------------------------------------------------------------------------------
graalvm 23.0.2 GraalVM Core Supported
native-image 23.0.2 Native Image Early adopter
  1. 安装 Visual Studio

https://www.graalvm.org/latest/docs/getting-started/windows/#prerequisites-for-using-native-image-on-windows

image.png

创建项目

image.png

image.png

测试

  1. 执行 gradle nativeCompile(exe 地址 ./build/nativeCompile)

  2. 启动项目后对比

image.png

image.png