aspose file tools*
The moose likes Java in General and the fly likes if two jars contains same classes (but different class implementation), will they comflict? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "if two jars contains same classes (but different class implementation), will they comflict? " Watch "if two jars contains same classes (but different class implementation), will they comflict? " New topic
Author

if two jars contains same classes (but different class implementation), will they comflict?

Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
two jar have same class files, but their classes have different interfaces.

if i add both jar files to my jboss lib directory, the app calls one of the class in one jar,

will the class be located? will compiler confuse?


** SCJP 5.0 84% **
** SCWCD 1.5 76% **
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

The class from whichever jar comes first on the classpath is the one that gets used. The other one might as well not even exist as far as the classloader is concerned. It's a good idea to avoid conflicts like this, but sometimes you can't.
Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
Greg Charles wrote:The class from whichever jar comes first on the classpath is the one that gets used. The other one might as well not even exist as far as the classloader is concerned. It's a good idea to avoid conflicts like this, but sometimes you can't.


Hi, if

class A in jar 1 have method foo()

and

class A in jar 2 have method foo(String param)

when

we call A.foo("haha"), can the second one be called?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40051
    
  28
If the second method isn't found, the class will not compile.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If you are deploying this in something like JBoss you have configurable, hierarchical class loaders at your disposal. If you really need to do this, you might try investigating these.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
Chrix Wu wrote:will the class be located? will compiler confuse?


What happened when you tried?

This isn't just with external JARs. For example, there are two List classes: java.util.List and java.awt.List. If you import both List classes, what happens when you create a variable of type List? Is there a way to have two different variables, one of each type?

You can figure these out by writing an extremely simple program and playing with the import statements.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: if two jars contains same classes (but different class implementation), will they comflict?