aspose file tools*
The moose likes Java in General and the fly likes same class in two jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "same class in two jar files" Watch "same class in two jar files" New topic
Author

same class in two jar files

Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

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.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Why don't you try?


42
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Thanks Dude.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Prabhu Venkatachalam:
Thanks Dude.


So what did you find out?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

I have not tried yet. If I got something, I'm sure I will share with ranchers.

Thanks.
Ådne Brunborg
Ranch Hand

Joined: Aug 05, 2005
Posts: 208
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.


Entia non sunt multiplicanda praeter necessitatem
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: same class in two jar files