【发布时间】:2020-03-23 04:30:30
【问题描述】:
请注意:我创建了this GitHub project right here,可以用来完美重现我看到的问题。
Java 8 在此尝试通过 gradle-launch4j Gradle 插件使用 Launch4J 来构建 Windows 原生 EXE 应用程序。我正在我的 Mac 上开发 Java Swing 应用程序,但该应用程序必须在 Windows 10 上作为 Windows EXE 运行。我还使用 ShadowJar 来构建我的独立“胖罐”。
我可以构建我的 (Swing) 应用程序的 fat jar,然后通过 java -jar build/lib/myapp.jar 在我的 Mac 上运行它。它启动并运行没有问题。
这是我的 Launch4J 的 Gradle 配置:
launch4j {
mainClassName = 'com.example.windows.hello.HelloWindowsApp'
icon = "${projectDir}/icon.ico"
jdkPreference = 'jdkOnly'
initialHeapSize = 128
jreMinVersion = '1.8.0'
jreMaxVersion = '1.8.9'
maxHeapSize = 512
stayAlive = false
bundledJre64Bit = true
bundledJrePath = '../hello-windows/jre8'
}
当我运行 ./gradle clean build shadowJar createExe createDistro 时,它会产生:
hello-windows.zip/
hello-windows.exe --> The Windows EXE built by the 'createExe' task
lib/* --> The lib/ dir for the EXE that is also built by the `createExe` task
jre8/ --> OpenJDK JRE8 (copied from the libs/jre8 dir)
所以我复制了该 ZIP 文件并将其移植到 Windows 10(64 位)机器上。我提取 ZIP 并通过在 Windows 资源管理器中双击它来运行 EXE(我可以确认 确实 将 EXE 视为 Application 类型)。首先我看到这个:
为什么会发生这种情况?我可以更改任何 Launch4J 配置/设置,以免发生这种情况吗?
提前致谢!
【问题讨论】:
-
你能从Windows命令行用
--l4j-debug参数启动exe文件,然后把生成的launch4j.log的内容贴在这里吗?见github.com/TheBoegl/gradle-launch4j#debugging。 -
我克隆了您的 GitHub 存储库并使用您发布的 Gradle 命令构建了项目。我可以确认 exe 文件可以在我的带有 Windows 10 企业评估版 64 位的虚拟机中启动。防守方没有确认,也没有其他消息。只是 GUI 会正确弹出。
标签: windows gradle java-8 gradle-plugin launch4j