由于在 Java > 9 中使用了 java.lang.IllegalAccessError
类,我得到了 com.sun.*
。解决方案是添加 --add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls
。我不知道如何将它添加到我的 build.gradle
,但我把
run {
jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls']
}
进入它并没有帮助。 This 几乎是我遇到的问题。错误信息是:
java.lang.IllegalAccessError: class org.controlsfx.control.textfield.AutoCompletionBinding (in unnamed module @0x2d7444bc) cannot access class com.sun.javafx.event.EventHandlerManager (in module javafx.base) because module javafx.base does not export com.sun.javafx.event to unnamed module @0x2d7444bc
at org.controlsfx.control.textfield.AutoCompletionBinding.<init>(AutoCompletionBinding.java:522) ~[controlsfx-11.0.0.jar:11.0.0]
at impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding.<init>(AutoCompletionTextFieldBinding.java:107) ~[controlsfx-11.0.0.jar:11.0.0]
at org.controlsfx.control.textfield.TextFields.bindAutoCompletion(TextFields.java:151) ~[controlsfx-11.0.0.jar:11.0.0]
[…]
at java.lang.Thread.run(Thread.java:835) [?:?]
最佳答案
看起来您没有模块化项目。有两个选项可以解决它:
如果添加模块信息描述符,例如:
module hellofx {
requires javafx.controls;
requires org.controlsfx.controls;
exports org.openjfx;
}
(当然,在那里添加您的模块),它将适用于:
run {
jvmArgs = ['--add-exports= \
javafx.base/com.sun.javafx.event=org.controlsfx.controls']
}
由于您的项目不是模块化的,它是所谓的未命名模块的一部分。因此,您应该使用
ALL-UNNAMED
,以便将包导出到所有模块,包括 ControlsFX:run {
jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED']
}
关于java - 使用 `--add-exports` 运行 Gradle,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58082298/