How to fix Error: JavaFX runtime components are missing, and are required to run this application in a JAR file?

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>module com.example.project {
requires javafx.controls;
requires javafx.fxml;
opens com.example.project to javafx.fxml;
exports com.example.project;
}
</code>
<code>module com.example.project { requires javafx.controls; requires javafx.fxml; opens com.example.project to javafx.fxml; exports com.example.project; } </code>
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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Manifest-Version: 1.0
Main-Class: com.example.project.Project
</code>
<code>Manifest-Version: 1.0 Main-Class: com.example.project.Project </code>
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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> <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>
</code>
<code> <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> </code>
 <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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật