Search code examples
javawebsphereehcache

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?


Solution

  • 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.