eclipse 项目未导入本地 Maven 存储库中的 jar 包

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

eclipse project not importing the jar packages in local Maven repository

eclipsemavenjar

提问by code4fun

I am facing a problem in setting my eclipse project. The problem is whenever I am creating a new project and import the code.Eclipse is not resolving the packages which are present in the jar files which are present in the C;/..../user/.m2/repository.

我在设置 eclipse 项目时遇到问题。问题是每当我创建一个新项目并导入代码时。Eclipse 没有解析存在于 C;/..../user/.m2/repository 中的 jar 文件中的包。

Hence it's giving a lot of compilation errors until I add all the required jar files manually in the build-path by going to "Add External Jars"

因此,它给出了很多编译错误,直到我通过转到“添加外部罐子”在构建路径中手动添加所有必需的 jar 文件

I saw that M2_REPO is present in my Eclipse classpath.But still it is not resolving the packages. Please suggest how this problem can be resolved.

我看到 M2_REPO 存在于我的 Eclipse 类路径中。但它仍然没有解析包。请建议如何解决此问题。

Gaurav

高拉夫

回答by rogueleaderr

I've been having a similar error in Eclipse on OSX. In Eclipse on the Mac, there is no "Maven" entry when you right-click on a project in the explorer.

我在 OSX 上的 Eclipse 中遇到了类似的错误。在 Mac 上的 Eclipse 中,当您右键单击资源管理器中的项目时,没有“Maven”条目。

However!

然而!

I just discovered that if I right click and then click "Validate", it suddenly magically resolves all the dependencies. No idea why, but maybe this will help.

我刚刚发现,如果我右键单击然后单击“验证”,它会突然神奇地解决所有依赖项。不知道为什么,但也许这会有所帮助。

回答by CheeseFerret

I've had this issue on Eclipse Kepler EE which comes prebuilt with m2e, I finally got it working by doing the following on each project:

我在使用 m2e 预构建的 Eclipse Kepler EE 上遇到了这个问题,我最终通过在每个项目上执行以下操作来使其工作:

  • Right click on the Project
  • Select Properties
  • Select Maven
  • Uncheck the option that says: Resolve Dependencies from Workspace projects
  • 右键单击项目
  • 选择属性
  • 选择 Maven
  • 取消选中以下选项:解决工作区项目中的依赖项

It should pop up with a box that says Maven setting has changed. Do you want to update project configuration. Click Yes to this.

它应该弹出一个框,说 Maven 设置已更改。是否要更新项目配置。单击“是”。

To confirm:

确认:

  • Right click on the project
  • Select Properties
  • Select Java Build Path
  • Check the Libraries tab under Maven dependencies that all the jar you expected are now there.
  • 右键单击项目
  • 选择属性
  • 选择 Java 构建路径
  • 检查 Maven 依赖项下的库选项卡,您期望的所有 jar 现在都在那里。

回答by breeze deus

close your project, and remove your project settings files: .project, .classpath, .settings/. Then re-import this project. It will be ok.

关闭您的项目,并删除您的项目设置文件:.project、.classpath、.settings/。然后重新导入这个项目。一切都会安好的。

回答by dunni

Have you put all needed dependencies in the pom.xml? Even if the Jars are already in your local repository, each project needs its dependencies mentioned in the pom.xml to resolve the dependencies. If you do that, m2eclipse will automatically resolve the build path.

您是否将所有需要的依赖项放在 pom.xml 中?即使 Jars 已经在您的本地存储库中,每个项目也需要 pom.xml 中提到的依赖项来解析依赖项。如果这样做,m2eclipse 将自动解析构建路径。

回答by Raghuram

Another possibility. Are you running Eclipse using JDK or JRE - the default is JRE. You will see a warning in Eclipse console, if so.

另一种可能性。您是使用 JDK 还是 JRE 运行 Eclipse - 默认是 JRE。如果是这样,您将在 Eclipse 控制台中看到警告。

maven eclipse plugin will not work correctly unless run with JDK.

除非与 JDK 一起运行,否则 maven eclipse 插件将无法正常工作。

回答by Ray Toal

I just had a similar problem. The JDK was there, the problems view was set to Show All, and yet there were hundreds of unresolved type errors. Not even Refresh (F5) would work.

我刚刚遇到了类似的问题。JDK 就在那里,问题视图设置为“全部显示”,但仍有数百个未解决的类型错误。甚至刷新(F5)都不起作用。

In the Project|Properties|Java Build Path|Libraries window I was seeing only the JRE System Library, but not the desired "Maven Dependencies" entry. And "Maven Dependencies" was also missing from the Package Explorer view as well.

在 Project|Properties|Java Build Path|Libraries 窗口中,我只看到了 JRE 系统库,但没有看到所需的“Maven 依赖项”条目。并且 Package Explorer 视图中也缺少“Maven Dependencies”。

I finally fixed this by right clicking on the project in the Package Explorer, selecting Maven from the menu, then selecting "Update Project Configuration." This added "Maven Dependencies" and all the errors went away.

我最终通过右键单击包资源管理器中的项目,从菜单中选择 Maven,然后选择“更新项目配置”来解决此问题。这添加了“Maven 依赖项”,所有错误都消失了。

This was nice because prior to this fix I had to treat Eclipse like a dumb editor and run mvn compileon the commandline to find errors.

这很好,因为在此修复之前,我必须将 Eclipse 视为一个愚蠢的编辑器,并mvn compile在命令行上运行以查找错误。