简体   繁体   English

Eclipse Maven从类中查找依赖关系

[英]Eclipse Maven Find Dependency from Class

I have a maven project in my Eclipse. 我的Eclipse中有一个maven项目。 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? 我可以点击一个类,Eclipse将打开“Type”导航器,它将显示类( .class )文件,也许会显示一些源代码 - 如果有的话 - 但是我如何让Eclipse向我显示maven依赖项或依赖项带来了那堂课?

EDIT: I know how to find the location in my local .m2 repo. 编辑:我知道如何在我当地的.m2回购中找到位置。 What I am looking for is a way to know which maven dependency that class is associated. 我正在寻找的是一种了解该类关联的maven依赖关系的方法。

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 例如,如果我点击HTTPClient,Eclipse会告诉我The Jar file /Users/clangdon/.m2/repository/net/authorize/sdk/1.4.6.jar has no source attachment ,但我怎么知道这个与maven依赖关联

    <dependency>
        <groupId>net.sf.opencsv</groupId>
        <artifactId>opencsv</artifactId>
        <version>2.3</version>
        <scope>compile</scope>
    </dependency>

ctrl + click on that class (somewhere in import) ctrl +点击该类(导入的某个地方)

if it open source and then 如果它是开源然后

right click > show in package-explorer

it will show you jar from which it is coming under classpath 它将向你显示它在类路径下的jar

if it opens class name then on top it will have the jar name along with full file path from your local maven repository 如果它打开类名,那么它将具有jar名称以及来自本地maven存储库的完整文件路径

once you find jar you, to find associated dependency you need to figureout group id and artifact and query maven dependency plugin 一旦找到jar,找到相关的依赖关系,你需要找出组ID和工件以及查询maven依赖插件

For example 例如

for 对于

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

GAV are GAV是

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 或者你可以去这个jar位置并检查它的pom.xml以获得GAV

once you have these parameters you need to do 一旦你有这些参数,你需要做

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

on root pom of your project 在项目的根pom上

Open pom.xml with maven editor: right click on pom -> Open with -> maven pom editor. 使用maven编辑器打开pom.xml :右键单击pom - >打开 - > maven pom editor。

Then open dependency hiearchy tab. 然后打开依赖项hiearchy选项卡。 Here you will find all you needs! 在这里,您将找到所需的一切!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM