收到错误:尝试启动 javaFX 应用程序时"JavaFX runtime components are missing, and are required to run this applicati



我正在尝试使用 Maven 使用 Java 11 创建 JavaFX 项目。我已经在POM文件中添加了依赖项,但是当我尝试运行应用程序时,出现错误:

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

如果我使用 Java 8 SE 运行应用程序,它会启动并正常工作。

我查看其他SO帖子,但找不到解决方案。我试图创建新的主文件,然后调用应用程序(myApplicationClass.class,args(

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

但随后我收到此错误:

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)

这是我的启动器类:

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();
   }

这是我的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>

我在使用 OpenJDK 版本 12 和 Oracle JDK 版本 12 时遇到了同样的问题。

作为临时解决方案,我恢复到Oracle JDK版本8。 这消除了错误。

相关内容

  • 没有找到相关文章

最新更新