12

When trying to register an MBean in JMX Console I'm getting the following error message:

The package javax.management is accessible from more than one module: <unnamed>, java.management

I'm using Eclipse and I have no module-info.java file in my project structure.

enter image description here

The error disappear when I comment my dependency for Java EE API, but the javax.management package is not part of the JAR.

enter image description here

enter image description here

Evandro Pomatti
  • 10,210
  • 13
  • 76
  • 141

5 Answers5

8

I experienced similar issue when updating from java 8 to java 11. Steps below helped me,

  • Right click Eclipse project > Properties > Java Build Path
  • In Libraries tab, remove all the external jar files under Modulepath and add them under Classpath (you can just select all the jars and drag them under Classpath)
  • Click Apply and Close

Note: JRE System Library will remain under Modulepath.

Eclipse version: 2019-09

Pro
  • 2,427
  • 1
  • 15
  • 25
1

The best workaround with this is to locate the library that causes the duplication issue as it provides the same package than another module in the application. Just browse your project dependencies both JRE System Libraries and Project External Libraries, and examine packages within each library.

When you found that library, just exclude it from the build.

Say it is a library with this dependency signature:

group: 'lib.group', name: 'lib-name', version: notImportant

All you have to do is to exclude it from the build like this:

dependencies {
...
  configurations {
       compile.exclude group: 'lib.group', module: 'lib-name'
  }
...
}

I answered to a similar question here ...

BryZe NtZa
  • 11
  • 1
  • 3
0

If you are facing same problem in Java 11 just simply remove module dependency in JRE 11 (java.xml, java.xml.crypto).

Follow below step right click on project -> build path -> Module dependency -> Just remove two modules from java11 it helps.

-1

Are you using Java-1.8? Because it is default package no need to add dependency for that.

kavan modi
  • 17
  • 3
-3

I was using java11, after switching back to java 8 helped me to resolve these issues in java build path.

  • 1
    that's because Java 8 doesn't have modules, that is from Java 9 forward. You should not use Java 8, try to find a solution for Java 11 or Java 14 as these are the new supported versions. Honestly, I've given up on Eclipse, VS Code is good free alternative if you cannot afford an IDE for Jakarta EE. – Evandro Pomatti Oct 19 '20 at 14:38
  • The author should remove this answer as it is not solving the question at hand - perhaps this can become a comment instead. – wavicle May 06 '22 at 16:29