-
安装 Liberica Native Image Kit 版本我选择的是17.0.11+10-23.0.4+1
-
配置JDK环境变量
-
安装 visual studio 地址直达 下载完成选择 c++桌面开发进行安装
-
提前把项目打包成==jar包== 确保 java -jar [jar name] 可以正常运行(不能运行直接不能进行下一步)
-
管理员权限打开 x64 Native Tools Command Prompt for VS 2022x64 Native Tools Command Prompt for VS 2022
-
进入 jar包的位置
-
打包镜像
native-image -Djava.awt.headless=false -jar emailSender-1.0-SNAPSHOT.jar --no-fallback -H:ReflectionConfigurationFiles=reflect-config.json -H:Path=out --enable-url-protocols=https
-
-Djava.awt.headless=false:确保图形界面(我这里是Swing项目)在构建本地镜像时能够正常工作。
-
-jar emailSender-1.0-SNAPSHOT.jar:指定要构建本地镜像的可执行 JAR 文件。
-
--no-fallback:禁用回退模式,强制使用本地镜像执行。
-
-H:ReflectionConfigurationFiles=reflect-config.json:指定反射配置文件的路径,以确保需要的类和方法在本地镜像中正确使用。
-
-H:Path=out:指定输出路径为 out文件夹,这样生成的本地镜像文件将保存在当前目录下的 out文件夹中。
-
--enable-url-protocols=https:启用 HTTPS 协议支持,以允许应用程序访问 HTTPS URL
[
{
"name": "com.resend.services.emails.model.CreateEmailOptions",
"allDeclaredConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "com.resend.services.emails.model.Attachment",
"allDeclaredConstructors" : true,
"allDeclaredMethods" : true,
"allDeclaredFields" : true
}
]
out目录中执行.exe文件即可