I recently converted an eclipse Java project into a dynamic web project. The imported jars listed in both the before and after projects are the same, but the change to dynamic web project causes the following compilation error:
W3C_XML_SCHEMA_NS_URI cannot be resolved or is not a field
to be thrown by the following line of code:
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
I have researched this error, and it seems to be thrown by conflicting versions of javax.xml.XMLConstants
in different jars, but I compared the lists of jars in both projects and they are identical, so I think one has to change the order of the jars. How does one do this?
Part of the solution might logically involve figuring out which jars include a package named javax.xml.XMLConstants
. So I followed @DiogoSantana's advice and used the Type wizard to get the results in the following print screen:
I then followed DiogoSantana's advice and ran mvn dependency:tree
and got the following results:
I next made the following change to the pom.xml
:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.7</version>
<exclusions>
<exclusion>
<groupId>jsr173_api</groupId>
</exclusion>
</exclusions>
</dependency>
And then I ran mvn clean install
before refreshing the eclipse project and even doing maven..update project
from within eclipse, but the error remains.
Note: a search for the string infoset
in the pom
did not produce any results, so I tried the next higher level jar
.
After you create a Java project, create a new folder by going to File > New > Folder. Call it “lib”. Then import the JAR file into the lib folder by going to File > Import > General > File. Alternatively, you could just copy the JAR file manually into that folder by navigating to it in your workspace.
I had the same problem and was able to solve it by doing the following :
To fix this, open up the Build-Path menu of your project, switch to "Order and Export" tab, and ensure that the Java System library is in the top of the list than the Maven dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With