使用Maven编译JavaFX项目时遇到断言失败错误

6

我正在进行一个JavaFX项目,希望使用Maven在终端编译,但无法成功。在IntelliJ中可以编译成功,但在终端中却失败了。我使用编译脚本运行程序,并且我使用的是M2的MacBook Air。

以下是我的Java版本:

openjdk 19.0.1 2022-10-18
OpenJDK Runtime Environment Zulu19.30+11-CA (build 19.0.1+10)
OpenJDK 64-Bit Server VM Zulu19.30+11-CA (build 19.0.1+10, mixed mode, sharing)

Maven版本:

Maven home: /opt/homebrew/Cellar/maven/3.8.6/libexec
Java version: 19.0.1, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/19.0.1/libexec/openjdk.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "13.0.1", arch: "aarch64", family: "mac"

附言:我对Maven不熟悉,这是我在stackoverflow上的第一篇帖子。欢迎提供任何建议。

以下是脚本:

1 #!/bin/bash -ex  
2
3 mvn -q -e clean
4 mvn -q -e compile
5 mvn -q -e exec:java

以下是堆栈跟踪:

Nov 30, 2022 10:41:30 AM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @56d120f3'
init() called
2022-11-30 10:41:30.934 java[34735:3292918] *** Assertion failure in -[_NSTrackingAreaAKViewHelper removeTrackingRect:], _NSTrackingAreaAKManager.m:1585
2022-11-30 10:41:30.936 java[34735:3292918] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '0x0 is an invalid NSTrackingRectTag. Common possible reasons for this are: 1. already removed this trackingRectTag, 2. Truncated the NSTrackingRectTag to 32bit at some point.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001809bc418 __exceptionPreprocess + 176
    1   libobjc.A.dylib                     0x0000000180506ea8 objc_exception_throw + 60
    2   Foundation                          0x00000001818fca60 -[NSCalendarDate initWithCoder:] + 0
    3   AppKit                              0x000000018414bf98 -[_NSTrackingAreaAKViewHelper removeTrackingRect:] + 200
    4   libglass.dylib                      0x000000012cc65e80 Java_com_sun_glass_ui_mac_MacApplication__1getMacKey + 3456
    5   libglass.dylib                      0x000000012cc6a540 Java_com_sun_glass_ui_mac_MacApplication__1getMacKey + 21568
    6   AppKit                              0x0000000183bd1ba4 -[NSView setFrame:] + 304
    7   libglass.dylib                      0x000000012cc6a5a0 Java_com_sun_glass_ui_mac_MacApplication__1getMacKey + 21664
    8   AppKit                              0x0000000183bdfad4 -[NSView resizeWithOldSuperviewSize:] + 508
    9   AppKit                              0x0000000183bdf4c4 -[NSView resizeSubviewsWithOldSize:] + 360
    10  AppKit                              0x0000000183bc3acc -[NSView setFrameSize:] + 1120
    11  AppKit                              0x0000000183bd1ba4 -[NSView setFrame:] + 304
    12  AppKit                              0x0000000183bdfad4 -[NSView resizeWithOldSuperviewSize:] + 508
    13  AppKit                              0x0000000183bdf4c4 -[NSView resizeSubviewsWithOldSize:] + 360
    14  AppKit                              0x0000000183bc3acc -[NSView setFrameSize:] + 1120
    15  AppKit                              0x0000000183bde130 -[NSThemeFrame setFrameSize:] + 244
    16  AppKit                              0x0000000183bdda7c -[NSWindow _oldPlaceWindow:fromServer:] + 540
    17  AppKit                              0x0000000183bdcb8c -[NSWindow _setFrameCommon:display:fromServer:] + 1824
    18  libglass.dylib                      0x000000012cc5d700 getImage + 5228
    19  libglass.dylib                      0x000000012cc74274 Java_com_sun_glass_ui_mac_MacWindow__1setBounds2 + 416
    20  ???                                 0x0000000114044aac 0x0 + 4630792876
    21  ???                                 0x0000000114041548 0x0 + 4630779208
    22  ???                                 0x0000000114041548 0x0 + 4630779208
    23  ???                                 0x0000000114041548 0x0 + 4630779208
    24  ???                                 0x0000000114041a88 0x0 + 4630780552
    25  ???                                 0x0000000114041548 0x0 + 4630779208
    26  ???                                 0x0000000114041548 0x0 + 4630779208
    27  ???                                 0x0000000114041548 0x0 + 4630779208
    28  ???                                 0x0000000114041548 0x0 + 4630779208
    29  ???                                 0x0000000114041548 0x0 + 4630779208
    30  ???                                 0x0000000114041548 0x0 + 4630779208
    31  ???                                 0x0000000114041548 0x0 + 4630779208
    32  ???                                 0x0000000114041548 0x0 + 4630779208
    33  ???                                 0x0000000114041548 0x0 + 4630779208
    34  ???                                 0x0000000114041548 0x0 + 4630779208
    35  ???                                 0x0000000114041548 0x0 + 4630779208
    36  ???                                 0x0000000114041a88 0x0 + 4630780552
    37  ???                                 0x0000000114041548 0x0 + 4630779208
    38  ???                                 0x0000000114041a88 0x0 + 4630780552
    39  ???                                 0x0000000114041300 0x0 + 4630778624
    40  ???                                 0x000000010cd3a564 0x0 + 4510164324
    41  ???                                 0x0000000114041300 0x0 + 4630778624
    42  ???                                 0x0000000114041548 0x0 + 4630779208
    43  ???                                 0x0000000114041a88 0x0 + 4630780552
    44  ???                                 0x0000000114030140 0x0 + 4630708544
    45  libjvm.dylib                        0x0000000103e5dd34 _ZN9JavaCalls11call_helperEP9JavaValueRK12methodHandleP17JavaCallArgumentsP10JavaThread + 564
    46  libjvm.dylib                        0x0000000103eb3c9c _ZL20jni_invoke_nonstaticP7JNIEnv_P9JavaValueP8_jobject11JNICallTypeP10_jmethodIDP18JNI_ArgumentPusherP10JavaThread + 536
    47  libjvm.dylib                        0x0000000103eb77c4 jni_CallVoidMethod + 224
    48  libglass.dylib                      0x000000012cc619e8 JNI_OnLoad + 204
    49  Foundation                          0x0000000181864b30 __NSThreadPerformPerform + 264
    50  CoreFoundation                      0x0000000180941a34 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
    51  CoreFoundation                      0x00000001809419c8 __CFRunLoopDoSource0 + 176
    52  CoreFoundation                      0x0000000180941738 __CFRunLoopDoSources0 + 244
    53  CoreFoundation                      0x000000018094033c __CFRunLoopRun + 836
    54  CoreFoundation                      0x000000018093f8a4 CFRunLoopRunSpecific + 612
    55  HIToolbox                           0x0000000189fb33bc RunCurrentEventLoopInMode + 292
    56  HIToolbox                           0x0000000189fb3200 ReceiveNextEventCommon + 672
    57  HIToolbox                           0x0000000189fb2f48 _BlockUntilNextEventMatchingListInModeWithFilter + 72
    58  AppKit                              0x0000000183b98630 _DPSNextEvent + 632
    59  AppKit                              0x0000000183b977c0 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728
    60  AppKit                              0x0000000183b8bbf0 -[NSApplication run] + 464
    61  libglass.dylib                      0x000000012cc63b70 JNI_OnLoad + 8788
    62  Foundation                          0x0000000181864b30 __NSThreadPerformPerform + 264
    63  CoreFoundation                      0x0000000180941a34 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
    64  CoreFoundation                      0x00000001809419c8 __CFRunLoopDoSource0 + 176
    65  CoreFoundation                      0x0000000180941738 __CFRunLoopDoSources0 + 244
    66  CoreFoundation                      0x000000018094033c __CFRunLoopRun + 836
    67  CoreFoundation                      0x000000018093f8a4 CFRunLoopRunSpecific + 612
    68  libjli.dylib                        0x0000000102ab7094 CreateExecutionEnvironment + 400
    69  libjli.dylib                        0x0000000102ab3794 JLI_Launch + 1208
    70  java                                0x00000001029fbbbc main + 392
    71  dyld                                0x0000000180537e50 start + 2544
)
libc++abi: terminating with uncaught exception of type NSException

1
由于您已经安装了JavaFX SDK,请参阅使用JavaFX SDK入门:运行HelloWorld,例如此处 - trashgod
2
但是你正在使用Maven,所以我建议卸载SDK并使用maven作为依赖项获取JavaFX模块。这样的配置会导致系统更简单、更易于维护。在trashgod提供的链接中也有关于这种方法的信息。使用最新的JavaFX版本19+,因为一些旧版本不包括M2支持或其中的M2支持存在错误。确保你没有将jar文件打包(在输出的jar文件中包含JavaFX类)。不要有一个调用JavaFX应用程序的主类,而是让JavaFX应用程序实现main方法。 - jewelsea
如果配置正确,您将不会收到此警告:“警告:不支持的JavaFX配置:类从 'unnamed module @56d120f3' 加载” - jewelsea
我遇到了完全相同的问题(同一台机器,同样的错误),在我进行软件更新之前它运行得非常好,也许这些信息可以提供一些见解? - Plegeus
这个问题与使用macOS SDK 13构建的JDK有关。在这里进行了描述(https://bugs.openjdk.org/browse/JDK-8296654)--希望很快就能得到解决。 - m0squito
显示剩余4条评论
2个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
1

这个问题在JDK 19.0.2中得到了修复(我使用JDK 19.0.1时也遇到了这个问题):

$ java -version
openjdk version "19.0.2" 2023-01-17
OpenJDK Runtime Environment (build 19.0.2+7-44)
OpenJDK 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)
$ uname -a
Darwin Juanans-MacBook-Air.local 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:52 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8112 arm64

只需下载最新的JDK(19.0.2)- 您可以从IntelliJ JDK设置中下载 - 并导出新的JAVA_HOME

$ export JAVA_HOME=/Users/juanan/Library/Java/JavaVirtualMachines/openjdk-19.0.2/Contents/Home

请确认您的mvn可执行文件是否使用了最新版本的JDK:

$ mvn --version
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /opt/homebrew/Cellar/maven/3.8.7/libexec
Java version: 19.0.2, vendor: Oracle Corporation, runtime: /Users/juanan/Library/Java/JavaVirtualMachines/openjdk-19.0.2/Contents/Home
Default locale: en_ES, platform encoding: UTF-8
OS name: "mac os x", version: "13.0.1", arch: "aarch64", family: "mac"

运行mvn脚本(在我的情况下为javafx:run):

$ mvn javafx:run

enter image description here


1
是的,我通过更改我的pom.xml文件来使用更新版本的open jfx成功解决了它。 - cupias

0
最有可能的问题不在于Java版本。

https://github.com/software-challenge/gui/pull/95

为了解决这个问题,尝试使用不同版本的JavaFX。 当我在MacOS上遇到相同的问题时,只有JavaFX版本21对我有帮助。 使用JavaFX版本21进行maven的示例可能如下所示。
...
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>11</maven.compiler.release>
        <javafx.version>21</javafx.version>
        <javafx.maven.plugin.version>0.0.8</javafx.maven.plugin.version>
    </properties>
...
17.0.1和18.0.1返回了相同的错误。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,