简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM