40
votes

I get the following error when I type the command mvn --version:

'mvn' is not recognized as an internal or external command, operable program or batch file.

I have also followed this but still I am unable to get the work done.

when I type this command echo %M2_HOME% I get path printed as D:\Program Files\apache-maven-3.0.4 when I type 'echo %M2%' I get the path printed as D:\Program Files\apache-maven-3.0.4\bin

Environment : Windows XP

3
Thanks for the guy who downvoted and suggested for close, instead should have given reason for doing so when you are not able to answer.Java Questions
The bin folder needs to be set on your %PATH% environment variable. The other variables are irrelevant in order to execute the batch from the shell. Have a look at %PATH%Andreas Dolk
@Andreas_D than please suggest me the CORRECT SITEJava Questions
make sure to relanuch your cmd window after changing pathDenis Tulskiy
There are a lot of sites, there is no "correct site". It's just that this SO site should only be used for programming related question (like: when you have maven up and running but trouble with build definition files). Your problem is "out of scope" according to the rules. Was my comment above helpful?Andreas Dolk

3 Answers

25
votes

Make sure you have your maven bin directory in the path and the JAVA_HOME property set

38
votes

On my Windows 7 machine I have the following environment variables:

  • JAVA_HOME=C:\Program Files\Java\jdk1.7.0_07

  • M2_HOME=C:\apache-maven-3.0.3

On my PATH variable, I have (among others) the following:

  • %JAVA_HOME%\bin;%M2_HOME%\bin

I tried doing what you've done with %M2% having the nested %M2_HOME% and it also works.

11
votes

Add maven directory /bin to System variables under the name Path.

To check this, you can echo %PATH%