Java 为课堂练习设置 Maven 项目的 Eclipse 错误:检查 $M2_HOME 环境变量和 mvn 脚本匹配

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

Eclipse error setting up Maven project for class exercise: Check $M2_HOME environment variable and mvn script match

javaeclipsemaven

提问by greeneggsnoham

I have found a few related questions on this, but they're all related to Intellij or on Mac OS. I'm on Windows 8.1 and using Eclipse:

我发现了一些相关的问题,但它们都与 Intellij 或 Mac OS 相关。我在 Windows 8.1 上使用 Eclipse:

Eclipse Java EE IDE for Web Developers. Version: Luna Service Release 2 (4.4.2) Build id: 20150219-0600

面向 Web 开发人员的 Eclipse Java EE IDE。版本:Luna Service Release 2 (4.4.2) 版本号:20150219-0600

Maven 3.3.1

Maven 3.3.1

I've set up the "Run As" parameters as directed for the coursebut I get the following error message when I try to run:

我已经按照课程的指示设置了“运行方式”参数但是当我尝试运行时收到以下错误消息:

-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.

-Dmaven.multiModuleProjectDirectory 系统属性未设置。检查 $M2_HOME 环境变量和 mvn 脚本匹配。

My output for mvn -version is as follows, and seems to be correct.

我的 mvn -version 输出如下,似乎是正确的。

Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T16:10:27-04:00)

Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.3.1 Java version: 1.7.0_75, vendor: Oracle Corporation

Java home: C:\Program Files\Java\jdk1.7.0_75\jre

Default locale: en_CA, platform encoding: Cp1252

OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"

Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T16:10:27-04:00)

Maven 主目录:C:\Program Files\Apache Software Foundation\apache-maven-3.3.1 Java 版本:1.7.0_75,供应商:Oracle Corporation

Java 主页:C:\Program Files\Java\jdk1.7.0_75\jre

默认语言环境:en_CA,平台编码:Cp1252

操作系统名称:“windows 8.1”,版本:“6.3”,arch:“amd64”,系列:“windows”

I'm a complete newb when it comes to Maven and Eclipse. Any help is appreciated.

当谈到 Maven 和 Eclipse 时,我是一个完全的新手。任何帮助表示赞赏。

回答by GilbertErik

You're not alone in encountering this. I recently moved to 3.3.1 as well and am encountering this same problem.

遇到这种情况的并不只有您一个人。我最近也搬到了 3.3.1 并且遇到了同样的问题。

This isn't the best answer, but this will probably help you today. Try moving back to the latest 3.2.x. (Currently 3.2.5)

这不是最佳答案,但今天可能会对您有所帮助。尝试返回到最新的 3.2.x。(目前为 3.2.5)

I have a feeling it's related to MNG-5767and a change that recently made it in. There may be some functionality in an m2e update or it may have something to do with the structure of your maven project. Without more detail, it's going to be difficult to tell.

我有一种感觉,它与MNG-5767和最近的更改有关。 m2e 更新中可能有一些功能,或者它可能与您的 maven 项目的结构有关。没有更多细节,将很难说清楚。

回答by greeneggsnoham

I managed to work out a solution for this.

我设法为此找到了解决方案。

1) I had to to to run configurations and add an argument to the VM. (Run - Run Configurations - JRE Tab - VM arguments). Enter the following in the text box

1)我必须运行配置并向VM添加参数。(运行 - 运行配置 - JRE 选项卡 - VM 参数)。在文本框中输入以下内容

 -Dmaven.multiModuleProjectDirectory=%M2_HOME%

You need to use %M2_HOME% or something similar to represent the path to Maven, because when I added my path to that argument directly, it was unable to find it. I think it's because there is a length limit on the argument. My path was

您需要使用 %M2_HOME% 或类似的东西来表示 Maven 的路径,因为当我直接将我的路径添加到该参数时,它无法找到它。我认为这是因为论点有长度限制。我的道路是

C:\Program Files\Apache Software Foundation\apache-maven-3.3.1

and I got an error stating that it couldn't find the runtime at Program Files\Apache

我收到一个错误,指出它在 Program Files\Apache 找不到运行时

2) Set up a system environment variable of called M2_HOME with C:\Program Files\Apache Software Foundation\apache-maven-3.3.1

2) 在 C:\Program Files\Apache Software Foundation\apache-maven-3.3.1 设置一个名为 M2_HOME 的系统环境变量

Control Panel - System and Security - System - Advanced System Settings - Environment Variables - System Variables - New

控制面板-系统和安全-系统-高级系统设置-环境变量-系统变量-新增

回答by Abhinav Kumar

Go to: Window--> Preference --> Java --> Installed JREs --> Edit In the edit Default VM arguments you need to put If you already set the maven home, for Windows machine:

转到: Window--> Preference --> Java --> Installed JREs --> Edit 在编辑默认 VM 参数中,您需要放置如果您已经设置了 maven home,对于 Windows 机器:

-Dmaven.multiModuleProjectDirectory=M2_HOME

And for Linux and Mac OS X:

对于 Linux 和 Mac OS X:

-Dmaven.multiModuleProjectDirectory=$M2_HOME

In case you are using Maven 3.x, the variable is named $MAVEN_HOME

如果您使用的是 Maven 3.x,则该变量名为 $MAVEN_HOME

-Dmaven.multiModuleProjectDirectory=$MAVEN_HOME

回答by kirenpillay

Updating your m2eclipse installation from https://www.eclipse.org/m2ewill solve this issue.

https://www.eclipse.org/m2e更新您的 m2eclipse 安装将解决此问题。

回答by Manjeet

adding below to VM argument worked for me -Dmaven.multiModuleProjectDirectory=M2_HOME

添加以下到 VM 参数对我有用 -Dmaven.multiModuleProjectDirectory=M2_HOME

回答by xdhmoore

Newer version of maven will automatically set the multiModuleProjectDirectory property in the bin/mvnscript. This was added here, though I'm not sure how the release number/patching works. You can look for the find_maven_basedirfunction in that file. If it doesn't exist, try upgrading maven.

较新版本的 maven 将自动在bin/mvn脚本中设置 multiModuleProjectDirectory 属性。这是在此处添加的,尽管我不确定版本号/补丁是如何工作的。您可以find_maven_basedir在该文件中查找该函数。如果它不存在,请尝试升级 maven。

回答by Dulith De Costa

Access the following location in eclipse

在eclipse中访问以下位置

Window
  Preference
    Java
      Installed JREs

Now edit Default VM argumentsand place below arguments according to your OS type.

现在Default VM arguments根据您的操作系统类型编辑并放置以下参数。

If Windows,

如果是 Windows,

-Dmaven.multiModuleProjectDirectory=M2_HOME

If Linux,

如果是 Linux,

-Dmaven.multiModuleProjectDirectory=$M2_HOME