Eclipse 2019-03 regarding Java modules and maven

后端 未结 1 1517
既然无缘
既然无缘 2021-01-23 22:43

I am having a maven (3.6.0) project based on java 11 with the following structure (which works fine on the commandline!):

src/main/java/
  module-info.java
  /de         


        
相关标签:
1条回答
  • 2021-01-23 23:06

    The error says that there is more than one module (probably a JAR) that contains the package org.apache.logging.log4j (or to be more precise, from which the package is accessible). This is not allowed in the Java Platform Module System (JPMS). But in this case, there is only one JAR that contains the package, so this error is shown by mistake in Eclipse 2019-03 (4.11). See:

    Eclipse bug 546315 - "The package […] is accessible from more than one module: , […]" error shown in Java editor by mistake

    As workaround for this bug do one of the following:

    • In module-info.java add the line requires org.apache.logging.log4j.core; which pulls all related JARs on the modulepath
    • Ignore the error (as it does not prevent the code to be compiled)
    • Downgrade to Eclipse 2018-12 (4.10) or wait until Eclipse 2019-06 (4.12)

    By default, all Maven dependencies are on the classpath. In module-info.java the line requires org.apache.logging.log4j; pulls the JAR with the org.apache.logging.log4j module on the modulepath. The error erroneously states that there is another JAR on the classpath (and therefore in the unnamed module) that also contains the package org.apache.logging.log4j. Please note, modules-info.test (with the file extension .test) is neither a Java nor a Maven thing and therefore for Eclipse only a text file.

    Multi-module support: in your case you have only one module-info.java which means you only have one Java module. In Eclipse for each Java module a Java project is required (due each module has its own dependencies).

    0 讨论(0)
提交回复
热议问题