开发者

getResource not loading resource in webapp

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 th开发者_运维百科e 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.


Place it in default package it should work

or

Thread.currentThread().getContextClassLoader().getResource("/com/your/package/"+DEFAULT_XSD_NAME)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜