Maven JavaFx 项目编译但 运行 从控制台给出 "Missing JavaFX application class" 错误消息

Maven JavaFx project compiles but running from console give "Missing JavaFX application class" error msg

我正在将我的 Maven JavaFX 应用程序从 Java 8 迁移到 Java 11。我已经将我的 pom.xml 中的插件更新到最多当前(Java 11 个兼容)插件。 编译 运行 很好,在 "target" 文件夹下的正确目录中为我提供了 jars 和所有依赖项和模块,但是当我尝试 运行 我的 jar 文件时,我得到了可怕的 "Missing JavaFX application class " 错误。无论我如何尝试更改插件配置 - 我总是收到此错误消息并且应用程序不会 运行.

现在,更多发现: 1. 主要 class 确实位于 classes 下的正确文件夹和 jar 中。 2. Manifest 文件位于正确的位置并包含主要 class 属性(在 Java 8 下工作正常)。

这是

的相关部分
<plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
            <source>11</source>
            <release>11</release>
            <showWarnings>true</showWarnings>
            <showDeprecation>true</showDeprecation>
            <compilerVersion>11</compilerVersion>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.ow2.asm</groupId>
                <artifactId>asm</artifactId>
                <version>7.0</version>
            </dependency>
        </dependencies>
</plugin>
<plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                   <addClasspath>false</addClasspath>
                   <mainClass>${mainClass}</mainClass>
                </manifest>
                <manifestEntries>
                   <JavaFX-Application-Class>${mainClass}</JavaFX-Application-Class>
                </manifestEntries>
             </archive>
             <outputDirectory>${project.build.directory}/libs</outputDirectory>
        </configuration>
</plugin>
<plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
                <execution>
                        <id>copy-libs</id>
                        <phase>prepare-package</phase>
                        <goals>
                                <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                                <outputDirectory>${project.build.directory}/libs</outputDirectory>
                                <includeScope>runtime</includeScope>
                                <excludeGroupIds>org.openjfx</excludeGroupIds>
                        </configuration>
                </execution>
                <execution>
                        <id>copy-modules</id>
                        <phase>prepare-package</phase>
                        <goals>
                                <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                                <outputDirectory>${project.build.directory}/mods</outputDirectory>
                                <includeScope>runtime</includeScope>
                                <includeGroupIds>org.openjfx</includeGroupIds>
                        </configuration>
                </execution>
        </executions>

我 运行 通过包含文档中所述的 JavaFX 模块来安装 jar :

java -verbose --module-path ../mods \
    --add-modules javafx.controls,javafx.graphics,javafx.fxml,javafx.swing \
     -jar jar-file-name.jar \
     package.class.MainClass

令我沮丧的是,我尝试了无穷无尽的配置,包括使用 JavaFx Java 11 个示例中的配置。什么都不管用。

有什么想法吗?

我在 https://github.com/javafxports/openjdk-jfx/issues/236 找到了解决方法。

此解决方法包括创建一个新的常规(非 Java Fx)class,它将成为 Jar 的主要 class,并且此 class 将启动原始 Java基于 Fx 的应用程序 class。

这是 link 中的新 class,我在其中找到了解决方法:

public class Main {

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

希望这对某人有所帮助。我没有将此答案标记为正确答案,因为它是一种解决方法而不是真正的解决方案。

编辑:事实证明,此处 JavaFX 文档中描述的解决方法:https://openjfx.io/openjfx-docs/#modular

As explained here, in order to create a runnable jar with all the required JavaFX dependencies, you will need to use a launcher class that doesn't extend from Application.