如何在java9中解析模块读取包错误 [英] How to resolve module reads package error in java9

查看:136
本文介绍了如何在java9中解析模块读取包错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过spring-boot来理解java 9中的新模块化,所以我想运行一些简单的应用程序,例如: https://github.com/tmatyashovsky/java9-springboot

I am trying to understand new modularity in java 9 with spring-boot so I want to run some simple application for example: https://github.com/tmatyashovsky/java9-springboot

我正在使用maven 3.5.0和java 9:

I am using maven 3.5.0 with java 9:

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T21:39:06+02:00)
Maven home: ~/soft/apache-maven-3.5.0
Java version: 9-ea, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-9-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-79-generic", arch: "amd64", family: "unix"

问题是我还有一些例外。它是什么意思,我应该如何修复它?

Problem is I still got some exception. What does it mean and how should I fix it ?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project api: Compilation failure: Compilation failure: 
[ERROR] module  reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.core reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.jcl reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.aop reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.expression reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.boot.starter.web reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.boot.starter reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.boot reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.boot.autoconfigure reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.boot.starter.logging reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module logback.classic reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module logback.core reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module slf4j.api reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module jul.to.slf4j reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module log4j.over.slf4j reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.boot.starter.json reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module jackson.databind reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module jackson.annotations reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module jackson.core reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module jackson.datatype.jdk8 reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module jackson.datatype.jsr310 reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module jackson.module.parameter.names reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.boot.starter.tomcat reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module tomcat.embed.core reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module tomcat.embed.el reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module tomcat.embed.websocket reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module hibernate.validator reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module validation.api reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module jboss.logging reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module classmate reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.web reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.webmvc reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.context reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module spring.beans reads package javax.annotation from both tomcat.embed.core and java.xml.ws.annotation
[ERROR] module com.lohika.morning.java9modules.service reads package javax.annotation from both java.xml.ws.annotation and tomcat.embed.core


推荐答案

问题是您的模块路径包含相同的包( javax.annotation )在不同的模块中( java.xml.ws.annotation tomcat.embed.core ),其中的模块系统禁止以使配置更可靠。这称为拆分包。当列出所有读取(即看到)该包两次的模块时,模块系统会告诉您。那么现在该怎么做?

The problem is that your module path contains the same package (javax.annotation) in different modules (java.xml.ws.annotation and tomcat.embed.core), which the module system forbids in order to make configurations more reliable. This is called a split package. The module system tells you as much when listing all the modules that read (i.e. "see") that package twice. So what to do now?

首先,业务的顺序是检查两个包是否包含相同的类。如果是的话,你很幸运。现在您需要做的就是确保模块系统只能看到其中一种,有两种可能性:

First order of business would be to check whether both packages contain the same classes. If yes, you're in luck. Now all you need to do is make sure the module system only sees one of those, for which there are two possibilities:


  • 如果来自一个对于模块,您只需要一个包而不需要其他包,将其从配置中取出并使用另一个包。也许你可以停止明确要求​​ java.xml.ws.annotation

  • 如果你把 tomcat.embed.core 放在课堂上path,它的包版本将被完全忽略,整个系统包括类路径上的代码只能看到 java.xml.ws.annotation 中的包。

  • If from one of the modules, you only need the one package and nothing else, take it out of your configuration and use the other one instead. Maybe you can stop explicitly requiring java.xml.ws.annotation?
  • If you put tomcat.embed.core on the class path, its version of the package will be completely ignored and the entire system, including the code on the class path will only see the package in java.xml.ws.annotation.

如果包的两个变体都包含(a)另一个不包含的类型和(b)您的应用程序需求,处于更艰难的境地。首先,这引起了人们的怀疑,即 tomcat.embed.core 做了一些可疑的事情(虽然我不确定)。我知道的唯一可以帮助的可能是非标准 javac 选项 - 补丁模块

If both variants of the package contain types that (a) the other does not contain and (b) your application needs, you're in a tougher situation. First of all, that raises the suspicion that tomcat.embed.core did something fishy (although I'm not sure about that). The only thing I know could help could be the non-standard javac option --patch-module.

这篇关于如何在java9中解析模块读取包错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆