英文:
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:
<?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:
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.bean
和aopalliance
模块...“
因为您的项目有一个模块描述符(module-info.java),Maven已经将这些依赖项(我可以看到您在pom中声明了这些依赖项)放在了模块路径上。
> „...然而我不知道我为什么会得到这个错误...“
因为JPMS不允许分割包...<sup>3</sup>
>> …
>>
>> „分割包有两个问题,
>> - 如果您在包的每个部分中有相同的类,则程序的行为取决于类路径中的顺序,
>> 我曾经遇到过这种问题,两个不同的库需要不同版本的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>
…
<br />
<br />
<br />
<br />
<br />
<sup><sup>1</sup></sup> <sup>该博客谈到了OSGi。但是核心的分割包定义也适用于JPMS。</sup><br />
<sup><sup>2</sup></sup> <sup>Project Jigsaw: Under The Hood — 附带幻灯片.</sup><br />
<sup><sup>3</sup></sup> <sup>Rémi Forax — 分割包问题 — Jigsaw Dev 邮件列表 — 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
>> - security, if you allow split packages, you allow anybody to insert any classes in any packages.
>>
>> …
The solution
…
<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>
…
<br />
<br />
<br />
<br />
<br />
<sup><sup>1</sup></sup> <sup>That blog talks about OSGi. But the core split package definition applies to JPMS too.</sup><br />
<sup><sup>2</sup></sup> <sup>Project Jigsaw: Under The Hood — accompanying slides.</sup><br />
<sup><sup>3</sup></sup> <sup>Rémi Forax — The split package problem — Jigsaw Dev Mailing List — November 2016.</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论