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

本小妞迷上赌 提交于 2020-08-11 03:15:34

问题


I'm working migrating my Maven JavaFX app from Java 8 to Java 11. Iv'e updated the plugins in my pom.xml to the most current (Java 11 compliant) plugins. Compilation runs fine, giving me the jars and all dependencies and modules in the right directories under the "target" folder but when I try to run my jar file I get the dreaded "Missing JavaFX application class " error. No matter how I try to change the plugin configuration - I always get this error msg and the app won't run.

Now, more findings : 1. The main class DOES reside in the right folder under classes and in the jar. 2. The Manifest file is in the right place and contains the main class attribute (which worked fine under Java 8).

Here is the relevant part of the

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

I'm running the jar by including the JavaFX modules as described in the documentation :

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

In my frustration Iv'e tried endless configurations, including using the configuration from the JavaFx Java 11 samples. Nothing works.

Any ideas?


回答1:


I found a workaround at https://github.com/javafxports/openjdk-jfx/issues/236.

This workaround includes creating a new, regular (non Java Fx) class that will be the main class of the Jar and this class will launch the original JavaFx based application class.

This is the new class from the link where I found the workaround:

public class Main {

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

Hope this helps someone. I'm not marking this answer as the correct one due to the fact that it's a workaround and not a real solution.

EDIT : it turns out that the workaround described in the JavaFX documentation here : 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.



来源:https://stackoverflow.com/questions/54861520/maven-javafx-project-compiles-but-running-from-console-give-missing-javafx-appl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!