File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes same name java classes in different JAR Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "same name java classes in different JAR" Watch "same name java classes in different JAR" New topic
Author

same name java classes in different JAR

Jean-Claude Serlet
Greenhorn

Joined: Aug 19, 2005
Posts: 2
Hello

What i don't find is the method used by the JVM when a class is requested and this class may be found in two different jar files under the classpath
I know that it's a vary bad organisation (
A sample : in class A there is an instanciation of class B
B machin = new B();
In the classpath there are two jar files (file1.jar and file2.jar) each containing a class B
Which class B will be used : B of file1.jar or B of file2.jar ? Why ?
Regards

Jean-Claude
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Assuming the fully qualified class names are the same, I'd guess the class loaded would be the first class the classloader finds. You could find out by jaring up two identically named class files in different jars, putting them both in the classpath and using this class from an application. Chuck a bit of logging in each class to say which one it is.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jean-Claude Serlet
Greenhorn

Joined: Aug 19, 2005
Posts: 2
Thanks
I'll try what you explain

Regards
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: same name java classes in different JAR
 
Similar Threads
Package question
Using Jar Files
What is the concept of endorsed directory??
Trying to execute java program which is in jar file
basic instantiation question