Search code examples
ivyopenjdk-11

dependency not resolved: DocumentBuilderFactory class need dependency of javax.xml.parsers in openJDK 11


Story: I was using JDK8 and IVY as dependency manager with ANT Builder. everything was fine. My DocumentBuilderFactory class able to find javax.xml.parsers dependency.

Issue: Now I am shifted to Open JDK11, Now DocumentBuilderFactory not able to find javax.xml.parsers dependency.

Eclipse gives me suggestions to import, but when i Import nothing happens, and already import says the import javax.xml.parsers.DocumentBuilder cannot be resolved like this: Import says dependency not resolved

What I Need as Solution: I need IVY dependency for Open JDK 11 to support javax.xml.parsers for DocumentBuilderFactory

screenshot my class need dependency :(


Solution

  • I was facing this issue too,

    It was because of DocumentBuilderFactory is available in other packages too.

    Reason Sometimes dependencies take transitive dependencies along with it self

    For example Class XYZ is available in jarA, JarB and JarC too. This issue was not visible untill Java8 but after Java9 release, Java9 release with Java Platform Module System.

    This module system restrict to have multiple classes in different jars with same name, I am not saying that we can not have same name in different classes, for this you have to write module-info.java and have to convert your application into Module System.

    If you are not planning to move your application into Module System then you can do one this, remove the dependencies which are not required for your applications and have same named classes.

    Like for your problem what you can do

    • Open project in eclipse
    • Press ctrl + shit + T >
    • Dialog opens> write your class name which is creating problem, >
    • Dialog will show the packages which contains the same class, Now find out the package which is not required or transitive property because of other dependency >
    • Right click on package name and click show in Package Explorer>
    • Now you will have the jar name, remove or exclude that jar from your dependency manager, Like Gradle or Maven Or Ivy

    I know lengthy process, but its your application your love you have to maintain this.