Java 在 Eclipse* 内执行“mvn dependency:tree”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21952445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Perform "mvn dependency:tree" *within Eclipse*
提问by Sebastien Diot
I have a Maven project which I program within Eclipse. In Eclipse, everything works, but when building it with Maven, I get a NoSuchMethodError on a call to a third-party jar. So I suspect that Eclipse uses a different version of that jar when compiling. I can see which version of what Maven uses, but I'd like to see which version of what Eclipseuses. I don't see how to perform a "mvn dependency:tree" from within Eclipse, such that I would see the result form "Eclipse's point-of-view".
我有一个在 Eclipse 中编程的 Maven 项目。在 Eclipse 中,一切正常,但是当使用 Maven 构建它时,我在调用第三方 jar 时收到 NoSuchMethodError。所以我怀疑 Eclipse 在编译时使用了那个 jar 的不同版本。我可以看到 Maven 使用的是哪个版本,但我想看看Eclipse使用的是哪个版本。我看不到如何从 Eclipse 中执行“mvn dependency:tree”,这样我就会看到“Eclipse 的观点”形式的结果。
The project was created using "File/Import.../Existing Maven Project".
该项目是使用“文件/导入.../现有 Maven 项目”创建的。
I am using "Eclipse IDE for Java Developers", Version: "Kepler Service Release 1"
我正在使用“面向 Java 开发人员的 Eclipse IDE”,版本:“Kepler Service Release 1”
To perform anyMaven command from Eclipse, I just found this SO question
要从Eclipse执行任何Maven 命令,我刚刚发现了这个 SO question
采纳答案by Thorbj?rn Ravn Andersen
Open the pom.xml you want to learn about. This is a multipane editor. One of the panes shows the dependencies and how they are resolved.
打开要了解的 pom.xml。这是一个多窗格编辑器。其中一个窗格显示了依赖关系以及它们是如何解决的。
回答by wonhee
Make sure you installed m2e ( previously called as m2eclipse ) plugin. If Eclipse opens pom.xml as plain text, then click the pom.xml and click mouse-right button for pop-up menu. You'll see "Open With" -> " Maven POM Editor". Within Maven Pom Editor, you can check those dependencies in either "dependencies" or "dependencies hierarchy".
确保您安装了 m2e(以前称为 m2eclipse)插件。如果 Eclipse 以纯文本形式打开 pom.xml,则单击 pom.xml 并单击鼠标右键弹出菜单。您将看到“打开方式”->“Maven POM 编辑器”。在 Maven Pom Editor 中,您可以在“依赖项”或“依赖项层次结构”中检查这些依赖项。
回答by Liang Stanley
Check your .classpath file and modify that add "attributes" under the "classpathentry" to use maven dependency in the build path.
检查您的 .classpath 文件并修改在“classpathentry”下添加“attributes”以在构建路径中使用 maven 依赖项。
Here is the example of .classpath
这是 .classpath 的示例
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>