Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

May be question is asked before but i found very strange kind of error. When I run mvn --version command from bin its gives the version and the other information. However when I run outside bin it gives exception. Both the result mention below

C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin>mvn --version
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:
28+0530)
Maven home: C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_25\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5>mvn --version
'mvn' is not recognized as an internal or external command,
operable program or batch file.

Also i set JAVA_HOME in user variable and M2_HOME, M2 in system environment variable. The output for these variables and %path% is:

C:\Users\SAHILBHALLA>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.7.0_25

C:\Users\SAHILBHALLA>echo %M2%
C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin

C:\Users\SAHILBHALLA>echo %M2_HOME%
C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5

C:\Users\SAHILBHALLA>echo %path% 
C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPow erShell\v1.0\;C:\Program Files\Java\jdk1.7.0_25\bin;.; 

Tell me where i am wrong. What should i do recover from it?

like image 388
rahul Avatar asked Jul 02 '13 18:07

rahul


2 Answers

My problem solved, path didn't resolve %M2%. When i added location of maven-bin in the path instead of %M2% after that commands works.

I would like to thanks to all those who try to solve the problem

like image 96
rahul Avatar answered Sep 19 '22 16:09

rahul


This problem arise because there is no any environmental variable corresponding to installed maven in your OS. For fixing this problem, I always use Intellij's bundled Maven and do not install separate version of Maven again, for finding bundled Maven's path go to intellij and hit Ctrl+Alt+S -> Build, Execution, Deployment -> Build tool -> Maven -> Maven home directory you can find the intellij's bundled maven path there as below image demonstrates.

enter image description here

Then go to System environment variables and set these variables:

Variable name: MAVEN_HOME

Variable value: C:/Program Files/JetBrains/IntelliJ IDEA 2019.3.1/plugins/maven/lib/maven3

enter image description here

After defining system variable MAVEN_HOME find variable path and add this line to the list

%MAVEN_HOME%\bin

enter image description here

Work is done, open command prompt and test it by writing mvn -v. 99 percent of the time it work, if you're among 1 percent, you have to restart your computer.

If you want to use mvn command from intellij's internal terminal you have to restart intellij after setting environment variables, then you shouldn't have any problem running maven command from terminal.

like image 21
D B Avatar answered Sep 20 '22 16:09

D B