今天下午我终于用Java完成了我的项目。所以我决定使用 launch4j 构建 exe 文件使其可用于 Windows。
看似简单的事情,但实际上对我来说不是。我现在的情况是这样的:
java -jar "jar file path"
在最详细地描述了你我的状态之后,我现在想明确声明我的目标:
希望有人能给我支持,因为这件事让我发疯,因为我已经完成了我的项目,但我仍然不能正式部署它
我是从
OpenJDK19U-jdk_x64_windows_hotspot_19.0.2_7.msi
安装的。
jdeps -cp "lib\*" --module-path "lib\*" --multi-release 19 --print-module-deps --ignore-missing-deps you-app.jar
或没有依赖jar文件:
jdeps --multi-release 19 --print-module-deps --ignore-missing-deps you-app.jar
示例结果:
java.base,java.desktop
jlink --add-modules java.base,java.desktop --output jdk-19-mini-jre --strip-debug --no-man-pages --no-header-files --compress=2
DemoApp
├── DemoApp.jar (your app jar)
├── demoapp.xml (Launch4j Config files)
└── jre (jlink command create JDK 19 jre)
C:\Users\IEUser\Downloads\DemoSwingApp\Output\DemoApp\demoapp.exe
C:\Users\IEUser\Downloads\DemoSwingApp\DemoApp\DemoApp.jar
GUI
jre
<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>C:\Users\IEUser\Downloads\DemoSwingApp\DemoApp\DemoApp.jar</jar>
<outfile>C:\Users\IEUser\Downloads\DemoSwingApp\Output\DemoApp\demoapp.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>false</stayAlive>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon></icon>
<jre>
<path>jre</path>
<bundledJre64Bit>true</bundledJre64Bit>
<bundledJreAsFallback>true</bundledJreAsFallback>
<minVersion></minVersion>
<maxVersion></maxVersion>
<jdkPreference>jdkOnly</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
</launch4jConfig>
点击 Launch4j 构建 exe
复制
jre
到Output\DemoApp\jre
DemoSwingApp/Output
└── DemoApp
├── demoapp.exe
└── jre
现在,您可以点击demoapp.exe
您需要将 DemoApp(包括 demoapp.exe + jre 目录)打包成一个 zip。
注意:我的例子没有使用第三方jar。只有App本身被打包成一个jar,并且只有Swing使用了JDK。