【发布时间】:2020-10-15 08:09:31
【问题描述】:
我尝试将我的 java8 spring 项目迁移到 java11。现在,当我尝试从 Eclipse 运行它时,出现以下异常:
Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules java.activation and jakarta.activation export package javax.activation to module spring.boot.starter.web
在 Referenced Libraries 下我只找到了导出包 javax.activation 的 jakarta.activation-api-1.2.2.jar。另一个模块 java.activation 我不知道它来自哪里。从名称来看,它应该在 JavaSE-11/JDK 内?我检查了条目 JRE 系统库,但在那里我没有看到那个包。
现在,古玩是 Gradle 6.5,我可以使用“gradlew bootRun”运行项目,它执行得很好。但是在 Eclipse 中,它会因错误而失败。
所以在 Eclipse 中,我只是尝试通过右键单击从构建路径中删除来删除 Jakarta.activation。尝试从 javax.activation 导入任何东西然后给我“导入无法解决”,到目前为止还不错。但是运行仍然会出现上述 ResolutionException 的问题。
所以要解决这个问题:
- 导出 javax.activation 包的其他源代码在哪里?我如何找到它?
- 如何防止 Eclipse 在运行时拥有这两个模块?
- 我可以排除 gradle 中的模块,以便项目在运行“gradlew eclipse”后像往常一样工作吗?
感谢您的帮助!我花了几个小时搜索,到目前为止没有找到任何有用的东西。
build.gradle 如下所示:
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'eclipse'
}
group = 'example'
version = '0.3.0'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
configurations.all {
// fix multiple slf4j dependencies are present
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
//TODO: 1st approach to fix ResolutionException
//exclude group: 'jakarta.activation', module: 'jakarta.activation-api'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf:2.3.1.RELEASE'
implementation ('org.springframework.boot:spring-boot-starter-web:2.3.1.RELEASE') {
//TODO: 2nd approach to fix ResolutionException
exclude group: 'jakarta.activation', module: 'jakarta.activation-api'
}
implementation 'org.springframework.boot:spring-boot-starter-security:2.3.1.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.3.1.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.3.1.RELEASE'
implementation 'mysql:mysql-connector-java:5.1.46'
implementation 'com.querydsl:querydsl-jpa:4.1.4'
implementation 'com.querydsl:querydsl-apt:4.1.4:jpa'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.flywaydb:flyway-core:5.2.4'
compileOnly 'org.springframework.boot:spring-boot-devtools:2.3.1.RELEASE'
// https://mvnrepository.com/artifact/org.apache.odftoolkit/simple-odf
implementation 'org.apache.odftoolkit:simple-odf:0.8.2-incubating'
// https://mvnrepository.com/artifact/org.apache.commons/commons-text
implementation 'org.apache.commons:commons-text:1.1'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation 'org.apache.commons:commons-lang3:3.7'
// https://mvnrepository.com/artifact/org.apache.commons/commons-csv
implementation 'org.apache.commons:commons-csv:1.5'
// https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.3
implementation 'org.apache.commons:commons-collections4:4.3'
implementation 'javax.validation:validation-api:2.0.0.Final'
// Dependencies that are no longer in java11
// implementation 'javax.xml.bind:jaxb-api:2.3.0'
// implementation 'com.sun.xml.bind:jaxb-core:2.3.0'
// implementation 'com.sun.xml.bind:jaxb-impl:2.3.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.5.2'
}
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
}
}
我找到但到目前为止对我没有帮助的其他链接:
- https://dba-presents.com/index.php/jvm/java/159-error-java-module-xyz-reads-package-org-apache-commons-logging-from-both-commons-logging-and-jcl-over-slf4j
- Modules A and B export package some.package to module C in Java 9
- Two Modules exports the same package (Spring)
- https://forum.byte-welt.net/t/resolutionexception-module-a-module-b-to-module-c/20843/2
【问题讨论】:
标签: eclipse spring-boot gradle java-9 gradle-eclipse