使用Maven编译JavaFX项目时触发断言失败问题求助
JavaFX项目终端Maven编译执行失败(M2 MacBook Air)
我正在开发一个JavaFX项目,在IntelliJ里能正常编译运行,但用终端执行Maven脚本时失败。设备是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新手,第一次提问,欢迎任何建议。
编译脚本
#!/bin/bash -ex mvn -q -e clean mvn -q -e compile 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
问题分析与解决建议
修复模块加载配置
报错开头的Unsupported JavaFX configuration提示JavaFX类未以模块方式加载。IntelliJ会自动处理模块配置,但终端执行Maven时需手动配置:- 在
pom.xml中引入org.openjfx:javafx-maven-plugin,明确指定模块名和主类:<plugin> <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>0.0.8</version> <configuration> <mainClass>你的主类全限定名</mainClass> <moduleName>你的模块名</moduleName> </configuration> </plugin> - 执行时直接用
mvn javafx:run替代exec:java,插件会自动处理模块路径和依赖。
- 在
适配M2 ARM架构
M2是ARM64架构,需确保JavaFX依赖对应平台:- 在pom.xml的JavaFX依赖中添加
mac-aarch64分类器:<dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> <version>19</version> <classifier>mac-aarch64</classifier> </dependency> - 建议使用JavaFX 19及以上版本,对ARM64的兼容性更好。
- 在pom.xml的JavaFX依赖中添加
优化执行脚本
将三次Maven调用
相关产品推荐
相关产品推荐

