This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.
Joined: Nov 10, 2000
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.
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.
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
Joined: Nov 10, 2000
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.