sshahine / JFoenix

JavaFX Material Design Library
MIT License
6.3k stars 1.06k forks source link

module java.base does not "opens java.lang.reflect" to module com.jfoenix #1200

Open FelipeAumannRS opened 3 years ago

FelipeAumannRS commented 3 years ago

Hello everyone,

Before start describing how I'm getting this error, here is some important information:

  1. It is essential the usage of the module-info.java in my project since jpackage won't work without using it.
  2. I'm using SDK 14.0.2 (this is the minimum version that enables the usage of jpackage)
  3. Every comment will be appreciated; although, if you're going to comment something related to using a specific VM argument, I ask you to press ctrl+F to check if I'm already using the argument you're going to suggest -since there's a bunch of VM arguments in my build.gradle

Ok, let's take a look about my issue:

First, focus on the VM argument below:

"--add-opens=java.base/java.lang.reflect=com.jfoenix",

If I don't use this argument, the following error pops up when the program runs:

java.lang.reflect.InaccessibleObjectException: Unable to make boolean java.lang.reflect.AccessibleObject.setAccessible0(boolean) accessible: module java.base does not "opens java.lang.reflect" to module com.jfoenix

IMPORTANT -> This is how my view shows without using the mentioned VM argument (let's call it image 1):https://snipboard.io/QJ5Fdc.jpg

"Ok, so why don't you just use the VM argument?" Great question! Alright, let's add it to my VM arguments and run the program once again.

After doing so, this is how my view looks like right now (let's call it image 2): https://snipboard.io/fbhGxw.jpg

Great! This is exactly how my view should be (note that considering it worked as expected, I've got no errors this time).

So, with everything working, I can finally move on and run my jpackage gradle task. After doing so, things stop making sense, since my view looks like the "image 1" view, regardless the fact that my project is working properly when I run it with the "run" gradle task.

### Any thoughts on why is this happening? (My guess is that my module-info.java is the key to solve it, since every time I remove an "opens" statement, e.g.: "opens my.package.name to javafx.fxml", the program gets me almost the equal error).

Let me know whether any code samples will be needed. All assistance will be appreciated. Thanks!

related stack overflow question: https://stackoverflow.com/questions/67302959/module-java-base-does-not-opens-java-lang-reflect-to-module-com-jfoenix

FelipeAumannRS commented 3 years ago
def args = [
        "--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED",
        "--illegal-access=warn",
        "--add-opens=javafx.controls/javafx.scene.control.skin=com.jfoenix",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
        "--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix",
        //the next line changes everything.
        **"--add-opens=java.base/java.lang.reflect=com.jfoenix",**

        "--add-exports=javafx.controls/javafx.scene.control.skin=com.jfoenix",
        "--add-exports=java.base/java.lang.reflect=ALL-UNNAMED",
        "--add-exports=java.base/java.lang.reflect=com.jfoenix",
        "--add-exports=javafx.controls/com.Sun.javafx.scene.control.behavior=com.jfoenix",
        "--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",

        "--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED",

        "--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior" +
                "=ALL-UNNAMED",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior" +
                "=com.jfoenix",
        "--add-exports=javafx.controls/com.sun.javafx.binding=com.jfoenix",
        "--illegal-access=warn",
        "--add-opens=javafx.controls/javafx.scene.control.skin=com.jfoenix",
        "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior" +
                "=com.jfoenix",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
        "--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix",
        "--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
        "--add-exports=javafx.base/com.sun.javafx.event=com.jfoenix",

        "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
        "--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
        "--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix",
        "--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
        "--add-exports=javafx.base/com.sun.javafx.event=com.jfoenix"
]

run {
    jvmArgs = args
}
JJBRT commented 3 years ago

Please take a look at my new article that explain how to export all modules to all modules at runtime in Java 16 and later without using any JVM parameter

souhaib100 commented 3 years ago

@FelipeAumannRS I suggest to switch to non-modular project by removing the module-info.java, and use the plugin https://github.com/beryx/badass-runtime-plugin to make the executable. And for error module java.base does not "opens java.lang.reflect" add this library https://www.burningwave.org, and then make this call inside your init() in your main class: Modules.create().exportAllToAll(); See below for optimized solution. Hop this will help.

Roberto-Gentili commented 3 years ago

@FelipeAumannRS I suggest to switch to non-modular project by removing the module-info.java, and use the plugin https://github.com/beryx/badass-runtime-plugin to make the executable. And for error module java.base does not "opens java.lang.reflect" add this library https://www.burningwave.org, and then make this call inside your init() in your main class: Modules.create().exportAllToAll(); Hop this will help.

Note that in this way the Modules.exportAllToAll() method is called twice because this method is called automatically when the StaticComponentContainer class is initialized and since the Modules class makes use of components that are in the StaticComponentContainer class, when you call the Modules.create() you have practically already called the Modules.exportAllToAll(). To change this behavior by allowing only the manual invocation of the Modules.exportAllToAll() methods it is necessary to include in the base folder of your class path a file named burningwave.static.properties which contains a property named module.export-all-to-all whose value is false (note that it is not necessary to put in the burningwave.static.properties file all the properties present in the previous link). Note also that is better to call org.burningwave.core.assembler.StaticComponentContainer.Modules.exportAllToAll() (copy this entire line) instead of creating a new Modules component.

souhaib100 commented 3 years ago

@Roberto-Gentili , yes , I didn't notice that. After some debugging you need just to use the class StaticComponentContainer in any ways, ex: org.burningwave.core.assembler.StaticComponentContainer.JVMInfo.getVersion() and this will automatically create the class and call Modules.exportAllToAll() only one time.

Roberto-Gentili commented 3 years ago

@Roberto-Gentili , yes , I didn't notice that. After some debugging you need just to use the class StaticComponentContainer in any ways, ex: org.burningwave.core.assembler.StaticComponentContainer.JVMInfo.getVersion() and this will automatically create the class and call Modules.exportAllToAll() only one time.

Exactly! and remember that you can change this behavior by allowing only manual calls to the exportAllToAll method by following the instructions in the previous answer