我正在尝试将应用程序从Java 8升级到Java 11.0.2。因此,这是我使用Jigsaw模块的第一步!
我的应用程序使用Guice,Assistedinject
和Throwingproviders
扩展名。
这是我当前的module-info.java
:
`
module com.example.mymodule {
requires com.google.guice;
requires com.google.guice.extensions.assistedinject;
requires com.google.guice.extensions.throwingproviders;
//...
}
`
该应用程序基于Maven,当我运行mvn package
时,我没有收到任何错误。但是在Eclipse(2018-12)中,出现以下错误“`可以从多个模块访问com.google.inject包”:
我尝试在module-info.java
中注释每个必需的模块,但是我显然需要其中的三个。
我可以采取一些措施来消除此错误吗?还是这是Eclipse错误?
这是我的pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.7</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.7</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-throwingproviders</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
<version>4.2.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
</plugins>
</build>
</project>
这里是minimal project,用于重现我的错误。
这是a video of the issue(为了清晰起见,请在1080P中观看!)。
答案 0 :(得分:2)
我可以在机器(相同的Eclipse版本,OpenJDK 11)上重现该错误,并且在Apache NetBeans IDE 10.0上可以正常工作。
似乎是Eclipse中的错误,您应该将其归档here。您已经有一个最少的项目,可以重现该错误,对您有很大帮助。
答案 1 :(得分:2)
您的测试项目已经在4.11的RC2中工作(将于2019年3月20日发布)
您可以在https://download.eclipse.org/eclipse/downloads/drops4/S-4.11RC2-201903070500/
下载候选版本。答案 2 :(得分:1)
Eclipse使用自己的编译器,在遵循规格方面,该编译器比javac还要严格。您在模块信息中需要使用模块com.google.inject的不同模块/容器。这是JPMS规范中不允许的某种拆分程序包情况。只有在相同模块的不同模块中存在实际的类时,AFAIK javac才会产生错误,但是eclipse编译器在这里更加挑剔。
有一些解决拆分包装问题的解决方案。如果找不到解决问题的较新版本的libs(不幸的是,对于今天的大多数依赖关系来说,不太可能),则可以将模块合并到一个自定义模块中,但这当然不是一个完美的解决方案。
有关此问题的更多背景信息,另请参见 Eclipse can't find XML related classes after switching build path to JDK 10和https://bugs.openjdk.java.net/browse/JDK-8215739
答案 3 :(得分:0)