在 Juno Eclipse 中设置一个 Maven 项目

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

setting up a maven project in Juno Eclipse

eclipsemavendependencies

提问by Lolo

I recently upgraded my Eclipse to Juno and am struggling with the way maven dependencies are handled.

我最近将我的 Eclipse 升级到了 Juno,并且正在努力处理 Maven 依赖项的处理方式。

I installed the m2e plugin. Still, many of my projects started complaining about libraries missing as if the dependencies specified in the pom were completely ignored. This happened despite right-clicking on the project, selecting Configure --> Convert to Maven project, which seems to be the replacement for what used to be "Maven --> Enable dependencies" before. When I looked at the Maven dependencies under the project directory, there were many fewer dependencies listed than in my pom.

我安装了 m2e 插件。尽管如此,我的许多项目开始抱怨缺少库,就好像 pom 中指定的依赖项被完全忽略了一样。尽管右键单击项目,选择配置 --> 转换为 Maven 项目,这似乎是之前“Maven --> 启用依赖项”的替代品,但仍然发生了这种情况。当我查看项目目录下的Maven依赖项时,列出的依赖项比我的pom中少很多。

Running a maven compile on the command line outside of Eclipse allowed my project to build and after selecting Maven --> Update project, I was able to see the dependencies added or removed accordingly to what I specified in the pom.xml.

在 Eclipse 之外的命令行上运行 maven 编译允许我的项目构建,在选择 Maven --> 更新项目后,我能够看到根据我在 pom.xml 中指定的内容添加或删除的依赖项。

Bottom line: maven dependencies seem to work now but I had to do some combination of operations I didn't think should have been needed:
- Configure -> Convert to Maven project
- Maven -> Update dependencies
- Run maven outside of Eclipse

底线:maven 依赖项现在似乎可以工作,但我必须执行一些我认为不需要的操作组合:
-配置-> 转换为 Maven 项目
-Maven-> 更新依赖项
-在 Eclipse 之外运行 maven

To get everything to work when with previous versions of Eclipse, all I had to do was Maven -> enable dependencies. What is the equivalent of this in Juno, i.e. what is the correct way of setting up juno Eclipse to handle properly a maven project?

为了在使用以前版本的 Eclipse 时使一切正常工作,我所要做的就是 Maven -> 启用依赖项。什么是 Juno 中的等价物,即设置 juno Eclipse 以正确处理 Maven 项目的正确方法是什么?

采纳答案by Lolo

I have been using Juno for a while now and the reliable way to solve Maven dependencies from within Eclipse after importing a project that is maven based is simply:

我已经使用 Juno 一段时间了,在导入基于 maven 的项目后,从 Eclipse 中解决 Maven 依赖项的可靠方法很简单:

  1. Configure --> Convert to Maven project

  2. Maven --> Update project

  1. 配置 --> 转换为 Maven 项目

  2. Maven --> 更新项目

Running Maven outside of Eclipse doesn't seem to help.

在 Eclipse 之外运行 Maven 似乎没有帮助。

I am not sure why these two steps are now required when they were not before with previous version of Eclipse (at least, two steps were not needed before for sure).

我不确定为什么现在需要这两个步骤,而以前版本的 Eclipse 不需要这两个步骤(至少,之前肯定不需要两个步骤)。

Running

跑步

mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo  

outside of Eclipse has brought me the problems I described in my comment to the other answer.

Eclipse 之外给我带来了我在评论中描述的其他答案的问题。

回答by gbshuler

On a Mac running Windows under Parallels Desktop on OS X? This similar discussion may solve your problem: intellij - java: Cannot find JDK '1.7' for module

在 OS X 上的 Parallels Desktop 下运行 Windows 的 Mac 上?这个类似的讨论可能会解决您的问题:intellij - java: Cannot find JDK '1.7' for module