0

I have an eclipse (Version: 2021-09 (4.21.0)) project and I am getting "The package org.w3c.dom is accessible from more than one module: unnamed>, java.xml".

The org.w3c.dom is in java.xml which is in the jre system library (openjdk-17) on the build path. The org.w3c.dom is also in the module xercesImpl-2.12.0.SP03.jar which is included in the wildfly 25 runtime library added to my build path.

I need the xerces classes from the jar for my project, but the new jdk enforces the rule that you can't have the same pacakage names in 2 jars.

How can I fix this? Note that I don't use maven so I need a way to exclude the "org.w3c.dom" classes from either the jar or from jdk17.

Thanks in advance.

dkuehner
  • 1
  • 1
  • Open the jar with unzip and delete files/packages, then zip the remaining files and rename to *.jar – Riadh Jan 05 '22 at 14:48
  • @Riadh - This is what I did (actually you can just delete from the jar directly using zip). It removes the conflict, but it seems like a drastic way to handle the issue and I would prefer a better way to handle it. – dkuehner Jan 06 '22 at 15:06

1 Answers1

0

I had the exact same problem, just with different jars. The best solution is that you don't use modular project, so you don't have module-info file, and you can put your xercesImpl-2.12.0.SP03.jar on the classpath.

If you must use modular project, try adding the following into the module-info file: requires xercesImpl-2.12.0.SP03; That way it shouldn't be in an unnamed module anymore. If it still doesn't work, try with Right click on the project->Build Path->Configure Build Path->Order and Export tab and move you jdk System library to the top.

This thread can be useful.

  • Aleksandar Cvisic - unfortunately this didn't solve my issue. I don't have a module-info file in my project and the ordering of the libraries in my build path didn't help. I also checked the thread that you referenced, but without joy. – dkuehner Dec 28 '21 at 17:06
  • @dkuehner When you open "Configure Build Path" of you project, is xercesImpl-2.12.0.SP03 on the modulepath or on the classpath? – Aleksandar Cvisic Dec 29 '21 at 13:48
  • @dkuehner If it is on the modulepath, your project is modular and you shoud have module-info file. I think you can create it, just create new file in the src folder of your project, name it module-info.java and add: module [your project name] { requires xercesImpl-2.12.0.SP03; }. Or you can just remove the jar from module path and add it to the classpath. – Aleksandar Cvisic Dec 29 '21 at 13:55
  • the xerces jar is on the classpath, not modulepath. It is included in the Wildfly Server Runtime library. What I have done to solve the problem (in a way I don't like) is to edit the jar and remove the org.w3c.dom objects from within. This removes the conflict, but it seems like a drastic way to handle the issue. – dkuehner Dec 29 '21 at 16:09