开发者

Simplest way to get Class.getResource()to use current ThreadContext class loader

It would seem that Class.getResource() uses the Class class loader and ignores the Thread context class loader which is not what i wan开发者_运维问答t. Any tipson how toget around this ?


Just go and get the current thread class loader and run the getResource on it:

Thread.currentThread().getContextClassLoader().getResourceAsStream( "path-to-resource.here" );


The question was tehe result of a bad classloader where my class loader did not override getResourceAsStream(). Once that was implemented things just work :)

I ended up overriding ObjectInputStream.readResolve() to use a provider that is passed to the ctor.

thankx all

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜