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

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

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

问题

以下是翻译好的内容:

module-info.java:

  1. module ui {
  2. requires javafx.fxml;
  3. requires transitive javafx.graphics;
  4. requires javafx.controls;
  5. requires org.testfx.junit5;
  6. requires junit;
  7. requires core;
  8. exports ui.java;
  9. exports test.ui to junit;
  10. }

pom.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <parent>
  6. <groupId>it1901.nachwithme</groupId>
  7. <artifactId>parent</artifactId>
  8. <version>0.0.1-SNAPSHOT</version>
  9. </parent>
  10. <modelVersion>4.0.0</modelVersion>
  11. <artifactId>ui</artifactId>
  12. <dependencies>
  13. <!-- UI imports core as a dependency -->
  14. <dependency>
  15. <groupId>it1901.nachwithme</groupId>
  16. <artifactId>core</artifactId>
  17. <version>0.0.1-SNAPSHOT</version>
  18. </dependency>
  19. <!-- Dependencies for javafx -->
  20. <dependency>
  21. <groupId>org.openjfx</groupId>
  22. <artifactId>javafx-fxml</artifactId>
  23. </dependency>
  24. <!-- ... (其他依赖) ... -->
  25. </dependencies>
  26. <build>
  27. <!-- 构建插件等配置 -->
  28. </build>
  29. </project>

错误信息:

  1. 错误发生于引导层初始化期间
  2. java.lang.module.ResolutionException: 模块 sisu.inject.bean aopalliance 导出了包 org.aopalliance.aop 到模块 org.testfx
  3. 进程以退出代码 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:

  1. module ui {
  2. requires javafx.fxml;
  3. requires transitive javafx.graphics;
  4. requires javafx.controls;
  5. requires org.testfx.junit5;
  6. requires junit;
  7. requires core;
  8. exports ui.java;
  9. exports test.ui to junit;
  10. }

pom.xml:

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  2. &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
  3. xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  4. xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  5. &lt;parent&gt;
  6. &lt;groupId&gt;it1901.nachwithme&lt;/groupId&gt;
  7. &lt;artifactId&gt;parent&lt;/artifactId&gt;
  8. &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  9. &lt;/parent&gt;
  10. &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  11. &lt;artifactId&gt;ui&lt;/artifactId&gt;
  12. &lt;dependencies&gt;
  13. &lt;!-- UI imports core as a dependency --&gt;
  14. &lt;dependency&gt;
  15. &lt;groupId&gt;it1901.nachwithme&lt;/groupId&gt;
  16. &lt;artifactId&gt;core&lt;/artifactId&gt;
  17. &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  18. &lt;/dependency&gt;
  19. &lt;!-- Dependencies for javafx --&gt;
  20. &lt;dependency&gt;
  21. &lt;groupId&gt;org.openjfx&lt;/groupId&gt;
  22. &lt;artifactId&gt;javafx-fxml&lt;/artifactId&gt;
  23. &lt;/dependency&gt;
  24. &lt;dependency&gt;
  25. &lt;groupId&gt;org.testfx&lt;/groupId&gt;
  26. &lt;artifactId&gt;testfx-core&lt;/artifactId&gt;
  27. &lt;exclusions&gt;
  28. &lt;exclusion&gt;
  29. &lt;!-- https://mvnrepository.com/artifact/org.sonatype.sisu/sisu-inject-bean --&gt;
  30. &lt;groupId&gt;org.sonatype.sisu&lt;/groupId&gt;
  31. &lt;artifactId&gt;sisu-inject-bean&lt;/artifactId&gt;
  32. &lt;/exclusion&gt;
  33. &lt;exclusion&gt;
  34. &lt;!-- https://mvnrepository.com/artifact/aopalliance/aopalliance --&gt;
  35. &lt;groupId&gt;aopalliance&lt;/groupId&gt;
  36. &lt;artifactId&gt;aopalliance&lt;/artifactId&gt;
  37. &lt;/exclusion&gt;
  38. &lt;/exclusions&gt;
  39. &lt;/dependency&gt;
  40. &lt;!-- Dependencies for javafx --&gt;
  41. &lt;!-- Dependencies for unit-testing --&gt;
  42. &lt;dependency&gt;
  43. &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
  44. &lt;artifactId&gt;junit-jupiter-api&lt;/artifactId&gt;
  45. &lt;scope&gt;test&lt;/scope&gt;
  46. &lt;/dependency&gt;
  47. &lt;dependency&gt;
  48. &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
  49. &lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
  50. &lt;scope&gt;test&lt;/scope&gt;
  51. &lt;/dependency&gt;
  52. &lt;dependency&gt;
  53. &lt;groupId&gt;org.openjfx&lt;/groupId&gt;
  54. &lt;artifactId&gt;javafx-graphics&lt;/artifactId&gt;
  55. &lt;version&gt;16-ea+2&lt;/version&gt;
  56. &lt;/dependency&gt;
  57. &lt;dependency&gt;
  58. &lt;groupId&gt;junit&lt;/groupId&gt;
  59. &lt;artifactId&gt;junit&lt;/artifactId&gt;
  60. &lt;scope&gt;compile&lt;/scope&gt;
  61. &lt;/dependency&gt;
  62. &lt;dependency&gt;
  63. &lt;groupId&gt;org.testfx&lt;/groupId&gt;
  64. &lt;artifactId&gt;testfx-junit5&lt;/artifactId&gt;
  65. &lt;scope&gt;compile&lt;/scope&gt;
  66. &lt;/dependency&gt;
  67. &lt;!-- Dependencies for unit-testing --&gt;
  68. &lt;dependency&gt;
  69. &lt;groupId&gt;org.testng&lt;/groupId&gt;
  70. &lt;artifactId&gt;testng&lt;/artifactId&gt;
  71. &lt;/dependency&gt;
  72. &lt;/dependencies&gt;
  73. &lt;build&gt;
  74. &lt;plugins&gt;
  75. &lt;plugin&gt;
  76. &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
  77. &lt;/plugin&gt;
  78. &lt;plugin&gt;
  79. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  80. &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
  81. &lt;/plugin&gt;
  82. &lt;plugin&gt;
  83. &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
  84. &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
  85. &lt;executions&gt;
  86. &lt;execution&gt;
  87. &lt;goals&gt;
  88. &lt;goal&gt;prepare-agent&lt;/goal&gt;
  89. &lt;/goals&gt;
  90. &lt;/execution&gt;
  91. &lt;execution&gt;
  92. &lt;id&gt;report&lt;/id&gt;
  93. &lt;phase&gt;test&lt;/phase&gt;
  94. &lt;goals&gt;
  95. &lt;goal&gt;report&lt;/goal&gt;
  96. &lt;/goals&gt;
  97. &lt;/execution&gt;
  98. &lt;/executions&gt;
  99. &lt;/plugin&gt;
  100. &lt;plugin&gt;
  101. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  102. &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
  103. &lt;/plugin&gt;
  104. &lt;plugin&gt;
  105. &lt;groupId&gt;com.github.spotbugs&lt;/groupId&gt;
  106. &lt;artifactId&gt;spotbugs-maven-plugin&lt;/artifactId&gt;
  107. &lt;/plugin&gt;
  108. &lt;plugin&gt;
  109. &lt;groupId&gt;org.openjfx&lt;/groupId&gt;
  110. &lt;artifactId&gt;javafx-maven-plugin&lt;/artifactId&gt;
  111. &lt;configuration&gt;
  112. &lt;options&gt;
  113. &lt;!-- &lt;option&gt;dash dash enable-preview&lt;/option&gt; --&gt;
  114. &lt;/options&gt;
  115. &lt;mainClass&gt;ui.java.App&lt;/mainClass&gt;
  116. &lt;/configuration&gt;
  117. &lt;/plugin&gt;
  118. &lt;/plugins&gt;
  119. &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
  120. &lt;resources&gt;
  121. &lt;resource&gt;
  122. &lt;directory&gt;src&lt;/directory&gt;
  123. &lt;includes&gt;
  124. &lt;include&gt;**/*.fxml&lt;/include&gt;
  125. &lt;include&gt;**/*.png&lt;/include&gt;
  126. &lt;/includes&gt;
  127. &lt;/resource&gt;
  128. &lt;/resources&gt;
  129. &lt;testSourceDirectory&gt;src/test&lt;/testSourceDirectory&gt;
  130. &lt;testResources&gt;
  131. &lt;testResource&gt;
  132. &lt;directory&gt;test&lt;/directory&gt;
  133. &lt;includes&gt;
  134. &lt;include&gt;**/*.fxml&lt;/include&gt;
  135. &lt;include&gt;**/*.png&lt;/include&gt;
  136. &lt;/includes&gt;
  137. &lt;/testResource&gt;
  138. &lt;/testResources&gt;
  139. &lt;/build&gt;
  140. &lt;/project&gt;

Error:

  1. Error occurred during initialization of boot layer
  2. java.lang.module.ResolutionException: Modules sisu.inject.bean and aopalliance export package org.aopalliance.aop to module org.testfx
  3. 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
>> - 安全性,如果允许分割包,就允许任何人将任何类插入任何包中。
>>
>> …

解决方案

  1. &lt;plugin&gt;
  2. &lt;groupId&gt;org.openjfx&lt;/groupId&gt;
  3. &lt;artifactId&gt;javafx-maven-plugin&lt;/artifactId&gt;
  4. &lt;version&gt;0.0.4&lt;/version&gt;
  5. &lt;configuration&gt;
  6. &lt;options&gt;
  7. &lt;option&gt;--patch-module&lt;/option&gt;
  8. &lt;option&gt;org.sonatype.sisu=${env.M2_REPO}/aopalliance/aopalliance/1.0/aopalliance-1.0jar&lt;/option&gt;
  9. &lt;/options&gt;
  10. &lt;mainClass&gt;ui.java.App&lt;/mainClass&gt;
  11. &lt;/configuration&gt;
  12. &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

  1. &lt;plugin&gt;
  2. &lt;groupId&gt;org.openjfx&lt;/groupId&gt;
  3. &lt;artifactId&gt;javafx-maven-plugin&lt;/artifactId&gt;
  4. &lt;version&gt;0.0.4&lt;/version&gt;
  5. &lt;configuration&gt;
  6. &lt;options&gt;
  7. &lt;option&gt;--patch-module&lt;/option&gt;
  8. &lt;option&gt;org.sonatype.sisu=${env.M2_REPO}/aopalliance/aopalliance/1.0/aopalliance-1.0jar&lt;/option&gt;
  9. &lt;/options&gt;
  10. &lt;mainClass&gt;ui.java.App&lt;/mainClass&gt;
  11. &lt;/configuration&gt;
  12. &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:

确定