mvn not recognized as an internal or external command error

+2 votes
I am trying to install maven on windows. I have downloaded the apache mavenbin.zip and extracted it on my C:\Program Files\apache-maven-3.6.1. I already have jdk 1.8 installed in my system and also have configured the JAVA_HOME and MAVEN_HOME environment variables via the system properties.I have also ensured that i have added their respective bin locations on the PATH variable. Still i am encountering the above error. Kindly help!
Jun 3, 2019 in DevOps Tools by Namik
• 1,230 points
93,298 views

3 answers to this question.

+1 vote

Setting the environment variables JAVA_HOME, MAVEN_HOME and  PATH  via the system property settings may not be effective sometimes.In the command prompt, echo %JAVA_HOME% ,%MAVEN_HOME%, %PATH% and check the values if they are correctly set and included in the PATH as well. if not, you need to set those Environment variables via the command prompt using the following command:

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_211"

setx PATH "%PATH%;%JAVA_HOME%\bin";

same for MAVEN_HOME as well.

setx MAVEN_HOME "C:\Program Files\apache-maven-3.6.1"

setx PATH "%PATH%;%MAVEN_HOME%\bin";

You can check if these are set appropriately by running the commands:  java -version and mvn --version on the command prompt.

answered Jun 3, 2019 by Sirajul
• 59,230 points
setx cammand not recognizing
What's your current PATH variable contents? At minimum, ensure C:\windows\system32 isn't missing from it..
I have done these all Still not working I fount This Problem

cd C:\Program Files\Java; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_111\\jre" "M2_HOME=C:\\Program Files\\apache-maven-3.6.3" cmd /c "\"\"C:\\Program Files\\apache-maven-3.6.3\\bin\\mvn.bat\" -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=webapp-javaee6 -DarchetypeVersion=1.5 -DarchetypeRepository=http://repo.maven.apache.org/maven2 -DgroupId=com.pro -DartifactId=mavenproject1 -Dversion=1.0-SNAPSHOT -Dpackage=com.pro.mavenproject1 -Dbasedir=\"C:\\Program Files\\Java\" -Darchetype.interactive=false -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.0.2\\java\\maven-nblib\\netbeans-eventspy.jar\" --batch-mode archetype:generate\""

I have set all environment variable properly,In fact when I try to check the Java version and maven version on cmd prompt. It shows appropriately, But when I try to run maven web app from jenkins it gives below error..Why is that hapening ? 

C:\Program Files (x86)\Jenkins\workspace\mvn_web_app>mvn package 
'mvn' is not recognized as an internal or external command,
operable program or batch file.
It seems you have not set the path for System variables. That is why it is not working from another folder. Check once in your environment variable.