问题
Advance thanks to, whom, will going to help me, rather down vote the question :)
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:
What I Need as Solution:
I need IVY dependency for Open JDK 11 to support javax.xml.parsers
for DocumentBuilderFactory
回答1:
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 clickshow in
Package Explorer
>- Now you will have the
jar
name,remove
orexclude
thatjar from your dependency manager, Like
Gradleor
MavenOr
Ivy`
This will help you, because this helped me too.
I know lengthy process, but its your application your love you have to maintain this.
❤ Enjoy 🤞
回答2:
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.
回答3:
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..
来源:https://stackoverflow.com/questions/55905047/dependency-not-resolved-documentbuilderfactory-class-need-dependency-of-javax-x