How to find out which dependency a class belongs t

2019-05-06 23:37发布

问题:

I'm using m2eclipse. I would like to reuse some of the dependencies from previous projects in a new project. I know which class I want to use, but I can't seem to find out which dependency exactly it belongs to. I would be happy if eclipse just told me the name of the jar it's loading it from.

I suspect that there is a way to do this in eclipse, because when I open the source code, before eclipse manages to load it, it shows the 'source not found' page, where it states which jar it was trying to load it from. Unfortunately, it loads the source too quickly so sometimes I don't manage to read the name.

回答1:

Use Ctrl+Shift+T (Open Type) to open the class you are interested in. Then, using a Package Explorer view, click on the double arrow icon (Link With Editor), the Package Explorer should now be showing you where it thinks that class comes from.

Also, while you're typing the class name in the Ctrl+Shift+T (Open Type) dialog, you should be able to see where Eclipse thinks that class is located.



回答2:

For IntelliJ, first, see which jar file it belongs to, then you can use

mvn dependency:tree

it will show all dependencies of that module so you can find its parent dependency if it is a transitive dependency.