• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

2 jar files with same package and same class name

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I have two seperate classloaders,each loading classes from 2 seperate jar files.The problem is :
both the jar files say j1 and j2 have a packeages by same name say p with the
same class say c.
ie structure is
j1 > p > c
and j2 > p > c

can we load these jars with 2 seperate classloaders have the same parent class loader.

Because in this case i am getting a class cast exception for class p.c on launching the application with this structure.

Best Regards,
Shobhit
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Because in this case i am getting a class cast exception for class p.c on launching the application with this structure.



I don't think there is any way to avoid a class cast exception if you try to assign to a reference in a class created by the parent class loader. I suspect you will have to use Java's reflection capabilities.

Maybe java.lang.reflect.Proxy will help.
Bill
 
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic