Java Eclipse 项目中缺少 Maven 依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29237490/
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
Maven dependencies missing in Eclipse project
提问by Anatch
I have created a maven project on Eclipse but the maven dependencies library is missing but when I go to project->properties: Java Build Path I can see the maven dependencies library.
我在 Eclipse 上创建了一个 Maven 项目,但是缺少 Maven 依赖库,但是当我转到 project->properties: Java Build Path 时,我可以看到 Maven 依赖库。
So because the maven dependencies is missing when I want to generate to project, I have BUILD SUCCESS but nothing is created.
因此,因为当我想生成项目时缺少 maven 依赖项,所以我已经构建成功,但没有创建任何内容。
回答by SmilinMadHyman
Unfortunately, there is not much information here, I would suggest adding you pom.xml file if it is possible so that we can look at that to diagnose the exact issue.
不幸的是,这里没有太多信息,如果可能的话,我建议您添加 pom.xml 文件,以便我们可以查看它来诊断确切的问题。
As a stab in the dark, if you are not using a jar as your packaging eclipse can move the maven dependencies into a different folder in the interface. and example is 'war' packages have their maven dependencies moved to under "java resources/Libraries"
作为黑暗中的刺,如果您不使用 jar 作为您的包装 eclipse 可以将 Maven 依赖项移动到界面中的不同文件夹中。例如,'war' 包将其 Maven 依赖项移至“java 资源/库”下
Usually the built project is under the 'target' file.
通常构建的项目位于“目标”文件下。
These are just guesses and I cant really tell you anything conclusive without additional information, sorry
这些只是猜测,如果没有其他信息,我无法真正告诉您任何结论性的信息,抱歉
回答by BK Batchelor
When you attempt to convert a Java project into a Maven project,Eclipse sometimes hoses the project and classpath files. Also, double check if Maven plugin (m2e) is installed. The plugin is a default for Eclipse Java, but not Eclipse EE.
当您尝试将 Java 项目转换为 Maven 项目时,Eclipse 有时会处理项目和类路径文件。另外,仔细检查是否安装了 Maven 插件 (m2e)。该插件是 Eclipse Java 的默认设置,但不是 Eclipse EE。
Check you ".project" file if contains the following Maven reference.
如果包含以下 Maven 参考,请检查“.project”文件。
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sample</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
Also, double check your classpath.
另外,请仔细检查您的类路径。
<?xml version="1.0" encoding="UTF-8"?>
<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/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<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"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
回答by Aaron Digulla
Open the context menu for the project -> Maven
-> Update Projects...
and select your project. Maven will then refresh everything.
打开项目的上下文菜单 -> Maven
->Update Projects...
并选择您的项目。Maven 然后将刷新所有内容。
If this item isn't available, The m2e plugin of Eclipse hasn't recognized your project as a Maven project. If so, go to the context menu -> Configure
-> Maven Nature
.
如果此项不可用,则 Eclipse 的 m2e 插件尚未将您的项目识别为 Maven 项目。如果是这样,请转到上下文菜单 -> Configure
-> Maven Nature
。
Also try to build the project from the command line to make sure your POM actually works.
还尝试从命令行构建项目以确保您的 POM 实际工作。
If you're missing dependencies, then check you POM (pom.xml
) and make sure they are in there. To verify your dependencies, open the POM editor and select the "Dependency Hierarchy" tab (at the bottom) to get an overview.
如果您缺少依赖项,请检查您的 POM ( pom.xml
) 并确保它们在那里。要验证您的依赖项,请打开 POM 编辑器并选择“Dependency Hierarchy”选项卡(位于底部)以获取概览。
回答by Jaroslav Záruba
Check out whether your Maven dependencies are listed in Project properties -> Deployment Assembly, it should look something similar to this:
检查您的 Maven 依赖项是否在项目属性 -> 部署程序集中列出,它应该类似于以下内容:
回答by yeaaaahhhh..hamf hamf
Open the .classpath
file inside your eclipse project.
Insert the following lines:
.classpath
在 eclipse 项目中打开该文件。插入以下几行:
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Then, rebuild your project at eclipse.Project->Clean/Build
然后,在 eclipse 中重建您的项目。Project->Clean/Build
回答by WesternGun
Convert the project to Maven project in context menu. That is how I fixed it.
在上下文菜单中将项目转换为 Maven 项目。我就是这样修复的。
回答by bigbadmouse
One extra thing to try:
要尝试的另一件事:
I got this today using eclipse RAD when I didhave a Maven nature and facets, and had followed all remedial steps listed above.
我今天使用 eclipse RAD 得到了这个,当时我确实有一个 Maven 性质和方面,并遵循了上面列出的所有补救步骤。
Eclipse had simply decided that I had no validmaven dependencies, and didn't show the "Maven Dependencies" element in the navigator window, even as an empty node. Rectifying the version on my onePOM dependency to a version that it could find made the "Maven Dependencies" element magically appear with the one expected child.
Eclipse 只是认为我没有有效的maven 依赖项,并且没有在导航器窗口中显示“Maven Dependencies”元素,即使是一个空节点。将我的一个POM 依赖项上的版本修正为它可以找到的版本,这使得“Maven Dependencies”元素神奇地与一个预期的孩子一起出现。
回答by Harika Mudiam
Right Click on the project. Click on "Build Project". It worked for me besides restart, refresh and all. Hope it works for you. Lemme know if it does.
右键单击项目。单击“构建项目”。除了重新启动,刷新等,它对我有用。希望对你有效。让我知道是否可以。