Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Maven Find Dependency from Class

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>
like image 765
Cindy Langdon Avatar asked Jul 09 '14 17:07

Cindy Langdon


Video Answer


2 Answers

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

like image 153
jmj Avatar answered Sep 21 '22 17:09

jmj


Open pom.xml with maven editor: right click on pom -> Open with -> maven pom editor.

Then open dependency hiearchy tab. Here you will find all you needs!

like image 32
gipinani Avatar answered Sep 21 '22 17:09

gipinani