2

Recently I downloaded the apache maven 3.3.9 zip and extracted it to my D:\ directory but when I run mvn -version or mvn in cmd sometimes it gives me the error mvn is not an internal or external command and sometimes JAVA_HOME is not set properly. However I checked by echo %JAVA_HOME% that it points to the right location of my jdk which is in my C:\ directory. I also inserted variables in user and environment variables. I run cmd as administrator. I have tried almost everything but nothing works. Can anyone please tell me how to fix this problem? It would be really appreciated. Thanks.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
AIK
  • 498
  • 2
  • 6
  • 20
  • 2
    do you have M2_HOME set? and you have M2_HOME in your PATH? – Nathan Hughes Jan 12 '16 at 20:07
  • 4
    Did you read the fancy [manual](https://maven.apache.org/install.html)? –  Jan 12 '16 at 20:08
  • Have you made sure that you are setting the "system variable" for mvn and not the "user variable". source: http://stackoverflow.com/questions/11890116/apache-maven-install-mvn-not-recognized-as-an-internal-or-external-command-a?rq=1 – nerdy900 Jan 12 '16 at 20:10
  • @NathanHughes my M2_HOME = D:\aamish\softwares backup\apachemaven3.3.9 JAVA_HOME = C:\Program Files\Java\jdk1.8.0_05 and PATH = C:\Windows\System32;%M2_HOME%\bin. All of them are in system variables in environment variables. – AIK Jan 12 '16 at 20:15
  • @RC.read the manual that's why asked here – AIK Jan 12 '16 at 20:31

2 Answers2

6

Open command line, type "set" and hit enter, it will give you list of environment variables. Search for M2_HOME and JAVA_HOME. If they don't exist then you need to right click My Computer--> Properties --> Advanced --> Environment variables. Add M2_HOME and JAVA_HOME environment variables there.

First, add JAVA_HOME, you need to click on User variables, add new variable and set it to your java directory, for example: "C:\Program Files\Java\jdk1.7.0_75"

Then add Java compiler location to System Path by clicking System Variables, choose Path, click edit and set it to java directory on your system. Make sure that path to compiler location ends with "/bin", like here: "C:\Program Files\Java\jdk1.7.0_75\bin"

To add M2_HOME do the same, set it to your location, for example: "C:\Program Files\Apache Software Foundation\apache-maven-3.3.3".

When you done, verify it on command line: mvn --version

Foxy
  • 416
  • 8
  • 18
4

The mvn executable has to be added to your PATH variable. Alternatively you can try starting mvn from its bin-directory as a first test.

This explains everything.

Hendrik Jander
  • 5,515
  • 3
  • 23
  • 31
  • 1
    your answer helped me to reach my solution. When i ran the mvn -version command from the maven bin directory. It gave me an error that M2_HOME variable is not set properly. My M2_HOME variable was set like this M2_HOME = D:\aamish\softwares backup\apachemaven3.3.9. After removing spaces in the path and adding a \ in the end worked. Now my path looks like this M2_HOME = D:\aamish\softwaresbackup\apachemaven3.3.9\. Thanks bro it helped me solve the problem so i will accept your answer as a compliment :) – AIK Jan 12 '16 at 20:43