开发者

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

开发者 https://www.devze.com 2023-03-22 10:47 出处:网络
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 ge

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

精彩评论

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