Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I'm on Windows 8.1 and using Eclipse:

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

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. Check $M2_HOME environment variable and mvn script match.

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

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"

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

like image 586
greeneggsnoham Avatar asked Mar 26 '15 17:03

greeneggsnoham


2 Answers

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:

-Dmaven.multiModuleProjectDirectory=M2_HOME

And for Linux and Mac OS X:

-Dmaven.multiModuleProjectDirectory=$M2_HOME

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

-Dmaven.multiModuleProjectDirectory=$MAVEN_HOME
like image 183
Abhinav Kumar Avatar answered Oct 30 '22 17:10

Abhinav Kumar


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

 -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

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

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

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

like image 16
greeneggsnoham Avatar answered Oct 30 '22 19:10

greeneggsnoham