When I build a jar file for my JavaFX application and try to run the jar file found out in /home/myusername/IdeaProjects/Myproject/out/artifacts/Project_jar opening it with Openjdk does not work. I tried in the terminal with java -jar and it throws the error:
Error: JavaFX runtime components are missing, and are required to run this application
I have searched on stackoverflow and on youtube but all the answers I could find were about how to fix this issue happening when a user tries to run their program in the IDE. I have this issue when I try to launch my jar. I know it is related to the fact that JavaFX is not part jdk anymore but it is a separated module and that you have to add JavaFX to your IDE, which I did as I can run the program in IntelliJ fine.
Moreover when I look into the jar file I can see a javafx folder which means IntelliJ added it to the jar. Unfortunately the error does not tell which components are missing so I don’t know what to do.
I have seen that often the issue is about not having a module-info.java or MANIFEST.MF but I do have them:
this is my module-info.java:
module com.example.project {
requires javafx.controls;
requires javafx.fxml;
opens com.example.project to javafx.fxml;
exports com.example.project;
}
this is my MANIFEST.MF:
Manifest-Version: 1.0
Main-Class: com.example.project.Project
I am not sure whether Intellij is using Maven for the build (I think so) so here is also the dependencies in pom.xml:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
These are my settings in project structure:
in Project→SDK: 17
In Project→Language level SDK default (17)
in Project→ Libraries: javafx.control,javafx.graphics,javafx.base,javafx.fxml and Junit libraries
In Platform Settings→SDK: 17 openjdk-15 (This was the version I used when my program was on an older computer)
In Platform Settings → Global Libraries: javafx-sdk-17.0
This is my Run/Debug Configuration
I added my project class to the main class space and following online instructions I added as VM option:
–module-path /home/myusername/Downloads/javafx-sdk-17.0.10/lib –add-modules=javafx.controls,javafx.fxml,
In an attempt to fix the error I tried adding javafx.base and javafx.graphics both to the module-info.java file and to the Run/Debug Configuration. I am not sure whether they are required or not by my app as in the IDE the program runs fine without them but in a video I saw that javafx.graphics was added to launch a hello world app (and both libraries are present in my project libraries) so I thought maybe they are require. However after that, I tried running my program in the IDE and I get the following error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module com.example.myproject not found
So I just removed them.
Any help to fix the issue would be appreciated.
ps: The type of Run/Debug Configuration is Application not Jar Application. I moved my project from another computer and don’t remember which type I used before (it was working on the other computer). When I opened the configuration on my new computer it was empty and first I made a Jar Application configuration but the jar file threw the same error as I am reporting now, so I deleted it and made the current one as Application. I don’t know whether that matters.