Skip to content
Advertisement

Can JavaFX realistically be used in a non-modular environment?

I’ve attempted to use JavaFX by following instructions found at:

https://openjfx.io/openjfx-docs/ under “JavaFX and IntelliJ” -> “Non-modular with Maven”

After completing steps 1 & 2 (Installation & Verification) I attempted to run a very simple program from IntelliJ rather than through the Maven plugin.

TraderWindow.java

JavaScript

TraderWindow.fxml

JavaScript

However when I attempted to run it I got:

JavaScript

The relevant part:

JavaScript

Which, I guess, is understandable since JafaFx is modularized and my application is not. In order to circumvent the problem I added this to VM path:

--add-opens javafx.graphics/com.sun.javafx.util=ALL-UNNAMED

I tried again, this time getting:

JavaScript

And so I added another –add-opens directive… And then I repeated these steps 3 more times before giving up.

Is there another way of making JavaFX work with Java 11+ rather than modularizing the application or painstakingly adding --add-opens directives for each and every illegal access operation?

Advertisement

Answer

If you completely want to get rid of all this module system trouble you could add a line like this to your main class

JavaScript

and then launch the app via this launcher. If you do that you can put everything on the classpath and remove all -add-opens. (actually you have to.) The only drawback is that since JavaFX 16 you will get a nasty warning message saying Unsupported JavaFX configuration but you can just ignore that.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement