Eclipse Is Confused by Imports ("Accessible from More Than One Module")

Eclipse is confused by imports (accessible from more than one module)

This is caused by

  • a JAR on the Classpath that contains the package java.awt that also exists in the system library but the
  • JRE System Library is on the Modulepath

In the Java Platform Module System (JPMS) it is not allowed to use the same package in more than one module. If the Modulepath and the Classpath is used, everything on the Classpath is handled as the <unnamed> module (in your case the package java.awt exists in the system module java.desktop and also via the JAR on the Classpath in the module <unnamed>).

Since the JRE System Library cannot be moved from the Modulepath to the Classpath (see this answer by Stephan Herrmann for details), you only have the following options:

  • Set the compiler compliance to 1.8 (as you already mentioned)
  • Rebuilt the JAR to avoid Java system library package names inside the JAR (if reflection is used, additional code changes may be necessary):

    • If you have the source code, change the package names (e.g. change the package and subpackae java to java_util and javax to javax_util) and recreate the JAR
    • If you have only the .class files you have to decompile the .class files first

Eclipse RCP , The packagexxx is accessible from more than one module: unnamed

Upgrading to eclipse 2021-12 can solve the problem

Thank you , @howlger

Eclipse - java.lang.ClassNotFoundException

I've come across that situation several times and, after a lot of attempts, I found the solution.

Check your project build-path and enable specific output folders for each folder. Go one by one though each source-folder of your project and set the output folder that maven would use.

For example, your web project's src/main/java should have target/classes under the web project, test classes should have target/test-classes also under the web project and so.

Using this configuration will allow you to execute unit tests in eclipse.

Just one more advice, if your web project's tests require some configuration files that are under the resources, be sure to include that folder as a source folder and to make the proper build-path configuration.

Hope it helps.

Java file outside of source root intelliJ

If you do an 'import from git', IntelliJ doesn't import the project structure from maven (or gradle) automatically.

One way to do this afterwards is to right-click on the pom.xml file in the root directory, and select 'Add as maven project'. Then the folders will be marked correctly, and dependent libraries will be imported. There should be no need to mark individual source folders manually.

I prefer to do a git clone outside of IntelliJ, and afterwards open the project in IntelliJ from the local filesystem, then IntelliJ imports the maven project structure automatically.



Related Topics



Leave a reply



Submit