java - 添加了 Maven 依赖项,Eclipse 看不到它

标签 java eclipse maven m2e

我将 guava 17.0 添加到我的 pom.xml,Eclipse 会自动重建项目。

mvn dependency:resolve , maven 显示 com.google.guava:guava:jar:17.0:compile在已解析文件列表中。

但是在 Eclipse 中我尝试自动完成 com.google.g ,它说“没有默认建议”。我之前在我的 pom.xml 中添加了依赖项,运行 mvn dependency:resolve Eclipse 立即将它们捡起来。这次有什么不同?

到目前为止,我已经尝试了以下方法:

我可以看到 target/<projname>-1.0-SNAPSHOT/WEB-INF/lib/guava-17.0.jar .

我的配置:

  • 操作系统:OS X 10.9.3
  • 专家:3.1.1
  • Eclipse:开普勒(使用 m2e 1.4)

最佳答案

@khmarbaise的建议效果最好,可以解决所有问题。

  1. 只需从 Eclipse 中删除该项目即可。

  2. 重新导入为“现有 Maven 项目”并将其指向包含项目的 pom.xml 文件的目录。

  3. 让 Eclipse 的 m2e 插件处理剩下的事情

对我来说完美无缺。

以下建议(取自 https://developers.google.com/appengine/docs/java/webtoolsplatform#maven )可能仅适用于 GAE 项目,但似乎应该普遍适用(我的项目是 GAE,所以不能确定):

The directory at the root of the Maven project must not contain any of the following:

1. A subdirectory named target

2. A subdirectory named .settings

3. A file named .classpath

4. A file named .project 

关于java - 添加了 Maven 依赖项,Eclipse 看不到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24483233/

相关文章:

java - Android 在 View Pager 的 Parent Activity fragment 中设置 View

java - 如何测试此对象是否返回正确的字符串?

java - persistence.xml 未添加到耳中

java - JScrollPane 在 JTextArea 中表现得很奇怪

java - 在 Eclipse 中生成一个包含外部库的 Jar

java - IntelliJ Idea无法使用Maven解决Mockito和JUnit依赖关系

java - Spring 5.0.0.M3 调用 ApplicationEventListener 时出错 : No ServletContext set - Exception encountered during context initialization

java - 跟踪字符串对

java - 类型不适用,我找不到错误

java - GWT-Maven-插件 : Link GWT compiled files into a defined directory