在 eclipse 中,我如何才能在我的类路径中找到一个类型来自哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16235412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:25:16  来源:igfitidea点击:

In eclipse, how can I find where in my classpath a type is coming from?

javaeclipseclasspath

提问by Bruce

Maybe I'm misunderstanding something, but..

也许我误解了一些东西,但是..

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

我希望能够看到 Eclipse在构建项目 B 时Foo.class从 a .jar(在 中的某处classpath)获取。

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

如果我使用“开放类型”( Ctrl + Shift + T),它似乎只是向我显示Foo.class了我的工作区中存在的所有位置?

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?

编辑:我试图找到哪个 jar 正在将一个类引入我的代码。这不是我的罐子。我没有消息来源。因此,我无法打开它并单击它。我想要一个可以输入类型名称的窗口,例如“Foo.class”,它告诉我在我的类路径中引入该类的位置。那一定很简单吧?理想情况下,它还会告诉我类路径中的哪些事件被隐藏了,因为它首先找到了第一个。这是有道理的还是我在胡说八道?

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..

编辑:猜猜我没有说清楚。我没有一段使用 Foo 的代码。它是在某些包含的开源库中的某个地方称为 Foo。所以我不能突出显示或右键单击任何东西。我想我可以写一段包含它的代码吗?好像有点笨重。。

回答by madington

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.

在eclipse Mars中,如果在mac下按shift+control+T / ?+?+T 调出“打开类型”对话框,包以及jar文件的名称和路径显示在底部所选班级的窗口。

回答by Prashanth

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

替代解决方案:特别是如果您想知道需要 class 的 jar 文件,您可以使用 WINRAR 进行搜索。

Use Findin WinRAR

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.

您将在 lib 文件夹中的所有 jar 文件中看到所有名为 ClassWriter.class 的类。

回答by Ray

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 :)

然后我只是删除了课程。一个插件会很好:)

回答by Apurv

  1. Look for .classpathfile in your project. OR
  2. Where ever class Foois used, go to that statement, while Ctrlkey is pressed, left click the class name. Eclipse will take you to the location of Fooclass. This will the Fooclass eclipse is referring while building your code.
  1. .classpath在您的项目中查找文件。 或者
  2. 在任何使用类的地方Foo,转到该语句,同时Ctrl按下 键,左键单击类名。Eclipse 将带您到Foo上课地点。这将是Fooeclipse 在构建代码时所指的类。

回答by maxivis

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

右键单击类名,然后选择“打开声明”(或直接按 F3),如果您没有附加源,则可以在此时进行。在包资源管理器中,您具有“与编辑器链接”功能(一个带有几个前后箭头的按钮),它将您重定向到类的 jar。如果您没有源代码,您仍然可以使用“与编辑器链接”功能来查看专有 jar