Java 添加了Maven依赖,Eclipse看不到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24483233/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 12:28:35  来源:igfitidea点击:

Added Maven dependency, Eclipse doesn't see it

javaeclipsemavenm2e

提问by markvgti

I add guava 17.0 to my pom.xml, Eclipse automatically rebuilds project.

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

Ran mvn dependency:resolve, maven shows com.google.guava:guava:jar:17.0:compilein the list of resolved files.

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

However when in Eclipse I try to auto-complete com.google.g, it says "No default proposals". I've added dependencies in my pom.xml before, run mvn dependency:resolveand Eclipse picked them up immediately. What's different this time?

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

I've tried the following so far:

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

I can see target/<projname>-1.0-SNAPSHOT/WEB-INF/lib/guava-17.0.jar.

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

My configuration:

我的配置:

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

采纳答案by markvgti

The suggestion by @khmarbaiseworks best and solves all problems.

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

  1. Just delete the project from Eclipse.

  2. Re-import as "Existing Maven Projects" and point it towards the directory that contains the project's pom.xmlfile.

  3. Let Eclipse's m2eplugin handle the rest

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

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

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

Worked flawlessly for me.

对我来说完美无缺。

The following advice (taken from https://developers.google.com/appengine/docs/java/webtoolsplatform#maven) may only apply to GAE projects, but seems like it should be generally applicable (my project is GAE, so can't be sure):

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

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

1. A subdirectory named target

2. A subdirectory named .settings

3. A file named .classpath

4. A file named .project 

Maven 项目根目录下不得包含以下任何内容:

1. A subdirectory named target

2. A subdirectory named .settings

3. A file named .classpath

4. A file named .project 

回答by Darko Margetic

In file pom.xmlinside < dependency > seleneiummaybe you have defined < scope> teste.g. < scope>test < /scope>.

pom.xml里面的文件中< dependency > seleneium,您可能已经定义了< scope> test例如< scope>test < /scope>.

Removing/deleting this also can solve your problem.

删除/删除它也可以解决您的问题。