Unable to load an XML for jaxb-ing

S

Sipayi

'lo!

Trying to use JAXB for my project. I did the following steps:
a. Created xml/xsd/xjb, placed it under "com.foo.blah"
b. xjc'd the xmls into "com.foo.blah.jaxb"
c. Tried to unmarshal:
--
1. JAXBContext jc = JAXBContext.newInstance("com.foo.blah.jaxb");
2. Unmarshaller um = jc.createUnmarshaller();
3. Object xmlData = unmarshaller.unmarshal(com.foo.blah.SomeClass.class.getResourceAsStream("abc.xml"));
--

Line 3. throws
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:173)
....

I presume this means the classloader of SomeClass is unable to locate
the XML file. I have tried placing the xml file in all directories...
\, com\, com\foo, com\foo\blah, com\foo\blah\jaxb, etc., in vain.

Can anyone tell me where I am going wrong?
Is this a locating/loading issues, or JAXB related? Am I using a wrong
class for loading? Shouldn't using a class at the level "com.foo.blah"
suffice in loading "com\foo\blah\abc.xml"?

Thanks in advance.

-Siplin
 
S

Sipayi

Well, specifying the complete path picks up the classes...
Object xmlData = unmarshaller.unmarshal(com.foo.blah.SomeClass.class.getResourceAsStream("/com/foo/blah/jaxb/abc.xml"));

-Siplin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top