1

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:

  1. Added JavaFX SDK libraries to the classpath.

  2. Used IntelliJ’s “Build Artifacts → JAR → From modules with dependencies”.

  3. 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?

5
  • 4
    Try jpackage, if stuck you can see lot of info by searching for "jpackage javafx" (including many SO duplicates) Commented Oct 29 at 12:57
  • 4
    Also see the tag wiki, under "Packaging". The short answer is not to create an executable jar, but a native package bundle which includes a JRE and the JavaFX runtime. Commented Oct 29 at 13:01
  • 1
    Probably a duplicate of stackoverflow.com/questions/52467561/…. Commented Oct 29 at 15:15
  • After creating your JAR file, how are you running it? Are you using java -jar command? If you are, then please edit your question and post the entire command (and not just the options). And if you are issuing command java -jar then you need to add a Class-Path header to the manifest of your JAR file. Commented Oct 30 at 11:58
  • Unfortunately Idea's "Build Artifacts" task doesn't work well to package JavaFX applications, so the methods in comments above are recommended instead. Commented Oct 30 at 15:30

1 Answer 1

-2

For .jar file it is in dist file after u click on project with right click inside the ide and find build or clean and build, go to folder of project u'll find dist folder, inside this folder called dist , u can find lib folder and .jar

after that, u can build .exe using the jpackage with that .jar file and use the jre u used in development.

In case, u still faced problem with some dependencies, u can build ur own jre customized with libs included in ur project using jlink

Sign up to request clarification or add additional context in comments.

4 Comments

"Error: JavaFX runtime components are missing" means that the JavaFX native components (e.g. dll or so files) are missing. The JavaFX SDK jars don't include those native components. They are included in the JavaFX jars hosted in Maven for particular platform classifiers or in jmods for target architectures, but the asker isn't using either of those options. On the option you mentioned for "own jre", info on how to do that using jmods is at openjfx.io under the section entitled "Runtime Images | Custom JDK+JavaFX image".
well for my case i didnt need to use maven and i did that method and it worked so well the .dll i get them by copying from bin folder of jdk to bin folder of my software where i created to jpackage it .. it did for version 1.0.0 and now i'm working with same for 1.1.1 and now i only do the jpackage with jar file and if some libs are added i add them onto lib folder and voilà i get my .exe file ✅
and he didn't mention maven so i thought my method will work for him
Your original answer didn't mention your extra manual steps of: "the .dll i get them by copying from bin folder of jdk to bin folder of my software where i created to jpackage it .. it did for version 1.0.0 and now i'm working with same for 1.1.1 and now i only do the jpackage with jar file and if some libs are added i add them onto lib folder and voilà i get my .exe file", which is critical to allow your suggested approach to work. I suggest you edit your answer so that it contains a self-contained replicable solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.