Answer a question

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

Answers

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.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐