0

I'm a rookie when it comes to Windows. I have installed Apache Maven by following the instructions in the given read me.

What I did was unzip the download and then set PATH="c:\program files\apache-maven-3.3.9\bin"

I then typed mvn --version into the command prompt and then I got the error; 'mvn' is not recognized as an internal or external command, operable program or batch file..

I have read various answers to this problem. Many people have solved it by moving the M2 and M2_HOME from user variables to system variables.

The problem is that I am getting confused by this. Can someone provide me with step-by-step instructions on how to solve this?

TheRealRave
  • 373
  • 1
  • 8
  • 21
  • Does `c:\program files\apache-maven-3.3.9\bin\mvn --version` work? – Rudziankoŭ Jun 17 '16 at 12:17
  • 3
    The step-by-step contains only 1 step: make sure the script `mvn.bat` is in the PATH... Check your environment variables and set it there. – Tunaki Jun 17 '16 at 12:20
  • Looks like you forgot the closing quotes. Or is it just a copy & paste error? – Frank Jun 17 '16 at 12:32
  • 2
    I feel the need to point out that you should be setting PATH like `set PATH=%PATH%;"C:\Program Files\apache-maven-3.3.9\bin"` since otherwise you're overwriting the entire PATH variable and you do _not_ want to be doing that. (Note that this will almost certainly not solve the problem you're currently having, but it will prevent other problems down the line.) – SomethingDark Jun 17 '16 at 12:39
  • 1
    Don't use `M2_HOME` or `M2` not needed. Only correct entry in `PATH` is needed. And of course JAVA_HOME. – khmarbaise Jun 17 '16 at 12:51
  • @Rudziankoŭ It does't work. When I do it I get the error message saying that `mvn` is recognized. – TheRealRave Jun 17 '16 at 13:02
  • @Tunaki I went into `Control Panel -> System -> Environment Variables - > System Variables`. I looked at what is there and I can see "Path" not "PATH". Currently "Path" has the value of `C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Java\jdk1.7.0_79\bin;C:\Program Files\apache-maven-3.3.9\bin\mvn.bat`. I added the `C:\Program Files\apache-maven-3.3.9\bin\mvn.bat` at the end and I am still getting the same error. – TheRealRave Jun 17 '16 at 13:06
  • @Frank That was a copy & paste error. I actually used `set` without the quotation marks. Does that make a difference? – TheRealRave Jun 17 '16 at 13:07
  • @TheRealRave You missed the quotes in your System variables. It should be `"C:\Program Files\apache-maven-3.3.9\bin"` – Tunaki Jun 17 '16 at 13:09
  • Don't specify paths in __PATH__ with double quotes even if the path contains 1 or more spaces. That is not common. A folder path in __PATH__ must be specified with double quotes only if the folder path contains a semicolon (CSV standard with semicolon as separator). See also [How to set environment variables with spaces?](http://stackoverflow.com/a/34402887/3074564) – Mofi Jun 17 '16 at 13:35
  • @Mofi, I agree, double-quotes are not common in `PATH`; but they do not harm, do they? – aschipfl Jun 17 '16 at 16:59
  • @aschipfl Windows itself removes the double quotes around a folder path in __PATH__ and therefore has no problems with folder paths with surrounding double quotes. But I have seen other applications (mainly installers/uninstallers) which modify __PATH__ and have problems with double quoted folder paths in __PATH__ resulting in corrupting __PATH__ value. For example the resulting __PATH__ value has an odd number of double quotes causing misinterpretation of the folder paths. – Mofi Jun 18 '16 at 08:45

1 Answers1

1

Step 1: Unzip maven apache-maven-3.3.3-bin.zip to a location on system say C:\Program Files. So we have a directory structure as:

enter image description here

Step 2: Set an environment variable (system variable) M2_HOME=C:\Program Files\apache-maven-3.3.3

enter image description here

Step 3: Edit the PATH variable (system variable) of your system. Add %M2_HOME%\bin; at the beginning of your PATH variable and click OK.

enter image description here

Step 4: Run mvn -version from command prompt.

enter image description here

Hope, this helps.

Sanjeev Saha
  • 2,632
  • 1
  • 12
  • 19
  • This worked. Thank you. One mistake I was doing is that I was using `apache-maven-3.3.9-bin` instead of `apache-maven-3.3.9-bin` – TheRealRave Jun 17 '16 at 13:37