java 9模块从A和B读取包X.

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 9模块从A和B读取包X.相关的知识,希望对你有一定的参考价值。

我正在尝试使用java 9和gradle的spring boot。我无法运行我的简单代码,我得到以下提到的错误: -

Information:java: Errors occurred while compiling module 'Java9Gradle_main'
Information:javac 9-ea was used to compile java sources
Information:6/9/2017 10:40 PM - Compilation completed with 65 errors and 0 warnings in 15s 200ms
Error:java: module  reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module  reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.web reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.web reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.autoconfigure reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.autoconfigure reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.logging reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.logging reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.core reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.core reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module snakeyaml reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module snakeyaml reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.tomcat reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.tomcat reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module hibernate.validator reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module hibernate.validator reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jackson.databind reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jackson.databind reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.web reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.web reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.webmvc reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.webmvc reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.context reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.context reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module logback.classic reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module logback.classic reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jcl.over.slf4j reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jcl.over.slf4j reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jul.to.slf4j reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jul.to.slf4j reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module log4j.over.slf4j reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module log4j.over.slf4j reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module commons.logging reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module commons.logging reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.core reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.core reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.el reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.el reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.websocket reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.websocket reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module validation.api reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module validation.api reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jboss.logging reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jboss.logging reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module classmate reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module classmate reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jackson.annotations reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jackson.annotations reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jackson.core reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jackson.core reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.aop reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.aop reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.beans reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.beans reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.expression reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.expression reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module logback.core reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module logback.core reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module slf4j.api reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module slf4j.api reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
D:projectJava9Gradlesrcmainjavamodule-info.java
Error:(1, 1) java: module Java9Gradle.main reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging

我的依赖项文件和module-info.java文件非常简单。

module Java9Gradle.main {
    requires spring.boot;
}


group 'Java9Gradle'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.9

repositories {
    mavenCentral()
}

dependencies {
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter
    compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '1.5.3.RELEASE'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.3.RELEASE'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

有人可以帮忙吗?

谢谢,

我的

答案

排除传递依赖使其工作并调整module-info.java !!!

compile("org.springframework.boot:spring-boot-starter:1.5.3.RELEASE") {
        exclude group: 'commons-logging', module: 'commons-logging'
    }
    compile("org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE"){
        exclude group: 'commons-logging', module: 'commons-logging'
    }
另一答案

根据Jigsaw specs

无干扰 - Java编译器,虚拟机和运行时系统必须确保包含相同名称的包的模块不会相互干扰。如果两个不同的模块包含同名的包,那么从每个模块的角度来看,该包中的所有类型和成员仅由该模块定义。一个模块中该包中的代码必须不能访问另一个模块中该包中的包私有类型或成员。

这在@Andy here的回答中被称为拆分包。解决方案是解开这些包,并确保模块jcl.over.slf4jcommons.logging中包含的包只能通过一个模块访问。


您可以分析依赖关系spring-boot-starter:1.5.3.RELEASEspring-boot-starter-web:1.5.3.RELEASE,以确保项目中包含两个模块中的任何一个。

以上是关于java 9模块从A和B读取包X.的主要内容,如果未能解决你的问题,请参考以下文章

如何解决java9中的模块读取包错误

9_模块_包导入

matlab中输入x. 与x的区别

Python_9 py文件导入和路径处理

从JVM的角度看JAVA代码--代码优化

电子学会青少年软件编程 Python编程等级考试三级真题解析(选择题)2020年9月B卷