并且是运行此应用程序所必需的

并且是运行此应用程序所必需的

本文介绍了如何解决“错误:缺少JavaFX运行时组件,并且是运行此应用程序所必需的"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JavaFx应用程序从源代码运行得很好,但是当我编译为单个jar文件时,出现错误消息:

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

我正在使用Maven作为我的存储库管理器,并且使用Maven的安装已成功完成.

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

注意:在我的Intellij构建工件中,我可以看到Intellij包括JavaFx及其所有库

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

推荐答案

a)对于我的Maven项目,诀窍是使用不继承自javafx.application.Application的额外启动器类:

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

}

我的pom.xml中包含JavaFx依赖项,如下所示:

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>

为了在构建中包含fxml文件,您可能需要将它们定义为资源:

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)作为替代方案,可以使用一个额外的maven插件"javafx-maven-plugin"来构建javafx应用程序,请参见 https://openjfx.io/openjfx-docs/#maven (这对我不起作用.我有几个pom文件,想在子目录中引用javafx依赖项项目.javafx-maven-plugin无法找到我的主类.)

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.)

这篇关于如何解决“错误:缺少JavaFX运行时组件,并且是运行此应用程序所必需的"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 19:24