views:

191

answers:

7

In Eclipse and a class is being loaded that should not be possible. In debug mode, I can pause it and see a call to class a.b.c BUT a.b.c class should exist anywhere since it has been renamed. My assumption is that there is an old jar file being called...but I cannot find it. So how do I find the jar file that class a.b.c is in while in debug mode in eclipse ? Either through an eclipse menu option or via Java and using reflection to get the object to tell me its own jar file.

Thanks.

+2  A: 

If you fire up your JVM using -verbose:class (you can set this as a JVM option in Eclipse) you can see exactly which classes are being loaded when, and I think from where.

Carl Smotricz
Just tried this , and can verify it does work.JVM:java version "1.6.0_17"Java(TM) SE Runtime Environment (build 1.6.0_17-b04)Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode)Example output of 'java -verbose:class MyClass':[Opened C:\Program Files\Java\jre6\lib\rt.jar][Loaded java.lang.Object from C:\Program Files\Java\jre6\lib\rt.jar]...
monojohnny
+1  A: 

Can you "F3" (open the class)? Even if it doesn't decompile it should show you the jar file.

extraneon
+2  A: 

There are a number of circumstances in which a compiled .class file remains available to Eclipse (and its JVM) although you've removed or renamed the source.

To ensure this isn't fooling you, you can either run Project|Clean in Eclipse or simply go into the Navigator view and delete your classes directory (standard is bin), then let Eclipse re-build it.

Carl Smotricz
+5  A: 

You can use the class loader to retrieve the URL of a resource. This works also for classes. To get the location of the java.lang.String class:

X.class.getClassLoader().getResource("java/lang/String.class");

Output:

jar:file:/C:/Program%20Files/Java/jdk1.6.0_17/jre/lib/rt.jar!/java/lang/String.class
Thomas Jung
You can also do something like:X.class.getProtectionDomain().getCodeSource().getLocation()
Andrew Niefer
+1  A: 

If there is an old jar somewhere, you can ask the JAR Class Finder to find it by specifying the class you are looking for.
It is an independent (i.e. not involving some extra code) way to find that jar.

alt text

VonC
This one was indeed very useful, unfortunately it's an oldfashioned WSAD/RAD plugin. Not sure if it works in modern Eclipse environments. I checked the site and last update was from 2007...
BalusC
@BalusC: still work with Eclipse3.5
VonC
+1  A: 

You can also use the "Open Type" dialog (Ctrl+Shift+T). Type the name of the class, and if Eclipse finds it, it'll show the jar(s) it came from.

Note, however, that the classpath that Eclipse sees is not necessarily identical to the runtime classpath.

Eli Acherkan
A: 

Thanks for your help, the solution from Thomas Jung was to:

X.class.getClassLoader().getResource("java/lang/String.class");

Chris