Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two different .jar with same Package name and same Class name. How to get the one?

In my project I have standard java system library with rt.jar that have class.

package javax.xml;

public final class XMLConstants {

    private XMLConstants() {
    }

    public static final String NULL_NS_URI = "";
    public static final String DEFAULT_NS_PREFIX = "";
    ...
}

And also included is stax-api-1.0.jar with class

package javax.xml;

public class XMLConstants {
    public static final String DEFAULT_NS_PREFIX = "";
    public static final String XML_NS_PREFIX = "xml";
    public static final String XML_NS_URI = "http://www.w3.org/XML/1998/namespace";
    public static final String XMLNS_ATTRIBUTE = "xmlns";
    public static final String XMLNS_ATTRIBUTE_NS_URI = "http://www.w3.org/2000/xmlns/";
}

And in third class I need to get NULL_NS_URI that looks like this

import javax.xml.XMLConstants;

public myClass(){

    doSomethin() {
        ...
        XMLConstants.NULL_NS_URI
        ...
    }
}

It gives error

NULL_NS_URI cannot be resolved or is not a field

And when I ctrl + click on XMLConstants in myClass eclipse takes me to class stax-api.jar. When I do same thing on colleague machine eclipse take him to rt.jar with no error because NULL_NS_URI is defined in that class.

like image 740
DinoJovic Avatar asked Nov 28 '25 00:11

DinoJovic


1 Answers

Check your build class path order. If the rt.jar resides above the stax-api-1.0.jar, the problem should get resolved. Because, while compilation, the compiler looks up the jars in the build class path order.

like image 96
Arka Ghosh Avatar answered Nov 30 '25 15:11

Arka Ghosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!