首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用javafx- maven -plugin运行包含jfoenix的maven java fx项目

如何使用javafx- maven -plugin运行包含jfoenix的maven java fx项目
EN

Stack Overflow用户
提问于 2020-04-28 01:11:37
回答 1查看 1.8K关注 0票数 1

我试图创建、编译我的应用程序并创建一个可执行文件。就目前而言,我看到最好的工具是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.graphics没有将com.sun.javafx.scene导出到模块com.jfoenix

我怎么才能解决这个问题?

到目前为止这是我的pom。

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-28 06:14:02

基于您共享的代码:https://github.com/Ealuthwala/javafx-export

我编辑了POM并使其运行,这就是我看到的输出

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

除此之外,您还必须使用JDK11.0.2或更低版本。您需要更改IDE的设置,以获取此项目的JDK11.0.2或更低版本。

因为您使用的是JFoenix的特性,它不能使用更高版本的JDK。原因在这里解释:https://github.com/jfoenixadmin/JFoenix/issues/955

这样,您就可以使用GluonVM、桌面、Linux、Mac和web (使用JPro)和rasberry饼等在移动(64位android和GluonVM)上运行这段代码。因此,实际上,除非您有非常大的理由想要升级到Jdk 12,否则实际上您不会有任何问题。如果您给出时间,可能需要一年时间,我相信JFoenix团队会修复它,如果它没有完成,而且您真的发现JFoenix非常有用,您可以选择使用这些补丁,或者使用其他的东西。

代码语言:javascript
运行
复制
<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>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61471051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档