Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing the order of jars in eclipse project

Tags:

java

eclipse

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.

like image 370
CodeMed Avatar asked Oct 23 '14 23:10

CodeMed


People also ask

How to Add JAR files in lib folder?

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.


2 Answers

I had the same problem and was able to solve it by doing the following :

  1. Right click the module which contains the file with error.
  2. Click "Properties"
  3. From left, select "Java Build Path"
  4. Now on right, select the "Order and Export" tab
  5. Click on the "JRE System Library" and click on the "Up" button to move it to the top of "Maven Dependencies"
like image 95
user4572219 Avatar answered Sep 28 '22 07:09

user4572219


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.

like image 30
Ahmed MANSOUR Avatar answered Sep 28 '22 07:09

Ahmed MANSOUR