2

i have created a jar for unmarshalling the XML and i was using the following code to search an xsd

Thread.currentThread().getContextClassLoader().getResource(DEFAULT_XSD_NAME) 

where DEFAULT_XSD_NAME="destination.xsd"

my xsd file is in the same package structure and at the same level where my class having the above code is. This was working fine in my stand alone application but when i placed the jar in my web-application under the lib directory the following code

Thread.currentThread().getContextClassLoader().getResource(DEFAULT_XSD_NAME).getFile() 

giving me null pointer exception below is the stack trace

java.lang.NullPointerException com.raisonne.tr.impex.xmlprocessor.impl.XMLUnmarshallerImpl.validateXML(XMLUnmarshallerImpl.java:194) com.raisonne.tr.impex.xmlprocessor.impl.XMLUnmarshallerImpl.unmarshal(XMLUnmarshallerImpl.java:85) com.raisonne.tr.service.impex.impl.DestinationImportServiceImpl.parseXMLToObject(DestinationImportServiceImpl.java:95) com.raisonne.tr.service.impex.impl.DestinationImportServiceImpl.startDestinationImport(DestinationImportServiceImpl.java:82) com.raisonne.tr.backoffice.actions.impex.DestinationImportAction.destinationImport(DestinationImportAction.java:118) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) 

i am running the application on tomcat 6.0.29.

any help/pointer is this regard is much appriciated.Additonaly it will be good if i have some solution that is container independent.

2 Answers 2

4

Place it in default package it should work

or

Thread.currentThread().getContextClassLoader().getResource("/com/your/package/"+DEFAULT_XSD_NAME) 
Sign up to request clarification or add additional context in comments.

8 Comments

You mean i should move out the XSD from the jar and place it some where in the package where i am using the functionality of jar??
I hope your above code and xsd both are in the same jar then follow the answer
Yes Code as well the XSD are at same jar at same directory structure.and placing the package name as mentioned by you is still not clear to me..is it something related to web-application container behaviour since standalone version of the application(converted to jar) was working perfectly fine
Thread.currentThread().getContextClassLoader().getResource("/com/your/package/"+DEFAULT_XSD_NAME) will work for you. and yes when bundle gets extracted it will follow this way
@org.life.java:It worked but its better to ask what exactly this mean rather than following it.so can you throw some light what exactly was i doing wrong it will help me to avoid future mistakes :)
|
2

Because, in the container if you just name it like destination.xsd, it would try to look from the URI path onwards. Placing a / in front like, /destination.xsd, will make it look in servlet container root directory.

1 Comment

Thanks Adeel :) I hope my comments answers the explanation well , let me know if there is anything missing thanks btw +1 :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.