Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle run with `--add-exports`

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) [?:?]
like image 392
piegames Avatar asked Mar 03 '23 09:03

piegames


1 Answers

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

  • Make a modular project

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']
}
  • Export to all modules

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']
}
like image 108
José Pereda Avatar answered Mar 12 '23 07:03

José Pereda