gpt4 book ai didi

java - Gradle jpackage 创建无法运行的应用程序

转载 作者:行者123 更新时间:2023-12-02 18:52:58 25 4
gpt4 key购买 nike

我正在尝试使用一个简单的 Gradle JavaFX 应用程序运行 jpackage,主要是为了尝试一下。它没有什么特别的,它是添加了 Gradle 的 IntelliJ JavaFX 示例。该应用程序通过 gradlew clean build run 运行良好。但是,当使用 gradlew jpackage 创建包时,生成的 exe 会立即崩溃并创建 hs_err_pid。

# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000000000000, pid=1132, tid=15340
#
# JRE version: (15.0.2+10) (build )
# Java VM: OpenJDK 64-Bit Server VM (15.0.2+10, mixed mode, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C 0x0000000000000000

在此处查看完整输出:https://pastebin.com/LgbSFa5L

我已经在 similar question 上尝试过答案。但他们没有工作。

  • zip.dll{app}\runtime\bin 复制到 {app}\
  • 尝试其他 JDK
    • 采用OpenJDK 11
    • 采用OpenJDK 14
    • 采用OpenJDK 15
    • BellSoft Liberica JDK 15

build.gradle 看起来像这样

// Setup Gradle
plugins {
id "application"
id "org.beryx.runtime" version "1.12.2"
id "org.openjfx.javafxplugin" version '0.0.9'
}

repositories {
mavenCentral()
jcenter()
}

// Setup application, dependencies
group = "io.mattw.sample"
sourceCompatibility = 15
targetCompatibility = 15

application {
mainClassName = "io.mattw.sample.Main"
}

javafx {
version = 15
modules = ["javafx.base", "javafx.controls", "javafx.fxml"]
}

dependencies {

}

// Setup release
// https://simply-how.com/custom-java-runtime
runtime {
addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
}

tasks.runtime.doLast {
copy {
from("src/main/resources")
into("$buildDir/image/bin")
}
}

编辑:

当使用 WinDbg (preview) 运行 exe 时,我得到以下输出。可能与我正常安装了 Java 8 有关,尽管我希望它使用捆绑的 SDK 而不是系统。

Microsoft (R) Windows Debugger Version 10.0.21306.1007 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\gradle-test-javafx.exe

************* Path validation summary **************
Response Time (ms) Location
Deferred srv*
Symbol search path is: srv*
Executable search path is:
ModLoad: 00007ff6`995d0000 00007ff6`9963f000 image00007ff6`995d0000
ModLoad: 00007ffc`36450000 00007ffc`36646000 ntdll.dll
ModLoad: 00007ffc`35320000 00007ffc`353dd000 C:\WINDOWS\System32\KERNEL32.DLL
ModLoad: 00007ffc`33d90000 00007ffc`34059000 C:\WINDOWS\System32\KERNELBASE.dll
ModLoad: 00007ffc`36210000 00007ffc`363b0000 C:\WINDOWS\System32\USER32.dll
ModLoad: 00007ffc`33d30000 00007ffc`33d52000 C:\WINDOWS\System32\win32u.dll
ModLoad: 00007ffc`346f0000 00007ffc`3471a000 C:\WINDOWS\System32\GDI32.dll
ModLoad: 00007ffc`343a0000 00007ffc`344ab000 C:\WINDOWS\System32\gdi32full.dll
ModLoad: 00007ffc`33c90000 00007ffc`33d2d000 C:\WINDOWS\System32\msvcp_win.dll
ModLoad: 00007ffc`33b90000 00007ffc`33c90000 C:\WINDOWS\System32\ucrtbase.dll
ModLoad: 00007ffc`35ac0000 00007ffc`36202000 C:\WINDOWS\System32\SHELL32.dll
(4ad0.33e0): Break instruction exception - code 80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00007ffc`36520670 cc int 3
0:000> g
ModLoad: 00007ffc`355c0000 00007ffc`355f0000 C:\WINDOWS\System32\IMM32.DLL
ModLoad: 00007ffc`34ba0000 00007ffc`34c4e000 C:\WINDOWS\System32\shcore.dll
ModLoad: 00007ffc`35a20000 00007ffc`35abe000 C:\WINDOWS\System32\msvcrt.dll
ModLoad: 00007ffc`34840000 00007ffc`34b96000 C:\WINDOWS\System32\combase.dll
ModLoad: 00007ffc`35720000 00007ffc`3584b000 C:\WINDOWS\System32\RPCRT4.dll
ModLoad: 00007ffc`11d50000 00007ffc`11d68000 C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\jli.dll
ModLoad: 00007ffc`224e0000 00007ffc`22590000 C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.19041.488_none_4238de57f6b64d28\COMCTL32.dll
ModLoad: 00007ffc`22cb0000 00007ffc`22cc9000 C:\WINDOWS\SYSTEM32\VCRUNTIME140.dll
ModLoad: 00007ffc`34c50000 00007ffc`34cfc000 C:\WINDOWS\System32\ADVAPI32.dll
ModLoad: 00007ffc`35520000 00007ffc`355bc000 C:\WINDOWS\System32\sechost.dll
ModLoad: 00007ffc`10080000 00007ffc`10095000 C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\vcruntime140.dll
ModLoad: 00007ffb`f76b0000 00007ffb`f774b000 C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\msvcp140.dll
ModLoad: 00007ffb`a5030000 00007ffb`a5bbf000 C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\server\jvm.dll
ModLoad: 00007ffc`34630000 00007ffc`34638000 C:\WINDOWS\System32\PSAPI.DLL
ModLoad: 00007ffc`1ff10000 00007ffc`1ff19000 C:\WINDOWS\SYSTEM32\WSOCK32.dll
ModLoad: 00007ffc`32a70000 00007ffc`32a7a000 C:\WINDOWS\SYSTEM32\VERSION.dll
ModLoad: 00007ffc`261f0000 00007ffc`26217000 C:\WINDOWS\SYSTEM32\WINMM.dll
ModLoad: 00007ffc`35870000 00007ffc`358db000 C:\WINDOWS\System32\WS2_32.dll
ModLoad: 0000014c`22330000 0000014c`2239b000 C:\WINDOWS\System32\ws2_32.DLL
ModLoad: 00007ffc`32a30000 00007ffc`32a42000 C:\WINDOWS\SYSTEM32\kernel.appcore.dll
ModLoad: 00007ffc`2acf0000 00007ffc`2acfa000 C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\jimage.dll
ModLoad: 00007ffc`22590000 00007ffc`22774000 C:\WINDOWS\SYSTEM32\DBGHELP.DLL
ModLoad: 00007ffc`21be0000 00007ffc`21c0c000 C:\WINDOWS\SYSTEM32\dbgcore.DLL
ModLoad: 00007ffc`34060000 00007ffc`340e0000 C:\WINDOWS\System32\bcryptPrimitives.dll
ModLoad: 00007ffc`09f50000 00007ffc`09f75000 C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\java.dll
(4ad0.30c4): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
0000014c`23890969 8b06 mov eax,dword ptr [rsi] ds:00000000`00000000=????????
0:004> g
(4ad0.30c4): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** WARNING: Unable to verify checksum for C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\jimage.dll
00000000`00000000 ?? ???
0:004> g
ntdll!NtTerminateProcess+0x14:
00007ffc`364ecba4 c3 ret

最佳答案

使用 Liberica,我可以通过添加以下行来使其工作:

runtime {
addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
addModules("javafx.base", "javafx.controls", "javafx.fxml") // <----
}

如果没有这个,似乎 javafx.controls 模块不会添加到生成的运行时镜像中(您可以使用 runtime\bin\java.exe --list-modules 检查这一点)。

手动运行应用程序以及之后通过生成的 exe 运行该应用程序。


如果没有 Liberica,我可以通过向 jpackage 添加 --win-console 选项来获取更多信息,如下所示:

runtime {
addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")

jpackage {
imageOptions = ["--win-console"] // <---
}
}

运行生成的 exe 结果

Error: JavaFX runtime components are missing, and are required to run this application

我认为这是 javafx 模块没有放在模块路径上而是放在类路径上的问题(据我所知现在不支持)。这似乎是所使用的运行时插件的问题(它表示它不支持模块化应用程序)。

我能够通过添加手动使其工作

runtime {
...
launcher {
jvmArgs = ["--add-modules=javafx.base,javafx.controls,javafx.fxml"]
}
}

然后手动将 javafx jar 复制到 app\mods 文件夹(我必须创建该文件夹)。查看 jpackage 创建的生成的 {app}.cfg 文件,这就是启动器将用作模块路径的文件。我还从 {app}.cfg 文件中删除了 javafx jar 中不需要的 app.classpath 条目。

关于java - Gradle jpackage 创建无法运行的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66517949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com