mP.
mP.

Reputation: 18266

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 want. Any tipson how toget around this ?

Upvotes: 1

Views: 1023

Answers (2)

mP.
mP.

Reputation: 18266

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

Upvotes: 1

Maurício Linhares
Maurício Linhares

Reputation: 40333

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

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

Upvotes: 1

Related Questions