coms
coms

Reputation: 479

Get rid of ClassCastException in different class loaders

I have got my own JAR () running via separated class loaders and one JAR (EhCache) loaded by shared class loader. So I can access to different cache instances via singleton CacheManager.

How can I cast the same classes from my own JAR among separated class loaders?

When I'm trying to invoke my own method I have got ClassCastException like class a.A is not a type of a.A.

PS: Can custom class loader or java reflection helps me?

Upvotes: 0

Views: 501

Answers (2)

jtahlborn
jtahlborn

Reputation: 53694

If you really want to be able to share instances between the 2 classloaders, one option is to implement a shared interface. this shared interface would have to be available from the shared classloader.

Upvotes: 2

NPE
NPE

Reputation: 500683

I don't believe you can. As far as I know, if you load the same class using two different class loaders, the two classes are treated as if they were totally unrelated.

Upvotes: 0

Related Questions