How to fix "Error: JavaFX runtime components are missing, and are required to run this application"

16,552

a) For my maven project the trick was to use an extra starter class that does not inherit from javafx.application.Application:

public class GUIStarter {

    public static void main(final String[] args) {
        GUI.main(args);
    }

}

The JavaFx dependencies are included in my pom.xml as follows:

<!-- JavaFx -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>12</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>12</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics </artifactId>
            <version>12</version>
            <classifier>win</classifier>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>12</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>12</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>12</version>
        </dependency>

         <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>12</version>
        </dependency>

In order to include fxml files in your build, you might need to define them as resource:

!-- define JavaFx files as resources to include them in the jar -->
<resource>
      <directory>${basedir}/src/main/java/foo/baa/view</directory>
      <filtering>false</filtering>  
      <targetPath>foo/baa/view</targetPath>            
</resource>

b) As an alternative, an extra maven plugin "javafx-maven-plugin" could be used to build the javafx appication, see example project at https://openjfx.io/openjfx-docs/#maven (This did not work for me. I have several pom files and want to reference the javafx dependencies in a sub project. My main class could not be found by the javafx-maven-plugin.)

Share:
16,552
Hilary Okoro
Author by

Hilary Okoro

Updated on July 29, 2022

Comments

  • Hilary Okoro
    Hilary Okoro over 1 year

    My JavaFx application is running perfectly well from source but When I'm compiling to a single jar file I get error :

    Error: JavaFX runtime components are missing, and are required to run this application.

    I'm using Maven as my repository manager and My install with Maven is sucessfull.

    Note: In my Intellij build artifact I can see that Intellij include JavaFx and all its libraries

  • Hilary Okoro
    Hilary Okoro almost 5 years
    JavaFx is in my module
  • Hilary Okoro
    Hilary Okoro over 4 years
    I have resolved that issue. Maven is repository is not including my libraries during compiling to a single jar file. I had to stop using maven for the compilation and move my source to different project then manually compile it myself
  • Doc
    Doc almost 4 years
    The extra starter class worked for me. Using Netbeans 11.3, I created a new project using "FXML JavaFX Maven Archetype (Gluon)" which could build but not run. The question is "why does this work?"
  • Stefan
    Stefan almost 4 years
    @Doc See info about "sun.launcher.LauncherHelper" here: mail.openjdk.java.net/pipermail/openjfx-dev/2018-June/…