如何使用javafx-maven-plugin运行包含jfoenix的maven Java fx项目 [英] How to run a maven java fx project that includes jfoenix using javafx-maven-plugin

查看:650
本文介绍了如何使用javafx-maven-plugin运行包含jfoenix的maven Java fx项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建编译我的应用程序并创建一个可执行文件.就目前而言,我看到使用的最佳工具是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>

解决方案

基于您共享的代码: 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>

i was trying to create compile my application and create an executable file. as for now i see the best tool to use is javafx-maven-plugin.

i couldn't get it to work, so i started with a basic code that is generated when creating a project according to this.

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

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

the basic example works but when i tried the same structure in my code or by simply adding a code that contains jfoenix to it. it cannot run.

following line seems to be the important line of the error,

Caused by: java.lang.IllegalAccessError: class com.jfoenix.skins.JFXSpinnerSkin (in module com.jfoenix) cannot access class com.sun.javafx.scene.NodeHelper (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.scene to module com.jfoenix

how can i fix this?

this is pom i has sofar.

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

解决方案

Based on the code you shared : https://github.com/Ealuthwala/javafx-export

I edited and the POM so that it runs, and this is the output I see

I am sharing the POM below, just use this POM and it should work.

Apart from this you must use JDK 11.0.2 or lower. You need to change settings of your IDE to pick up JDK 11.0.2 or lower for this project.

Because you are using features of JFoenix which will not work with a higher version of JDK. Reason is explained here : https://github.com/jfoenixadmin/JFoenix/issues/955

With this you will be able to make this code run on mobile (64-bit android and iPhone ) using GluonVM, and Desktop, Linux, Mac, and web (using JPro), rasberry pie etc. So practically you cannot have any problem with this unless you have a very big reason for wanting to upgrade to Jdk 12. If you give time, may be a year, I am sure JFoenix team will fix it, if it is not done, and you really find JFoenix very useful you can either pitch in and contribute the fixes or use something else.

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

这篇关于如何使用javafx-maven-plugin运行包含jfoenix的maven Java fx项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆