Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out which dependency a class belongs to?

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.

like image 310
Zoltán Avatar asked Sep 19 '11 09:09

Zoltán


People also ask

How do you find transitive dependency?

First go to View → Tool Windows → Maven, to make sure that the Maven window is visible. The top-level elements in the tree are your direct dependencies, and the child elements are the transitive dependencies.

How do you determine dependency hierarchy?

Maven Dependency Tree in Eclipse IDExml “Dependency Hierarchy” tab shows the dependency tree of the project. It has two sides - the left side shows verbose output and the right side shows the resolved dependencies. We can use the “Filter” option to look for a specific dependency.

How do I find the dependencies of a JAR file?

jar file. Use the -verbose:class option to find class-level dependencies or use the -v or -verbose option to include dependencies from the same JAR file. Use the -R or -recursive option to analyze the transitive dependencies of the com.

How do you analyze a dependency tree in Maven?

A project's dependency tree can be filtered to locate specific dependencies. For example, to find out why Velocity is being used by the Maven Dependency Plugin, we can execute the following in the project's directory: mvn dependency:tree -Dincludes=velocity:velocity.


2 Answers

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.

like image 80
Paul Grime Avatar answered Oct 16 '22 00:10

Paul Grime


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.

like image 25
S'chn T'gai Spock Avatar answered Oct 16 '22 00:10

S'chn T'gai Spock