Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

same class in two jar files  RSS feed

 
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say, you have a class like below,


jarfile1.jar and jarfile2.jar has above class.

Now you set a class path which has these JAR files. If you try to use class a in your code what will happen?

Thanks in advance.
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try?
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dude.
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Prabhu Venkatachalam:
Thanks Dude.



So what did you find out?
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not tried yet. If I got something, I'm sure I will share with ranchers.

Thanks.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to recall having this problem as the cause for an "unexplainable bug" a couple of years back. Different version of class a was included in two different jar-files, and I kept getting the same old bug even though I knew I had included the new version.

The explanation was that the order in which the jar-files was included in the project determined which version of the class was used. This was using WebSphere Application Developer, and it preferred using the jar-file listed first of the two in the project library setup. Or possibly the last one.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This happens all the time, more often than you think. Just pick two jar files from your server class path and see how many classes they have in common.

A class loader will only load the class once, from the first "resource" it can find that has the class. So it is never a problem until as Ande points out, two different class loaders load potentially different versions of the class. When versions conflict, usually you get an error that hints that serialization identifier of the classfile is different than the one expected.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!