mavenintellij-ideamaven-shade-pluginopenjfxjava-16

JavaFX16: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @...'


I have a Maven multi-module project on IntelliJ that produces 3 jars, 2 of which are executables and the other one is for commmon resources.

One of the executable modules has a main class that asks if the user wants to start the program with CLI or GUI.

Running this main from IntelliJ works without problem, instead when I use Maven to make the jar (using maven shade):

mvn package -pl myModule -am

and then launch the jar with GUI option, this warning appears:

com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @...'

The GUI then starts without problems.

How can I get rid of this warning? The JDK of my project is openJDK 16 (I've already added module-info.java in order to work with javafx), openJFX 16, maven shade plugin 3.2.4, maven compiler plugin 3.8.1.

If there's need to add furthermore information, I'll add them.


Solution

  • It seems that maven is shading the JavaFX jars into a single fat jar.

    Shading multiple modules into the same jar is not possible, because a jar can only contain 1 module. So, I suppose the shade plugin resolves that problem by removing the module-info files of the dependencies it's using, which means the JavaFX code will not be loaded as a module, and you get a warning like this.

    I think the only way to get rid of the warning is to not use shading, but keep the JavaFX modules as separate jar files, that you then put on the module path when running the application.