• Post Reply Bookmark Topic Watch Topic
  • New Topic

same name java classes in different JAR  RSS feed

 
Jean-Claude Serlet
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jean-Claude Serlet
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
I'll try what you explain

Regards
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!