aspose file tools*
The moose likes Java in General and the fly likes Stax API conflicts with J2SE lib Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Stax API conflicts with J2SE lib" Watch "Stax API conflicts with J2SE lib" New topic
Author

Stax API conflicts with J2SE lib

Vu Pham
Ranch Hand

Joined: May 28, 2005
Posts: 100
Hi all,

I'm using Stax API (http://stax.codehaus.org/) in my project. I'm using Eclipse IDE also. But I'm having a small issue. I have a java file like below:


import javax.xml.XMLConstants;

...
final private static SchemaFactory SCHEMA_FACTORY =
SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
...


I want to use XMLConstants of J2SE lib. The problem is IDE just understands XMLConstants class here is of Stax API. XMLConstants class of Stax API doesn't have W3C_XML_SCHEMA_NS_URI property. That's why Eclipse can't compile my java file. I can't remove Stax API from my program because there are some others places I used it. Do you know how to solve this one? Thanks very much.

Kind regards,
Vu Pham
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

The import should make sure you're using the JSE class and not the Stax class. It's only available since Java 5.0 though. Are you perhaps still using Java 1.4?
Single import statements always take precedence over wildcard import statements (e.g. import java.util.*) so with that line either you are using the right class or the entire import will cause a compiler error.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

That's what I thought at first too, Rob, but acting on a hunch, I downloaded the jar (thanks for the link!) The API jar file actually includes its own copy of javax/xml/XMLConstants.class , as vile as that may seem to us.

My recommendation to you, Vu Pham, would be to build your own stax.jar which didn't include this class; just removing the file from the jar. You could just un-jar it, delete that one class, and re-jar it.


[Jess in Action][AskingGoodQuestions]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

But shouldn't classes in rt.jar take precedence over any other classes because they are loaded by the bootstrap class loader?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

You'd think. Maybe he's got stax installed as a standard extension (in /ext?)
Vu Pham
Ranch Hand

Joined: May 28, 2005
Posts: 100
I have changed the order of JAR file in "Configure Build Path". It's ok now :-)

Thanks all for your help :-)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Figures. I think Eclipse uses its own bootstrap class loader and ignores the JVM that has loaded it. Instead it only looks at the project properties.
 
jQuery in Action, 2nd edition
 
subject: Stax API conflicts with J2SE lib