【问题标题】:How to run a maven java fx project that includes jfoenix using javafx-maven-plugin如何使用 javafx-maven-plugin 运行包含 jfoenix 的 maven java fx 项目
【发布时间】:2020-04-28 01:11:37
【问题描述】:

我试图创建编译我的应用程序并创建一个可执行文件。至于现在,我认为最好的工具是 javafx-maven-plugin。

我无法让它工作,所以我从根据这个创建项目时生成的基本代码开始。

https://www.youtube.com/watch?v=4vd-RE0X5Lg

https://openjfx.io/openjfx-docs/#maven

基本示例有效,但是当我在我的代码中尝试相同的结构或简单地添加包含 jfoenix 的代码时。它无法运行。

下面的行似乎是错误的重要行,

原因:java.lang.IllegalAccessError:com.jfoenix.skins.JFXSpinnerSkin 类(com.jfoenix 模块中)无法访问 com.sun.javafx.scene.NodeHelper 类(javafx.graphics 模块中),因为模块 javafx。图形不会将 com.sun.javafx.scene 导出到模块 com.jfoenix

我该如何解决这个问题?

这是我到目前为止的 pom。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.openjfx</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>com.jfoenix</groupId>
            <artifactId>jfoenix</artifactId>
            <version>9.0.9</version>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                    <compilerArgs>
                        <arg>--add-opens</arg><arg>javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>org.openjfx.App</mainClass>
                    <options>
                        <option>--add-opens</option>
                        <option>javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED</option>
                    </options>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

【问题讨论】:

  • 您的问题不是很清楚,但是如果您需要有关 maven pom 的帮助,请告诉我。如果 JFoenix 与 JavaFX 11 及更高版本一起使用,它应该可以直接使用。让我看看有没有。
  • 您需要在 jvm 参数中添加 --add-opens javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED ;有一种方法可以在 Maven 中做到这一点,我无法让它工作。让我知道它是否有效。
  • 成功!我让它运行了

标签: java maven javafx jfoenix


【解决方案1】:

根据您分享的代码: https://github.com/Ealuthwala/javafx-export

我编辑了 POM 以便它运行,这是我看到的输出

我正在分享下面的 POM,只需使用这个 POM,它应该可以工作。

除此之外,您必须使用 JDK 11.0.2 或更低版本。您需要更改 IDE 的设置以为此项目选择 JDK 11.0.2 或更低版本。

因为您正在使用 JFoenix 的功能,这些功能不适用于更高版本的 JDK。原因在这里解释:https://github.com/jfoenixadmin/JFoenix/issues/955

有了这个,您将能够使用 GluonVM 和桌面、Linux、Mac 和 web(使用 JPro)、rasberry pie 等使此代码在移动设备(64 位 android 和 iPhone)上运行。所以实际上你不能拥有这有什么问题,除非你有很大的理由想要升级到 Jdk 12。如果你给时间,可能是一年,我相信 JFoenix 团队会修复它,如果它没有完成,你真的很喜欢 JFoenix有用的你可以投入并贡献修复或使用其他东西。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.openjfx</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source> <!-- DO NOT USE JDK greater than 11 -->
        <maven.compiler.target>11</maven.compiler.target> <!-- DO NOT USE JDK greater than 11 -->
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>com.jfoenix</groupId>
            <artifactId>jfoenix</artifactId>
            <version>9.0.9</version>
        </dependency>
        <dependency>
            <groupId>io.datafx</groupId>
            <artifactId>datafx</artifactId>
            <version>8.0.7</version>
        </dependency>
        <dependency>
            <groupId>io.datafx</groupId>
            <artifactId>flow</artifactId>
            <version>8.0.7</version>
        </dependency>
        <dependency>
            <groupId>org.kordamp.ikonli</groupId>
            <artifactId>ikonli-javafx</artifactId>
            <version>11.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.kordamp.ikonli</groupId>
            <artifactId>ikonli-fontawesome5-pack</artifactId>
            <version>11.4.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!--
        This is what will make the code actually run.
                This is taken from José Pereda's answer from
                https://stackoverflow.com/a/56467911/2448015
            -->
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>org.openjfx.App</mainClass>
                    <options>
                        <option>--add-opens</option><option>javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.base/com.sun.javafx.binding=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.base/com.sun.javafx.event=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.base/com.sun.javafx.binding=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.base/com.sun.javafx.event=ALL-UNNAMED</option>
                        <!--
                            Refer : https://github.com/jfoenixadmin/JFoenix/issues/889#issuecomment-450744122
                            In order to make jfoenix works, it should need less and doesn't need all of these.
                            You may have to go one by one to find what - - add-opens ... you'll need in your case.
                            - - add-opens is for enabling deep-reflection
                            - - add-exports is for direct access
                        -->
                    </options>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

【讨论】:

  • 感谢您的帮助。我根据这个改变了我的pom..但我一直收到完全相同的错误。
  • 和0.0.4版本的插件根本无法运行..我使用的是0.0.3版本
  • 是的,我就是这么运行的,没有任何变化,如果你可以看看我可以上传我的项目
  • @Eshaka 是的,请给,让我看看。同时下载我发送的代码并运行它,它会运行。只需执行mvn javafx:run
  • 是的,我试过了。一些依赖没有找到,所以我改变了一些版本。然后它开始工作。螺母代码不起作用
猜你喜欢
  • 2011-11-07
  • 1970-01-01
  • 2019-08-09
  • 2017-09-23
  • 1970-01-01
  • 1970-01-01
  • 2019-12-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多