Eclipse项目中缺少Maven依赖项
我们与maven建立了一个项目,用于解决依赖性问题。它通常工作得很好,但现在我正试图在一台新的PC上编译并运行它,我遇到了Eclipse中缺少依赖项的问题 有趣的是,若我在控制台或eclipse中运行“mvn包”,它运行良好,甚至生成包含所有必要JAR的war。只有Eclipse抱怨“项目未生成,因为其生成路径不完整。找不到org.slf4j.Logger的类文件…”。如果我将该项目与其他一些计算机(项目工作正常)进行比较,我会注意到Eclipse中的“Maven依赖项”列表中缺少很多库。即使它们在打包的war中,也可以在存储库文件夹下找到 因此,jar-s就在那里,Eclipse不会将它们全部列在“Maven依赖项”下。我能做什么 计算机在Windows 7上运行,使用64位java和eclipse。问题已解决 我不知道到底是什么解决了这个问题,但我在Eclipse中做了4件事:Eclipse项目中缺少Maven依赖项,eclipse,maven-2,m2eclipse,Eclipse,Maven 2,M2eclipse,我们与maven建立了一个项目,用于解决依赖性问题。它通常工作得很好,但现在我正试图在一台新的PC上编译并运行它,我遇到了Eclipse中缺少依赖项的问题 有趣的是,若我在控制台或eclipse中运行“mvn包”,它运行良好,甚至生成包含所有必要JAR的war。只有Eclipse抱怨“项目未生成,因为其生成路径不完整。找不到org.slf4j.Logger的类文件…”。如果我将该项目与其他一些计算机(项目工作正常)进行比较,我会注意到Eclipse中的“Maven依赖项”列表中缺少很多库。即使它
- 窗口->首选项:Maven->安装:全局设置->打开文件和硬编码本地存储库
- 项目->清洁
- 右键单击project:Maven->Update dependencies
- 右键单击project:Maven->更新项目配置
我猜是更新依赖项,因为在前两个项目之后没有任何更改。对于在其他项目中创建的依赖项,我遇到了这个问题。下载的第三方依赖项在构建路径中显示良好,但不是我创建的库
解决方案:
在未正确构建的项目中
- 右键单击项目并选择Properties,然后选择Maven
- 取消选中标记为“从工作区解析依赖项”的框 项目”
- 点击Apply,然后点击OK
- 再次右键单击您的项目并执行Maven->更新快照 (或更新依赖项)
当您的项目重新构建时,您的错误应该会消失(如果启用了自动构建,则会自动消失)。我也是Eclipse的新手,我也遇到过类似的问题,Eclipse无法识别导入语句,即使所有迹象都表明依赖项已成功下载 您应该通过转到命令行并键入来检查依赖项文件是否已实际下载
mvn依赖项:树
如果您在那里看到您的包,但是Eclipse没有确认它,那么对我来说(有时)有效的方法是转到终端,将cd放入项目文件夹,然后键入
mvn eclipse:clean
然后
mvn eclipse:eclipse
最后在eclipse中刷新项目
我不知道为什么这样做有效,有时候一次都不行,然后再做一次就行了。。。值得一试 我的项目刚刚搞砸了。下面是我如何为Eclipse Indigo x64(J2EE 3.7.3)修复它的:
希望这能帮助别人。:) 我也有类似的问题。我通过运行Maven->updateprojectconfiguration操作解决了这个问题如果在执行Maven->updateprojectconfiguration之后出现“嵌套路径”错误(或者在Juno中是“updateconfiguration…”),那么您的构建路径配置错误 右键单击项目->生成路径->配置生成路径
确保只包含“/src”和该级别的目录。如果存在例如“/src”和“/src/main/resources”,则这是不正确的。第二个资源('/src/main/resources')嵌套在第一个('/src')下,这会导致您无法导入资源,因为它会阻止eclipse看到maven依赖项。我的问题听起来很类似,因此我将添加到讨论中。我取消了将现有maven项目导入Eclipse的操作,这导致它无法更新,也无法正确完成工作空间的构建 我必须做的是选择
runas…->Maven build…
在目标下,我输入了依赖项:离线运行
然后我右键单击该项目并选择Maven->updateproject…
并更新了该特定项目
这最终允许它创建源文件夹并完成导入。令人惊讶的是,这个问题有这么多不同的原因和可能的解决方案。我找到了另一个对我有效的解决方案 好吧,与其说它是一个解决方案,不如说它是一个发现:我可以在PackageExplorer中看到Maven Dependencies节点,这是Java透视图的默认值,但我在JavaEE透视图中看不到它,它默认使用ProjectExplorer。这两个探索者在快速浏览时看起来非常相似,因此您可能希望看到两者中的Maven依赖关系
当我试图弄明白这一点时,我还没有意识到这一点,所以这毕竟对我来说并不是一个真正的问题。整个项目在eclipse中看起来很奇怪,maven dependencies文件夹丢失,它显示了一些未知的类型,但我能够在maven中成功构建它。解决我的问题的方法是将gen文件夹添加到项目生成路径上的源路径 可能
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</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.nondependency" value=""/>
</attributes>
</classpathentry>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>iText</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>
mvn eclipse:clean
<?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 excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="WEB-INF/" kind="src" path="src/main/webapp"/>
<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>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.9.RELEASE</version>
<scope>runtime</scope>
</dependency>
</dependencies>