2

Maybe I'm misunderstanding something, but..

I want to be able to see that eclipse is getting Foo.class from a .jar (somewhere in the classpath) when it builds project B.

If I use the 'open type' (Ctrl + Shift + T) it seems that that just shows me all the places that Foo.class exists in my WORKSPACE?

Many thanks..

EDIT: I'm trying to find which jar is introducing a class into my code. It's not my jar. I don't have the source. I can't therefore open it and click it. I want a window that I can type in a type name, like 'Foo.class', and it tells me where that class is being brought in in my classpath. That must be quite simple? Ideally it would also tell me which occurrences later in the classpath were being hidden because it found the first one first. Does that make sense or am I talking nonsense?

EDIT: Guess I'm not making it clear. I don't have a piece of code that uses Foo. It's that somewhere in some included open source library something calls something calls Foo. So I can't highlight or right click anything. I guess I could write a piece of code that has it in? Seems a bit clunky..

Bruce
  • 2,406
  • 5
  • 29
  • 35
  • 1
    In IntelliJ, I just hover over the tab for the class and it tells me in a tool tip. Try a better IDE. – duffymo Apr 26 '13 at 11:33
  • The class you are looking for `Foo` which is present in some `.jar`, are you using this `Foo` class in your code ? – Apurv Apr 26 '13 at 12:02
  • No. But my code calls something that at some point calls it. Also the question is partly hypothetical. Java at some point must be able to resolve any reference to any class that's in the classpath, because that's how it knows which class to use. I just want to know how it resolves a class by asking eclipse. Does it do that? – Bruce Apr 26 '13 at 14:21

5 Answers5

2

Came here looking for the same, so though the question is two years old:

In eclipse Mars, if you press shift+control+T / ⇧+⌘+T on mac to bring up the "Open Type" dialog, the package as well as the name and path of the jar file is shown in the bottom of the window for a selected class.

madington
  • 21
  • 3
1

Alternate Solution : particularly if you want to know the jar files which have needed class , you can search using WINRAR.

Use Find in WinRAR

i)   Open WinRAR
ii)  Open lib folder ( which contains all jar files ) in WinRAR
iii) Click on Find , type any classname (ex : ClassWriter.class )
iv)  Click on OK

you will see all the classes which are named as ClassWriter.class in all jar files in lib folder.

Prashanth
  • 914
  • 10
  • 7
1

Since there seems to be no good solution or plugin for this, I often create a dummy class in the root of my project:

public class Find {
    public static void main(String[] args) {
        System.out.println(
            SomeClass.class.getProtectionDomain().getCodeSource().getLocation());
    }
}

Then I just delete the class. A plugin would be nice :)

Ray
  • 1,324
  • 10
  • 18
0
  1. Look for .classpath file in your project. OR
  2. Where ever class Foo is used, go to that statement, while Ctrl key is pressed, left click the class name. Eclipse will take you to the location of Foo class. This will the Foo class eclipse is referring while building your code.
Apurv
  • 3,723
  • 3
  • 30
  • 51
0

Right click on the class name, then select "Open declaration" (or just press F3), if you don't have a source attached, you can do it at that point. In the package explorer you have the functionality "Link with Editor" (a button with a couple of arrows going back and forward), that redirects you to the jar of the class. If you don't have the source, you still can use the "Link with Editor" functionality to see the propietary jar

maxivis
  • 1,727
  • 3
  • 21
  • 35
  • Thanks for your comment. I don't know where the class is. It's just showing up in a stacktrace. Is there a way to open declaration and type in a type name? – Bruce Apr 26 '13 at 11:48
  • Hi @Bruce, so the only information you have is coming from the stacktrace... I'm trying to reproduce that behavior, but I guess I have the source from most of my libraries, I'll keep trying but I have a question: do you know the propietary jar and you're trying to figure out from where is taking it, or you don't have a clue about the jar? because in the last case you could search it in sites like jarvana.com or findjar.com – maxivis Apr 26 '13 at 12:02