Nuñito Calzada
Nuñito Calzada

Reputation: 2056

Error: M2_HOME is set to an invalid directory

I got this error

Error: M2_HOME is set to an invalid directory.
M2_HOME = "C:/Users/joanet/.m2/repository"
Please set the M2_HOME variable in your environment to match the
location of the Maven installation

but C:/Users/joanet/.m2/repository is a valid directory !

Upvotes: 2

Views: 7501

Answers (5)

Niroshan Ratnayake
Niroshan Ratnayake

Reputation: 3801

This happened to me when I tried to upgrade to new Maven version.
Below are the steps you should follow when setting up Maven on Windows.
If something is missing, the above error will trigger (most probably the 2nd or 3rd step may be missing for mentioned error).

Step 1:

First, download(Apache Maven download link: https://maven.apache.org) and extract it to C:\Program Files

enter image description here

Step 2:

Go to Environment Variables and Define below varibles in System variables

enter image description here

M2_HOME - C:\Program Files\apache-maven-3.3.9
MAVEN_HOME - C:\Program Files\apache-maven-3.3.9

Step 3:

Make sure to add the maven bin file to Path varible in System variable

enter image description here

C:\Program Files\apache-maven-3.3.9\bin

Step 4:

Once you are done with configurations, make sure to restart the project.

Step 5:

Check whether the Maven is configured successfully using below command

mvn -version

enter image description here

Upvotes: 0

Sagansha San
Sagansha San

Reputation: 176

If your java version is 8 you can remove "MAVEN_OPTS : -Xms256m - XMX512m" environmental variable and check "mvn -v". because java 8 does not support for the above config.

Upvotes: 0

Ishara Samantha
Ishara Samantha

Reputation: 403

Check the System Variable M2_HOME and PATH values set in different maven installation locations.

Upvotes: 0

Grushman
Grushman

Reputation: 41

Such issue appears also, if you have 2 or more mavens installed. Try to delete old versions to have only latest.

Upvotes: 1

JoSeTe4ever
JoSeTe4ever

Reputation: 472

Yes, your folder is valid, but this is not the folder you want to point to.

I think it should point actually where the error messages says to you, to your maven installation folder (something like this)

C:\development\maven\apache-maven-3.1.0

You are currently pointing to your local repository, something which is usually configured in the settings.xml of maven (in the conf folder of the previous url route).

Upvotes: 4

Related Questions