Gradle使用--add-exports运行 [英] Gradle run with `--add-exports`

查看:686
本文介绍了Gradle使用--add-exports运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于在Java> 9中使用了com.sun.*类,因此得到了java.lang.IllegalAccessError.解决方案是添加--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls.我不确定如何将其添加到我的build.gradle中,但是我放了

I got a java.lang.IllegalAccessError because of using a com.sun.* class in Java >9. The solution to this is to add --add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls. I'm not sure how to add this to my build.gradle, but I put

run {
    jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls']
}

进入它并没有帮助. 几乎是我遇到的问题.错误消息是:

into it and it didn't help. This is pretty much the issue I have. The error message is:

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) [?:?]

推荐答案

您似乎没有模块化项目.有两种解决方法:

It looks like you don't have a modular project. There are two options to solve it:

  • 进行模块化项目

如果添加模块信息描述符,例如:

If you add a module-info descriptor, like:

module hellofx {
    requires javafx.controls;
    requires org.controlsfx.controls;

    exports org.openjfx;
}

(当然要在其中添加模块),它可以与:

(adding your modules there, of course), it will work with:

run {
    jvmArgs = ['--add-exports= \
                javafx.base/com.sun.javafx.event=org.controlsfx.controls']
}

  • 导出到所有模块
  • 由于您的项目不是模块化的,因此它是所谓的未命名模块的一部分.因此,您应该使用ALL-UNNAMED,以便将包导出到所有模块,包括ControlsFX:

    Since your project is not modular, it is part of the so called unnamed module. Therefore, you should use ALL-UNNAMED, so the package is exported to all the modules, including ControlsFX:

    run {
        jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED']
    }
    

    这篇关于Gradle使用--add-exports运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆