我试图使用java 9和gradle的Spring启动。我无法运行我的简单代码,我得到下面提到的错误:-
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:\project\Java9Gradle\src\main\java\module-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'
}
有人能帮忙吗??
谢谢
阿马尔
这样的问题发生在多个库中,比如Apache Mina(sshd-core),其中sshd-core和sshd-Common之间存在分裂。类似于Springfox Swagger 2,在那里你可以得到类似的拆分包问题:“模块XXX从springfox.core和springfox.spi.读取包springfox.documentation服务”
在分析了如何克服它的多种方法后,我找到了一种适用于所有情况的解决方案。
其想法是将有问题的库重新打包到单个jar中,并将它们安装到您的公司(或本地存储库)中。如果您有公司范围的nexus,您可以安装它,否则在运行整个构建之前,您可以手动将此类库安装到本地maven存储库。
虽然这些看起来像是过度杀伤力和一些不容易做到的事情,但事实上这是相当容易的。
您需要在主项目中创建新的maven模块(或者如果您没有运行多模块项目,则创建单独的maven项目)。然后将引入包拆分的依赖项添加到pom中。xml和配置maven汇编插件来重新打包它们。
对于春狐来说,这将是一个好消息
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-core</artifactId>
<version>${io.springfox.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${io.springfox.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webmvc</artifactId>
<version>${io.springfox.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-schema</artifactId>
<version>${io.springfox.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-web</artifactId>
<version>${io.springfox.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spi</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
请注意两件事。首先
在pom之后。xml已准备好。您可以转到新模块目录,运行
clean install
或clean package
创建一个包,将所有依赖项编译到单个jar中。jar将位于您的目标文件夹下。通过这种方式,您将创建您命名的文件,例如springfox-all-3.0。0.jar
(在单个模块中包含所有springfox代码)。
现在,您可以将该软件包安装到本地repo中,或者更好地将其部署到nexus中,例如使用以下命令
mvn deploy:deploy-file -Dversion=3.0.0-SNAPSHOT -Durl=http://nexus.youc.company.net/nexus/content/repositories/yourRepoId -Dfile=springfox-all-3.0.0.jar -DgroupId=patched.io.springfox -DrepositoryId=yourRepoId -DartifactId=springfox-all
现在,在项目中使用此依赖项,而不是在pom和pom中使用单个依赖项集。xml文件和您的模块信息中。JAVA
module com.acme.your.module {
// requires springfox.spring.web;
// requires springfox.swagger2;
// requires springfox.core;
// requires springfox.spi;
requires springfox.all;
}
根据拼图规格
无干扰-Java编译器、虚拟机和运行时系统必须确保包含同名包的模块不会相互干扰。如果两个不同的模块包含同名的包,那么从每个模块的角度来看,该包中的所有类型和成员都仅由该模块定义。一个模块中该包中的代码不能访问另一个模块中该包中的包私有类型或成员。
在@Andy的回答中,这被称为拆分包。因此,解决方案是取消这些包的拆分,并确保包含在模块jcl中的包。结束slf4j
和公共空间。日志记录
仅通过一个模块访问。
您可以分析这两个依赖项springbootstarter:1.5。3.释放
和Spring启动机web:1.5。3.发布
,以确保项目中包含这两个模块中的任何一个。
排除可传递依赖项使其工作并调整模块信息。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'
}
问题内容: 我正在尝试将Spring Boot与Java 9和Gradle一起使用。我无法运行我的简单代码,出现以下错误: 我的依赖项文件和module-info.java文件非常简单。 有人可以帮忙吗? 问题答案: 排除传递依赖关系使其可以工作,并且也可以调整module-info.java !!!
我得到3个不同的错误。 无法确定模块名称... 未命名模块读取包... 模块org.reactivestreams读取包从两个... 这些错误到底是什么? 建筑格拉德尔 错误消息: 编译Java 错误:无法确定/Users/srihariprasad/的模块名称。gradle/caches/modules-2/files-2.1/io。github。resilience4j/resilience4
我有三个模块模块a、模块b和模块c,当我运行我的应用程序时,我得到如下结果: 引导层初始化过程中出错java.lang.module.Resolution异常:模块模块-a和模块-b导出包some.package模块模块-c 这意味着什么,考虑到模块c不导入以及如何修复它?
食氧;视窗7;JDK 9决赛从9日开始,21日结束;JUnit4.12和现有的应用程序。作为起点,可以编译、执行应用程序,并且所有JUnit测试都显示为绿色。现在我们使用eclipse生成文件模块信息。JAVA结果是: 但有一个错误:junit无法解析为模块。问题是:如何告诉文件junit没有定义任何模块,应该在兼容模式下运行?
问题内容: 我有三个模块,分别是模块a,模块b和模块c。运行应用程序时,我得到以下信息: 引导层java.lang.module.ResolutionException初始化期间发生错误:模块module-a和module- b将包some.package导出到模块module-c 考虑到module-c不会导入以及如何解决它,这是什么意思? 问题答案: 看起来您已经创建了一个拆分包,这意味着两个
这是 module-info.java文件 不幸的是,当我构建这个项目时,弹出了几个错误,您可以在这里看到:errors null