| 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
Bartender
Joined: Oct 01, 2001
Posts: 2550
|
|
|
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: 32830
|
|
|
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.
|
 |
 |
|
|
subject: if two jars contains same classes (but different class implementation), will they comflict?
|
|
|