Forums Register Login

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

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
If the second method isn't found, the class will not compile.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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 want my playground back. Here, I'll give you this tiny ad for it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 7467 times.
Similar Threads
adEjbModule error
Can I run 2 classLoader in ONe JVM :confused:
conflict due class is having same name as well as same package structure
Order of jar file in the classpath
Pls. help, i am new to Websphere server 4.0.2. Class Loader Violation Error
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:20:22.