运行JavaFX应用程序 – 初始化引导层时发生错误:java.lang.module.ResolutionException

huangapple go评论96阅读模式
英文:

Running javafx application - Error occurred during initialization of boot layer: java.lang.module.ResolutionException

问题

以下是翻译好的内容:

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>
        <!-- ... (其他依赖) ... -->
    </dependencies>

    <build>
        <!-- 构建插件等配置 -->
    </build>
</project>

错误信息:

错误发生于引导层初始化期间
java.lang.module.ResolutionException: 模块 sisu.inject.bean 和 aopalliance 导出了包 org.aopalliance.aop 到模块 org.testfx

进程以退出代码 1 结束
英文:

As the title says, I'm just trying to run the javafx application. However I have no idea why I'm getting this error, and I don't know why the error is referencing the sisu.inject.bean and aopalliance modules. I don't know wether the module-info.java or the pom.xml is causing the error. Thanks in advance for any anwser.

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:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;parent&gt;
&lt;groupId&gt;it1901.nachwithme&lt;/groupId&gt;
&lt;artifactId&gt;parent&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;/parent&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;artifactId&gt;ui&lt;/artifactId&gt;
&lt;dependencies&gt;
&lt;!-- UI imports core as a dependency --&gt;
&lt;dependency&gt;
&lt;groupId&gt;it1901.nachwithme&lt;/groupId&gt;
&lt;artifactId&gt;core&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- Dependencies for javafx --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
&lt;artifactId&gt;javafx-fxml&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.testfx&lt;/groupId&gt;
&lt;artifactId&gt;testfx-core&lt;/artifactId&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;!-- https://mvnrepository.com/artifact/org.sonatype.sisu/sisu-inject-bean --&gt;
&lt;groupId&gt;org.sonatype.sisu&lt;/groupId&gt;
&lt;artifactId&gt;sisu-inject-bean&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;exclusion&gt;
&lt;!-- https://mvnrepository.com/artifact/aopalliance/aopalliance --&gt;
&lt;groupId&gt;aopalliance&lt;/groupId&gt;
&lt;artifactId&gt;aopalliance&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;!-- Dependencies for javafx --&gt;
&lt;!-- Dependencies for unit-testing --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
&lt;artifactId&gt;junit-jupiter-api&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
&lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
&lt;artifactId&gt;javafx-graphics&lt;/artifactId&gt;
&lt;version&gt;16-ea+2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;junit&lt;/groupId&gt;
&lt;artifactId&gt;junit&lt;/artifactId&gt;
&lt;scope&gt;compile&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.testfx&lt;/groupId&gt;
&lt;artifactId&gt;testfx-junit5&lt;/artifactId&gt;
&lt;scope&gt;compile&lt;/scope&gt;
&lt;/dependency&gt;
&lt;!-- Dependencies for unit-testing --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.testng&lt;/groupId&gt;
&lt;artifactId&gt;testng&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.jacoco&lt;/groupId&gt;
&lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;goals&gt;
&lt;goal&gt;prepare-agent&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;id&gt;report&lt;/id&gt;
&lt;phase&gt;test&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;report&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;com.github.spotbugs&lt;/groupId&gt;
&lt;artifactId&gt;spotbugs-maven-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
&lt;artifactId&gt;javafx-maven-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;options&gt;
&lt;!-- &lt;option&gt;dash dash enable-preview&lt;/option&gt; --&gt;
&lt;/options&gt;
&lt;mainClass&gt;ui.java.App&lt;/mainClass&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
&lt;resources&gt;
&lt;resource&gt;
&lt;directory&gt;src&lt;/directory&gt;
&lt;includes&gt;
&lt;include&gt;**/*.fxml&lt;/include&gt;
&lt;include&gt;**/*.png&lt;/include&gt;
&lt;/includes&gt;
&lt;/resource&gt;
&lt;/resources&gt;
&lt;testSourceDirectory&gt;src/test&lt;/testSourceDirectory&gt;
&lt;testResources&gt;
&lt;testResource&gt;
&lt;directory&gt;test&lt;/directory&gt;
&lt;includes&gt;
&lt;include&gt;**/*.fxml&lt;/include&gt;
&lt;include&gt;**/*.png&lt;/include&gt;
&lt;/includes&gt;
&lt;/testResource&gt;
&lt;/testResources&gt;
&lt;/build&gt;
&lt;/project&gt;

Error:

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

答案1

得分: 1

TL;DR — 这两个模块有一个分割包是共同的。而JPMS禁止分割包。


详细版本

这篇2010年的博客第一句概括了什么是分割包...<sup>1</sup>

>> „...“分割包”是一个相当古老的Java术语,其中您在具有相同名称的不同库中有包提供相关(或有时是无关的)功能...

请记住,这是在2010年编写的,在JPMS之前。因此,博客在第二句中关于„在编译和运行时都没有任何问题“的声明已经过时了;至少在模块路径中是如此。

要获得更详细、更实时的解释,请观看这个来自JavaOne 2016的Project Jigsaw: Under the Hood视频<sup>2</sup>

> „...为什么错误是在引用sisu.inject.beanaopalliance模块...

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

> „...然而我不知道我为什么会得到这个错误...

因为JPMS不允许分割包...<sup>3</sup>

>> …
>>
>> „分割包有两个问题
>> - 如果您在包的每个部分中有相同的类,则程序的行为取决于类路径中的顺序,
>> 我曾经遇到过这种问题,两个不同的库需要不同版本的ASM,在运行时,旧版本的类调用了新版本的类 运行JavaFX应用程序 – 初始化引导层时发生错误:java.lang.module.ResolutionException
>> - 安全性,如果允许分割包,就允许任何人将任何类插入任何包中。
>>
>> …

解决方案

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

<br />
<br />
<br />
<br />
<br />


<sup><sup>1</sup></sup>&nbsp;<sup>该博客谈到了OSGi。但是核心的分割包定义也适用于JPMS。</sup><br />
<sup><sup>2</sup></sup>&nbsp;<sup>Project&nbsp;Jigsaw:&nbsp;Under&nbsp;The&nbsp;Hood&nbsp;—&nbsp;附带幻灯片.</sup><br />
<sup><sup>3</sup></sup>&nbsp;<sup>Rémi&nbsp;Forax&nbsp;—&nbsp;分割包问题&nbsp;—&nbsp;Jigsaw&nbsp;Dev&nbsp;邮件列表&nbsp;—&nbsp;2016年11月。</sup>

英文:

TL;DR — The two modules have a split package in common. And JPMS forbids split packages.


The long-winded version

The first sentence of this 2010 blog gives a summary of what a split package is…<sup>1</sup>

>> „…A “split package” is a pretty old Java term where you have packages in different libraries with the same name providing related (or sometimes unrelated functionality)…

Keep in mind that was written in 2010 though; before JPMS. So the blog's claim of „without any problem at both compile and runtime“ in the second sentence is out-of-date; for the modulepath in any case.

For a way more detailed, more up-to-date explanation, watch this Project Jigsaw: Under the Hood video from JavaOne 2016.<sup>2</sup>

> „…why the error is referencing the sisu.inject.bean and aopalliance modules…

Because your project has a module descriptor (module-info.java) Maven has put those dependencies — which I can see you declared in your pom — on the modulepath.

> „…However I have no idea why I'm getting this error…

Because JPMS abhors split packages…<sup>3</sup>

>> …
>>
>> „There are two issues with split packages,
>> - if you have the same class in each part of the package, the behavior of your
>> [program] depend on the order in the classpath,

>> i've experienced this kind of bugs with two different libraries requiring
>> different version of ASM, at runtime, a class of the older version was calling a
>> class of the newer version 运行JavaFX应用程序 – 初始化引导层时发生错误:java.lang.module.ResolutionException

>> - security, if you allow split packages, you allow anybody to insert any classes in any packages.
>>
>> …

The solution

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

<br />
<br />
<br />
<br />
<br />


<sup><sup>1</sup></sup>&nbsp;<sup>That&nbsp;blog&nbsp;talks&nbsp;about&nbsp;OSGi.&nbsp;But&nbsp;the&nbsp;core&nbsp;split&nbsp;package&nbsp;definition&nbsp;applies&nbsp;to&nbsp;JPMS&nbsp;too.</sup><br />
<sup><sup>2</sup></sup>&nbsp;<sup>Project&nbsp;Jigsaw:&nbsp;Under&nbsp;The&nbsp;Hood&nbsp;—&nbsp;accompanying&nbsp;slides.</sup><br />
<sup><sup>3</sup></sup>&nbsp;<sup>Rémi&nbsp;Forax&nbsp;—&nbsp;The&nbsp;split&nbsp;package&nbsp;problem&nbsp;—&nbsp;Jigsaw&nbsp;Dev&nbsp;Mailing&nbsp;List&nbsp;—&nbsp;November&nbsp;2016.</sup>

huangapple
  • 本文由 发表于 2020年10月4日 05:12:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/64189054.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定