Eclipse 不会相信我有 Maven 2.2.1

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

Eclipse won't believe I have Maven 2.2.1

javaeclipsemaven-2

提问by Andrew Clegg

I have a project (built from an AppFuse template) that requires Maven 2.2.1. So I upgraded to this (from 2.1.0) and set my path and my M2_HOMEand MAVEN_HOMEenv variables.

我有一个需要 Maven 2.2.1 的项目(从 AppFuse 模板构建)。所以我升级到这个(从 2.1.0)并设置我的路径以及我M2_HOME和环境MAVEN_HOME变量。

Then I ran mvn eclipse:eclipseand imported the project into Eclipse (Galileo).

然后我运行mvn eclipse:eclipse并将项目导入 Eclipse (Galileo)。

However, in the problems list for the project (and at the top of the pom.xml GUI editor) it says:

但是,在项目的问题列表中(以及在 pom.xml GUI 编辑器的顶部),它说:

Unable to build project '/export/people/clegg/data/Workspace/funcserve/pom.xml; it requires Maven version 2.2.1

无法构建项目 '/export/people/clegg/data/Workspace/funcserve/pom.xml; 它需要 Maven 版本 2.2.1

This persists whether I set Eclipse to use its Embedded Maven implementation, or the external 2.2.1 installation, in the Preferences -> Maven -> Installations dialog.

无论我是在首选项 -> Maven -> 安装对话框中将 Eclipse 设置为使用其嵌入式 Maven 实现还是外部 2.2.1 安装,这都会持续存在。

I've tried closing and reopening the project, reindexing the repository, cleaning the project, restarting the IDE, logging out and back in again, everything I can think of! But Eclipse still won't believe I have Maven 2.2.1.

我尝试关闭并重新打开项目,重新索引存储库,清理项目,重新启动 IDE,注销并重新登录,我能想到的一切!但是 Eclipse 仍然不会相信我有 Maven 2.2.1。

I just did a plugin update so I have the latest version of Maven Integration for Eclipse -- 0.9.8.200905041414.

我刚刚做了一个插件更新,所以我有最新版本的 Eclipse Maven 集成——0.9.8.200905041414。

Does anyone know how to convince Eclipse I really dohave the right version of Maven? It's like it's recorded the previous version somewhere else and won't pay any attention to my changes :-(

有谁知道如何说服 Eclipse 我确实拥有正确版本的 Maven?就好像它是在别处记录了以前的版本,不会注意我的更改:-(

采纳答案by Richard Gomes

Eclipse allows you to specify an external Maven installation. But there's a catch. :( Have a look at Windows > Preferences > Maven > Installations.

Eclipse 允许您指定外部 Maven 安装。但有一个问题。:( 看看 Windows > Preferences > Maven > Installations。

You will see a message like this:

你会看到这样的消息:

Note: Embedded runtime is always used for dependency resolution, but does
not use global settings when it is used to launch Maven.
To learn more, visit the maven web page.

Translating to English, it means that Eclipse will continue to employ its internal Maven instance in order to perform some tasks. When you "Run As > maven install" it will run your pom.xml script employing the external Maven instance you specified but when Eclipse performs some of its internal stuff, it will continue to use the embedded Maven instance, whatever version it is.

翻译成英文,这意味着 Eclipse 将继续使用其内部 Maven 实例来执行某些任务。当您“运行方式 > maven 安装”时,它将使用您指定的外部 Maven 实例运行您的 pom.xml 脚本,但是当 Eclipse 执行其某些内部内容时,它将继续使用嵌入式 Maven 实例,无论它是什么版本。

(edited) As far as I know, when you install M2Eclipse you are implicitly defining which "internal Maven instance" you will have, which is exactly that one packaged by the plugin. In the plugin configuration, you can add external Maven instances by telling where they are installed.

(已编辑)据我所知,当您安装 M2Eclipse 时,您隐含地定义了您将拥有的“内部 Maven 实例”,这正是插件打包的那个。在插件配置中,您可以通过告诉它们的安装位置来添加外部 Maven 实例。

回答by Richard Gomes

If you are using a recent m2eclipse version, you can try this too:

如果你使用的是最近的 m2eclipse 版本,你也可以试试这个:

<prerequisites>
    <maven>>=2.2.1</maven>
</prerequisites>

Notice the greater thanin >=2.2.1. It works fine for me.

注意大于> = 2.2.1。这对我来说可以。

回答by james2611nov

I got the same issue. Resolved it by restarting the system because every time you change the 'Path' in environment variables you should restart the system or else if would not pick the changes.

我遇到了同样的问题。通过重新启动系统来解决它,因为每次更改环境变量中的“路径”时,您都应该重新启动系统,否则不会选择更改。

回答by Andreas Dolk

A common source of trouble (of this kind) is if you change global preferences and don't remember or know that you have enabled some project specific settings. At least it's a chance that the global setting is now set to use the external maven but the project setting is still set to 'embedded'.

一个常见的麻烦来源(这种)是如果您更改了全局首选项并且不记得或不知道您已启用某些项目特定设置。至少现在有机会将全局设置设置为使用外部 maven,但项目设置仍设置为“嵌入”。

回答by Jherico

M2Eclipse uses an embedded maven instance, not the maven instance you have installed on your system.

M2Eclipse 使用嵌入式 maven 实例,而不是您在系统上安装的 maven 实例。

回答by deterb

Have you tried switching workspaces?

您是否尝试过切换工作区?

You can still reference the same project in the new workspace. This would provide about as much of a reset as you can do in terms of eclipses internal settings.

您仍然可以在新工作区中引用同一个项目。这将提供与 eclipse 内部设置一样多的重置。

回答by Richard Paul

Try creating your eclipse project with mvn project:m2eclipse or use the maven import option under import project.

尝试使用 mvn project:m2eclipse 创建您的 eclipse 项目或使用导入项目下的 maven 导入选项。

回答by Dan Haywood

Using m2eclipse, my fallback in these situations is to do Maven > Update Dependencies and then Maven > Update Project Configuration. The first is just me being supersticious, but the second will rewrite .project and .classpath.

使用 m2eclipse,我在这些情况下的回退是执行 Maven > 更新依赖项,然后执行 Maven > 更新项目配置。第一个只是我迷信,但第二个会重写 .project 和 .classpath。

As Pascal says about, m2eclipse can also be pointed at an external instance. I've done this in the past, though not at 2.2.1.

正如 Pascal 所说,m2eclipse 也可以指向外部实例。我过去做过这个,虽然不是在 2.2.1。

Dan