尝试使用 maven 编译 JavaFX 项目时断言失败

cup*_*ias 8 java terminal javafx maven

我正在开发一个 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)
Run Code Online (Sandbox Code Playgroud)

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"
Run Code Online (Sandbox Code Playgroud)

PS 我是 Maven 新手,这是我关于堆栈溢出的第一篇文章。任何提示表示赞赏。

这是脚本:

1 #!/bin/bash -ex  
2
3 mvn -q -e clean
4 mvn -q -e compile
5 mvn -q -e exec:java
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪:

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
Run Code Online (Sandbox Code Playgroud)

Jua*_*nan 2

这已在 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)
Run Code Online (Sandbox Code Playgroud)
$ 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
Run Code Online (Sandbox Code Playgroud)

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

$ export JAVA_HOME=/Users/juanan/Library/Java/JavaVirtualMachines/openjdk-19.0.2/Contents/Home
Run Code Online (Sandbox Code Playgroud)

仔细检查您的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"
Run Code Online (Sandbox Code Playgroud)

并运行你的 mvn 脚本(javafx:run在我的例子中):

$ mvn javafx:run
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述