我尝试将我的 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
在引用的库下,我只找到了导出包 javax.activation 的 jakarta.activation-api-1.2.2.jar。另一个模块 java.activation 我不知道它来自哪里。从名称来看,它应该在 JavaSE-11/JDK 内?我检查了 JRE System Library 条目,但在那里看不到那个包。现在古玩是 Gradle 6.5 我可以使用“gradlew bootRun”运行项目并且它执行得很好。但是在eclipse中它失败并出现错误。
所以在eclipse中我只是试图通过右键单击从构建路径中删除来删除Jakarta.activation。尝试从 javax.activation 导入任何内容然后给我“导入无法解决”,到目前为止还不错。但是运行仍然会提示上述 ResolutionException。
所以要解决这个问题:
谢谢你的帮助!我花了几个小时搜索,到目前为止没有发现任何有用的东西。
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
}
}
我发现但到目前为止没有帮助我的其他链接:最佳答案
好的,我在尝试创建一个示例来重现该问题时找到了部分答案。
首先,我尝试清理项目以确保在 eclipse 中没有缓存任何坏的东西:
gradlew clean eclipse
问题还是出现了。现在我全力以赴并删除了所有构建文件,.project,.classpath 并重新运行 gradlew eclipse,在添加新的运行配置时,项目现在开始正常。
所以可能会归咎于运行配置的缓存。
也许这个或关于同一问题的其他帖子的交叉链接仍然可以帮助某人。
关于 eclipse ResolutionException : Modules A and B export package P to module C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62565679/