In a non-modular app that uses ControlsFX's GridView (ControlsFX version = '11.1.1', JDK 17), if I run it in an Eclipse launch configuration with the VM arguments settings (in the (x)=Arguments tab) with the same --add-opens and --add-export arguments as shown in the code snippet below, the app runs just fine.
However, when I invoke gradle run from the Gradle Tasks view in Eclipse, with the following run block, the result is
java.lang.IllegalAccessError:
class org.controlsfx.control.spreadsheet.GridBase (in unnamed module @0x73a0cead)
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 @0x73a0cead
Here's the run block in build.gradle for the project.
run {
jvmArgs
'--add-opens=javafx.controls/javafx.scene.control.skin=org.controlsfx.controls \
--add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED \
--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls \
--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED \
--add-exports=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls, \
--add-exports=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls \
--add-exports=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls \
--add-exports=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls \
--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls'
}
the app runs, but the FXML views that include a GridView are empty windows (as expected given the above error).
You can clearly see that the export of javafx.base/com.sun.javafx.event is specified in the run block. Yet the behavior of gradle run is different (failure) from that of the launch configuration (success).
Any thoughts on what is causing the failure would be greatly appreciated.
I finally settled on the following way to set the jvmArgs for the run task. Since I'm doing this in Eclipse (Spring Tool Suite, actually), the relevant contents of
build.gradleare:The
applicationblock is where one setsapplicationDefaultJvmArgs(seems like a poor choice to use "Default" since these are custom settings!):Gradle Application plugin documentation is here.
In my case, I set the
jvmArgsvalue in theextblock. Note that I have to include a bunch of otheradd-exportandadd-opensbecause I use quite a few other controls from the ControlsFX project. See Using ControlsFX with JDK 9 and above for notes on individual controls.To use ControlsFX GridView in JavaFX 9+, add the following:
which are the last two items in the
jvmArgslist above.There's a difference between setting these jvmArgs in an Eclipse launch configuration and executing the
runtask in Gradle: the launch configuration does not seem to requireThat's where I was being thrown off.
Side-note: honestly, I don't know where I got the notion that the
runblock accepted a string forjvmArgs.