gradlejavafxjfoenixmodule-infojpackage

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


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 package)
  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 after executing my program through a .exe (generated by jpackage) 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!

edit: related GitHub issue: enter link description here


Solution

  • The only way I found to properly fix this issue is using BurningWave:

    <dependency>
            <groupId>org.burningwave</groupId>
            <artifactId>core</artifactId>
            <version>12.62.6</version>
    </dependency>
    

    After adding the dependency, just copy/paste this code into your init() method (this method can be -and should- override the init method in your class which extends Application class, which is your JavaFX application entry point)

    org.burningwave.core.assembler.StaticComponentContainer.Modules.exportAllToAll();
            Class<?> bootClassLoaderClass = Class.forName("jdk.internal.loader.ClassLoaders$BootClassLoader");
    
            Constructor<? extends ClassLoader> constructor = ClassLoader.getPlatformClassLoader().getClass().getDeclaredConstructor(bootClassLoaderClass);
    
            constructor.setAccessible(true);
            Class<?> classLoadersClass = Class.forName("jdk.internal.loader.ClassLoaders");
    
            Method bootClassLoaderRetriever = classLoadersClass.getDeclaredMethod("bootLoader");
    
            bootClassLoaderRetriever.setAccessible(true);
    

    EDIT

    Answering to @KenobiBastila comment, I don't know about the banner since I didn't had the necessity to remove it, but I did had to remove the BurningWave logs. In order to do so, create a burningwave.static.properties file under resources folder. Add these lines in it:

        managed-logger.repository=autodetect
        managed-logger.repository.enabled=false