Home > Back-end >  Module javafx.controls not found error in VS Code
Module javafx.controls not found error in VS Code

Time:06-09

I have spent half a day trying to find a working solution for this, but either I'm doing everything wrong, or nothing is working for me. I'm new to Java and JavaFX specifically.

I'm using VSCode on Windows, and having installed the "Extension Pack for Java" and "Maven for Java" extensions, I created a project using JAVAFX archetype as a build method.

A sample project is generated and I run it without problems, even without adding a "launch.json" with "VMargs" etc.

My problem is when I run mvn package to make a jar file.

Trying to run the jar file like any other file does nothing. Then I tried to add the path for the JavaFX sdk and the modules by running:

java --module-path 'C:\Program Files\Eclipse Adoptium\jdk-11.0.15.10-hotspot\lib' --add-modules=javafx.controls,javafx.fxml -jar .\test.jar

that gives me the error:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found

I didn't put any code because I didn't change anything from the auto-generated code from VSCode. If you want it, I can paste it though.

Any help is appreciated. Thanks

CodePudding user response:

You are adding the module path of the jdk, not the JavaFX sdk.

Download the JavaFX sdk or modules from openjfx.io and place the lib directory from that on your module path instead of the jdk (which is there automatically).

Or use a distribution like liberica “full jdk” that includes JavaFX modules.

  • Related