简体   繁体   English

Eclipse错误设置Maven项目进行类练习:检查$ M2_HOME环境变量和mvn脚本匹配

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

I have found a few related questions on this, but they're all related to Intellij or on Mac OS. 我在这方面找到了一些相关问题,但它们都与Intellij或Mac OS有关。 I'm on Windows 8.1 and using Eclipse: 我在Windows 8.1上使用Eclipse:

Eclipse Java EE IDE for Web Developers. 面向Web开发人员的Eclipse Java EE IDE。 Version: Luna Service Release 2 (4.4.2) Build id: 20150219-0600 版本:Luna Service Release 2(4.4.2)Build id:20150219-0600

Maven 3.3.1 Maven 3.3.1

I've set up the "Run As" parameters as directed for the course but I get the following error message when I try to run: 按照课程的指示设置了“运行方式”参数但是当我尝试运行时收到以下错误消息:

-Dmaven.multiModuleProjectDirectory system propery is not set. -Dmaven.multiModuleProjectDirectory系统propery未设置。 Check $M2_HOME environment variable and mvn script match. 检查$ 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) 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 Maven主页:C:\\ Program Files \\ Apache Software Foundation \\ apache-maven-3.3.1 Java版本:1.7.0_75,供应商:Oracle Corporation

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

Default locale: en_CA, platform encoding: Cp1252 默认语言环境:en_CA,平台编码:Cp1252

OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows" 操作系统名称:“windows 8.1”,版本:“6.3”,arch:“amd64”,系列:“windows”

I'm a complete newb when it comes to Maven and Eclipse. 对于Maven和Eclipse,我是一个完整的新手。 Any help is appreciated. 任何帮助表示赞赏。

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: 转到:窗口 - >首选项 - > Java - >已安装的JRE - >编辑在编辑中需要放置的默认VM参数如果已经为Windows机器设置了maven home:

-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

I managed to work out a solution for this. 我设法为此制定了解决方案。

1) I had to to to run configurations and add an argument to the VM. 1)我不得不运行配置并向VM添加参数。 (Run - Run Configurations - JRE Tab - VM arguments). (运行 - 运行配置 - JRE选项卡 - VM参数)。 Enter the following in the text box 在文本框中输入以下内容

 -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. 您需要使用%M2_HOME%或类似的东西来表示Maven的路径,因为当我直接添加我的路径到该参数时,它无法找到它。 I think it's because there is a length limit on the argument. 我认为这是因为论证有一个长度限制。 My path was 我的道路是

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 控制面板 - 系统和安全 - 系统 - 高级系统设置 - 环境变量 - 系统变量 - 新增功能

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. 尝试回到最新的3.2.x. (Currently 3.2.5) (目前3.2.5)

I have a feeling it's related to MNG-5767 and 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. 我有一种感觉它与MNG-5767有关,并且最近也发生了变化。在m2e更新中可能有一些功能,或者它可能与你的maven项目的结构有关。 Without more detail, it's going to be difficult to tell. 如果没有更多细节,那将很难说清楚。

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

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

Newer version of maven will automatically set the multiModuleProjectDirectory property in the bin/mvn script. 较新版本的maven将自动在bin/mvn脚本中设置multiModuleProjectDirectory属性。 This was added here , though I'm not sure how the release number/patching works. 这是在这里添加的,虽然我不确定发布号码/补丁是如何工作的。 You can look for the find_maven_basedir function in that file. 您可以在该文件中查找find_maven_basedir函数。 If it doesn't exist, try upgrading maven. 如果它不存在,请尝试升级maven。

Access the following location in eclipse 在eclipse中访问以下位置

Window
  Preference
    Java
      Installed JREs

Now edit Default VM arguments and 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM