I’ve built a modular JavaFX application using JDK 21 and JavaFX SDK 21.0.1. The project runs perfectly inside my IDE (IntelliJ IDEA), but when I try to export it as a .jar file and run it outside the IDE, it throws the following error:
Error: JavaFX runtime components are missing, and are required to run this application.
Here’s my module-info.java file:
module com.rohan.unitconverter {
requires javafx.controls;
requires javafx.fxml;
opens com.rohan.unitconverter to javafx.fxml;
exports com.rohan.unitconverter;
}
I’ve already tried the following:
Added JavaFX SDK libraries to the classpath.
Used IntelliJ’s “Build Artifacts → JAR → From modules with dependencies”.
Ran with VM options:
--module-path "C:\javafx-sdk-21.0.1\lib" --add-modules javafx.controls,javafx.fxml
Still, the .jar fails to run independently.
What’s the correct way to bundle JavaFX dependencies into an executable .jar (or .exe) file so that it runs on any system without requiring external JavaFX setup?
java -jarthen you need to add a Class-Path header to the manifest of your JAR file.