Eclipse Maven Find Dependency from Class

eclipse, java, maven

Solution

ctrl + click on that class (somewhere in import)

if it open source and then

right click > show in package-explorer

it will show you jar from which it is coming under classpath

if it opens class name then on top it will have the jar name along with full file path from your local maven repository

once you find jar you, to find associated dependency you need to figureout group id and artifact and query maven dependency plugin

For example

for

/Users/clangdon/.m2/repository/net/authorize/sdk/1.4.6.jar

GAV are

groupId= net.authorize
artifactId=sdk
version=1.4.6

or you can go at this jar location and check its `pom.xml` to get GAV

once you have these parameters you need to do

mvn dependency:tree -Dincludes="net.authorize:sdk"

on root pom of your project

Problem

I have a maven project in my Eclipse. I can click on a class and Eclipse will open the "Type" navigator and it will display the class (`.class`) file, and maybe some source - if one is available - but how can I make Eclipse show me the maven dependency or dependencies that brought in that class? EDIT: I know how to find the location in my local .m2 repo. What I am looking for is a way to know which maven dependency that class is associated. For example, if I click on HTTPClient, Eclipse will tell me `The Jar file /Users/clangdon/.m2/repository/net/authorize/sdk/1.4.6.jar has no source attachment`, but how do I find out that this is associated to the maven dependency ``` <dependency> <groupId>net.sf.opencsv</groupId> <artifactId>opencsv</artifactId> <version>2.3</version> <scope>compile</scope> </dependency> ```

Original source