3

I'm migrating a Java 8 project to Java 11. IDE used is Eclipse 2020-09. I have NOT modularized the project.

For the below imports:

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

I'm getting compile time error message:

The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml

I have checked my project and org.w3c.dom package is not present in 3rd party libs or added by any transitive dependencies in the project jars.

However note that org.w3c.dom.Document is an interface and I found few libraries that implement this interface. Is this the root cause of

package is accessible from more than one module

message ?

Below are the implementors of org.w3c.dom.Document in Eclipse project

As you can see in above screenshot the JBoss EAP 7.3 runtime libraries contain implementation of org.w3c.dom.Document. Is it correct to say JBoss runtime libraries are contributing to this Java 11 migration problem I'm having ?

Nirmal581
  • 43
  • 1
  • 5

1 Answers1

3

Java 9 introduced a new requirement as defined in JLS §7.4.3. Every qualified type name requires that its prefix is a uniquely visible package. The incompatibility is due to transitive dependencies allowed in prior Java versions.

When the project Properties, Java Compiler, "Compiler compliance level" is set to higher than "1.8", Eclipse will report violations of this requirement. Since the custom Java implementation when using Streaming 10.6 or higher will be running in a Java 11 JVM, these must be resolved.

The resolution choices are to:

  1. upgrade the libraries to a Java 11 compatible version without transitive dependencies,
  2. exclude the conflict explicitly in POM dependencyManagement, or
  3. avoid the conflict by only importing the classes needed and do not use wildcards (*) in import statements.

In all cases, some investigation will need to be done to find the source of the conflict by knowing what packages each library brings into the project and the specific uses of the classes from those libraries. To see what dependencies each library exposes to the project, use:

mvn dependency:tree

This will provide the information to find what needs to be imported explicitly or excluded.

Referenced from: https://support.tibco.com/s/article/Upgrading-Streaming-projects-to-use-Java-11-package-is-accessible-from-more-than-one-module

Saravanakrishnan Pk
  • 451
  • 1
  • 5
  • 15
  • Out of the resolution choices mentioned above, in my case the unique package constraint violation is caused by a library of the JBoss server on which I'm deploying my application. In this case what choice do I have ? For example jboss-saaj-api_1.3_spec-1.0.6.Final-redhat-1.jar - containing the class public abstract class javax.xml.soap.SOAPPart implements org.w3c.dom.Document, javax.xml.soap.Node { ... } most probably causing JLS §7.4.3 violation. – Nirmal581 Aug 20 '21 at 01:28