微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

运行javafx应用程序-引导层初始化期间发生错误:java.lang.module.ResolutionException

如何解决运行javafx应用程序-引导层初始化期间发生错误:java.lang.module.ResolutionException

正如标题所述,我只是尝试运行javafx应用程序。但是,我不知道为什么会收到此错误,也不知道为什么该错误引用了sisu.inject.beanaopalliance模块。我不知道是否是module-info.java或pom.xml引起了错误。在此先感谢您的协助。

module-info.java:

module ui {
    requires javafx.fxml;
    requires transitive javafx.graphics;
    requires javafx.controls;
    requires org.testfx.junit5;
    requires junit;
    requires core;
    exports ui.java;
    exports test.ui to junit;
}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">

    <parent>
        <groupId>it1901.nachwithme</groupId>
        <artifactId>parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>ui</artifactId>

    <dependencies>
        <!-- UI imports core as a dependency -->
        <dependency>
            <groupId>it1901.nachwithme</groupId>
            <artifactId>core</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <!-- Dependencies for javafx -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-core</artifactId>
            <exclusions>
                <exclusion>
                    <!-- https://mvnrepository.com/artifact/org.sonatype.sisu/sisu-inject-bean -->
                    <groupId>org.sonatype.sisu</groupId>
                    <artifactId>sisu-inject-bean</artifactId>
                </exclusion>
                <exclusion>
                    <!-- https://mvnrepository.com/artifact/aopalliance/aopalliance -->
                    <groupId>aopalliance</groupId>
                    <artifactId>aopalliance</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- Dependencies for javafx -->

        <!-- Dependencies for unit-testing -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>16-ea+2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-junit5</artifactId>
            <scope>compile</scope>
        </dependency>
        <!-- Dependencies for unit-testing -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <configuration>
                    <options>
                        <!-- <option>dash dash enable-preview</option> -->
                    </options>
                    <mainClass>ui.java.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <includes>
                    <include>**/*.fxml</include>
                    <include>**/*.png</include>
                </includes>
            </resource>
        </resources>
        <testSourceDirectory>src/test</testSourceDirectory>
        <testResources>
            <testResource>
                <directory>test</directory>
                <includes>
                    <include>**/*.fxml</include>
                    <include>**/*.png</include>
                </includes>
            </testResource>
        </testResources>
    </build>
</project>

错误

Error occurred during initialization of boot layer  
java.lang.module.ResolutionException: Modules sisu.inject.bean and aopalliance export package org.aopalliance.aop to module org.testfx

Process finished with exit code 1

解决方法

TL; DR -这两个模块有一个共同的split package。 JPMS禁止拆分软件包。


冗长的版本

this 2010 blog 第一句话 给出了拆分包是什么的摘要... 1

…“拆分包”是一个非常古老的Java术语,其中您在不同库中的包具有相同的名称,以提供相关(或有时不相关的功能)…

请记住,这是在2010年写的;在JPMS之前。因此,博客在第二句中声称“ 在编译和运行时都没有问题”的观点已经过时;在任何情况下都可以使用modulepath。

有关更详细,最新的解释,请观看JavaOne 2016中的Project Jigsaw: Under the Hood video 2

…为什么错误引用了sisu.inject.beanaopalliance模块……

因为您的项目有一个模块描述符( module-info.java ),所以Maven将那些依赖项-我可以看到您在pom中声明的-放在了模块路径中

...但是我不知道为什么我会收到此错误…

因为JPMS讨厌拆分软件包... 3

...

拆分包存在两个问题

  • 如果包的每个部分都具有相同的类,则您的行为 [程序]取决于类路径中的顺序, 我在两个不同的库中遇到了这种错误,需要 不同版本的ASM,在运行时,较旧版本的类正在调用 较新版本的类:(
  • 安全性,如果允许拆分包,则允许任何人在任何包中插入任何类。

...

解决方案

…
<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.4</version>
    <configuration>
        <options>
            <option>--patch-module</option>
            <option>org.sonatype.sisu=${env.M2_REPO}/aopalliance/aopalliance/1.0/aopalliance-1.0jar</option>
        </options>
        <mainClass>ui.java.App</mainClass>
    </configuration>
</plugin>
…






1 博客谈论OSGi。但是,核心拆分包定义也适用于JPMS。
2 Project Jigsaw: Under The Hood — accompanying slides
3 Rémi Forax —拆分程序包问题-拼图Dev邮件列表-2016年11月。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。