Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How Classes Are Loaded

 
greg philpott
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say that you have two jar's in your classpath, say a.jar and b.jar.
Now say there is a class, lets call it common.class in both of these jar files.
If you compile a .java file that calls that common class, the compiler will use the common.class file in the first jar it gets to in the classpath.
example. classpath=c:\jars\a.jar;c:\jars\b.jar Then the common.class in a.jar is used.
Now for my question.
If you have two jars in your installed extensions directory, how is the class found?

(ie. the jars are in c:\(java2 jdk)\jre\lib\ext; )
Thanks for your help.
 
Chris O`Hara
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg,
I don`t know the definitive answer to this, but you could determine which class is used first by a simple experiment.
Create two versions of a class which simply output a message say "using class a(or b)" and run the class which uses the jar and see what message is output first - hence you could deduce what class within the directory is used first.
 
greg philpott
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the suggestion.
The order jar files are looked through by the class loader is alphabetical, so a.jar is looked in before b.jar.
 
Lance Zant
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to resolve this using the -verbose:class option, but found some "Loaded class..." messages omit the "from foo.jar" part. Any idea when this option does & does not report where it found a class?
Originally posted by greg philpott:
thanks for the suggestion.
The order jar files are looked through by the class loader is alphabetical, so a.jar is looked in before b.jar.

 
Marilyn Monickam
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greg,

I guess you are wrong.
I have experimented on something similar to this.
As far as class files are concerned ,they are taken in the order in which they appear in the classpath.
It could possibly be a.jar's class file because you have given it first in your classpath.Try putting b.jar first in the order.It could solve your doubt as well as mine.
Reply after trying,
With regards,
Marilyn
 
greg philpott
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, It has been ages since this post was first made . . . must be book givaway week in this forum!!!
Marilyn,
You do not understand the original post. Please re-read my first post carefully.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic