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

4

5

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 :(

Aunt answered 29/4, 2019 at 14:3 Comment(0)
H
5

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.

Holna answered 13/7, 2019 at 6:58 Comment(1)
I like that ctrl + shit ;)Vorfeld
A
4

I am using Eclipse Scout v9.0, and i facing same problem when i migrated from Java 1.8 to 11. I spent hours to solve it and i finally figure it out. Using the information provided by "catalystOne Dupinder", i found out that Java 11 has its own src.jar containing the following class:

  • DocumentBuilder.java
  • DocumentBuilderFactory.java
  • FactoryConfigurrationErro.java
  • etc. same class as "xml-apis" thus. So what i did are the following:
  • exclude the "xml-apis" from maven dependency,
  • configured the build path of the module and under the "Order and Export" tab click "JRE System Library [JavaSE-11]"

What i just did is, i just exported the jar library from Java 11 to maven dependencies.

Hope this will help you guys..

Ambidextrous answered 18/9, 2019 at 8:4 Comment(1)
Examples for the exclusion of xml-apis with maven you can find here #21881683 and here https://mcmap.net/q/93661/-eclipse-is-confused-by-imports-quot-accessible-from-more-than-one-module-quotFuddle
T
3

I have resolved the same issue using the below-mentioned steps :

  1. I have executed the mvn dependency:tree in my terminal

    output:

    [INFO] +- org.seleniumhq.selenium:selenium-server:jar:3.8.1:compile
    [INFO] |  +- com.beust:jcommander:jar:1.48:compile
    [INFO] |  +- org.apache.commons:commons-text:jar:1.1:compile
    [INFO] |  +- commons-io:commons-io:jar:2.6:compile
    [INFO] |  +- commons-net:commons-net:jar:3.6:compile
    [INFO] |  +- org.w3c.css:sac:jar:1.3:compile
    [INFO] |  +- net.sourceforge.cssparser:cssparser:jar:0.9.24:compile
    [INFO] |  +- net.sourceforge.htmlunit:htmlunit:jar:2.28:compile
    [INFO] |  +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.28:compile
    [INFO] |  +- net.sourceforge.htmlunit:neko-htmlunit:jar:2.28:compile
    [INFO] |  +- net.jcip:jcip-annotations:jar:1.0:compile
    [INFO] |  +- org.seleniumhq.selenium:jetty-repacked:jar:9.4.7.v20170914:compile
    [INFO] |  +- org.eclipse.jetty:jetty-client:jar:9.4.7.v20170914:compile
    [INFO] |  +- org.eclipse.jetty:jetty-http:jar:9.4.7.v20170914:compile
    [INFO] |  +- org.eclipse.jetty:jetty-io:jar:9.4.7.v20170914:compile
    [INFO] |  +- org.eclipse.jetty:jetty-util:jar:9.4.7.v20170914:compile
    [INFO] |  +- org.eclipse.jetty:jetty-xml:jar:9.4.7.v20170914:compile
    [INFO] |  +- org.seleniumhq.selenium:htmlunit-driver:jar:2.28:compile
    [INFO] |  +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
    [INFO] |  +- org.eclipse.jetty.websocket:websocket-api:jar:9.4.7.v20170914:compile
    [INFO] |  +- org.eclipse.jetty.websocket:websocket-client:jar:9.4.7.v20170914:compile
    [INFO] |  +- org.eclipse.jetty.websocket:websocket-common:jar:9.4.7.v20170914:compile
    [INFO] |  +- xalan:serializer:jar:2.7.2:compile
    [INFO] |  +- xalan:xalan:jar:2.7.2:compile
    [INFO] |  +- xerces:xercesImpl:jar:2.11.0:compile
    [INFO] |  +- xml-apis:xml-apis:jar:1.4.01:compile
    [INFO] |  \- org.yaml:snakeyaml:jar:1.15:compile
  1. I have exclude the xml-apis dependency from org.seleniumhq.selenium:selenium-server:jar:3.8.1:compile
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-server</artifactId>
          <version>3.8.1</version>
          <exclusions>
              <exclusion>
                  <groupId>xml-apis</groupId>
                  <artifactId>xml-apis</artifactId>
              </exclusion>
          </exclusions>
      </dependency>

3.I update the maven project (Project > maven > update project) After updating the maven project I have solved my issue.

Taker answered 18/3, 2021 at 8:53 Comment(0)
Q
1

javax.xml are extracted as separate module in Java 9.

In your project's Java build path option, go to Libraries tab and change JDK from Classpath to ModulePath and this should fix this problem.

Let me know if it helped.

Quinque answered 2/5, 2019 at 13:56 Comment(1)
Thanks, Issue is resolved, I set modulepath and compile time issues are goneAunt

© 2022 - 2024 — McMap. All rights reserved.