0

I'm trying to create JavaFX project with Java 11 using Maven. I have added dependencies to the POM file, but when I try to run the application I get error:

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

If I run the application using Java 8 SE it launches and works normally.

I look at other SO posts but I can't find the solution. I tried to create new main file that then calls Application(myApplicationClass.class, args)

public class Main {
    public static void main(String[] args) {
        Application.launch(Launcher.class, args);
    }
}

but then I get this error:

Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>
    at com.sun.glass.ui.win.WinApplication.staticScreen_getScreens(Native Method)
    at com.sun.glass.ui.Screen.initScreens(Screen.java:412)
    at com.sun.glass.ui.Application.lambda$run$1(Application.java:152)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at com.sun.prism.d3d.D3DPipeline.getAdapterOrdinal(D3DPipeline.java:205)
    at com.sun.javafx.tk.quantum.QuantumToolkit.assignScreensAdapters(QuantumToolkit.java:695)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runToolkit(QuantumToolkit.java:313)
    at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$startup$10(QuantumToolkit.java:258)
    at com.sun.glass.ui.Application.lambda$run$1(Application.java:153)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)

This is my Launcher class:

public class Launcher extends Application {

   public static void main(String[] args) {
       launch(args);
   }

   @Override
   public void start(Stage primaryStage) {
       Scene rootScene = new MainMenu();
       AppContext.init(primaryStage, rootScene);

       primaryStage.setResizable(false);
       primaryStage.show();
   }

And this is my POM.xml

...
<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>11</release>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>hr.fer.zemris.gui.Main</mainClass>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-swing</artifactId>
        <version>11-ea+24</version>
    </dependency>
  </dependencies>
</project>
  • How do you run the app in the first case? From Eclipse (like a Java application) or from Maven (`mvn compile exec:java`)? For the second error, edit your question and post the launcher class. – José Pereda Apr 01 '19 at 11:04
  • Both time I run from Eclipse. I added the code for the second error. – ColdBlade97 Apr 01 '19 at 11:29
  • 1
    Running from Eclipse you have to configure the module-path options. See https://openjfx.io/openjfx-docs/#IDE-Eclipse. The launcher is wrong, see this [NewMain](https://stackoverflow.com/a/52654791/3956070) for a valid launcher class. – José Pereda Apr 01 '19 at 11:32

1 Answers1

0

I encountered the same problem using both OpenJDK version 12 and Oracle JDK version 12.

As a temporary solution, I reverted to Oracle JDK version 8. This eliminated the error.