mvn is not recognized after installation Maven 3 - maven

I have some problems with my maven 3 installation.
I have downloaded maven 3.0.3 and extracted it to a folder.
I set the following environment variables.
M2_HOME: C:\a few folders\apache-maven-3.0.3
M2: %M2_HOME%\bin
JAVA_HOME: C:\Program Files\Java\jdk1.6.0_25
Path: %JAVA_HOME%\bin; %M2%
I get a message that the command is not recognized when i type "mvn" in the command line. Any ideas?

Maven 3.0.3 and later doesn't need the M2_HOME variable.
The following environment variable changes are sufficient to run Maven from the command-line:
Setting JAVA_HOME to the Java jdk directory (eg. C:\Program Files\Java\jdk1.6.0_29)
Setting PATH to include the Maven bin directory.

Everything looks OK.
I don't know if there should be a space after the semicolon and %M2%. This might be your problem.
Make sure you typed a "a few folders" correctly.

Try this:
Add(create) these new variables at the SYSTEM VARIABLES (M3_HOME and M3):
M3_HOME: C:\maven_installation_folder\
M3: %M3_HOME%\bin
Include at: "CLASSPATH" and "Path" variables
CLASSPATH: other_variables;%M3%;
Path: other_variables;%M3%;
Go to Command Prompt (cmd) and type:
mvn -version

Maven 3.0.3 and later doesn't need the M2_HOME variable. So no need to add that.
I did the following in the Windows System variables and it works:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_31
Path=C:\Program Files\Java\jdk1.8.0_31\bin;C:\Selenium 3\Maven\apache-maven-3.3.3\bin

Related

Maven isn't installing correctly

I am trying to install maven v3.5.4 onto my computer and whenever I try the 'mvn -version' command, I get
'mvn' is not recognized as an internal or external command,
operable program or batch file.
I have looked up multiple tutorials on how to do this, and they are giving nearly the same information. Add system variables M2 and M2_HOME, then append a directory to the Path system variable. I have the System Variables configured to the following:
M2:
Name: M2
Value: C:\Program Files\Apache\maven\bin
M2_HOME:
Name: M2_HOME
Value: C:\Program Files\Apache\maven
MAVEN_HOME:
Name: MAVEN_HOME
Value: C:\Program Files\Apache\maven
Path:
Name: Path
Value: %M2_HOME%\bin;%JAVA_HOME%\bin
I have seen people saying that there should be a .exe or .bat file inside the bin directory. I do not have any of these. I only have 4 files inside this folder.
This could perhaps be the issue. The path to my Maven directory is:
I have the following maven related system variables:
And my Path variable is:
I'm not sure how to fix this issue so if anyone knows, please let me know.
Add a variable MAVEN_HOME like:
Name: MAVEN_HOME
Value: C:\Program Files\apache-maven-3.3.9\bin
In your case, the M2_HOME path is not correct. Hence It must not be working. Try to give the correct path to the bin folder.
First you have to download maven from here, preferably the latest version and install it.
Then, you have to set the Path variable for Maven.
Go to Start and search for 'Edit the system environment variables'.
Choose the environment variables option and like you do in the example you provided, leave M2_HOME as you have it, delete M2 and change the one in your path to: %M2_HOME%\bin\;
Also, please make sure that you are editing the system environment variables.
As I it says on the download page of the version you are trying to install: "Maven 3.3+ require JDK 1.7 or above to execute". So make sure you have the right version of java.
If this does not work, then I don't think someone on Stack-Overflow can help.
Install Java
Download Java SE Development Kit from Oracle's website and install it
Browse via windows search to Environment Variables
Press New... in System variables list
Insert JAVA_HOME to Variable name
Insert its path to Variable value (e.g: C:\Program Files\Java\jdk1.8.0_102)
Press Edit to Path and then press New
Insert %JAVA_HOME%\bin
Open cmd and type java -version to check if it is ok
Install Maven
Download Maven Binary zip archive from Apaches's website
Unzip the folder and move it to C:\Program Files
Browse via windows search to Environment Variables
Press New... in System variables list
Insert MAVEN_HOME to Variable name
Insert its path to Variable value (e.g: C:\Program Files\apache-maven-3.6.2)
Press Edit to Path and then press New
Insert %MAVEN_HOME%\bin
Open cmd and type mvn -version to check if it is ok

Not able to check maven version

When i run the below command i am not getting the maven version. java -version works perfectly.
>mvn -v
'mvn' is not recognized as an internal or external command,
operable program or batch file.
Below are the environment variables set
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_11
M2_HOME=C:\Program Files\apache-maven-3.5.3
M2=%M2_HOME%\bin
PATH=%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;%JAVA_HOME%\bin;%M2%;
Try moving the folder apache-maven-3.5.3 to C:\apache-maven-3.5.3
Make sure you are adding environment variable to SYSTEM VARIABLES:
M2_HOME = C:\apache-maven-3.5.3
Then add %M2_HOME%\bin to the PATH system variable.
Try also running the command line with Administrator privileges.

How to add Maven to the Path variable?

I have downloaded the maven 3.5.0 from here. I have set it in the path:
C:\apache-maven-3.5.0
Then i treid to add it to the path of Windows 7 as below:
Right click on my computer
Properties
Advanced System Setting
Environment Variable
New user variable and added Maven_Home with value C:\apache-maven-3.5.0
Add it to path variable with: %Maven_Home%\bin
Open cmd and ask for mvn -version in desktop
Result:
It does not recognize maven
In windows:
Download the latest version of Maven from the http://maven.apache.org/ and Navigate to Use --> Download --> Download the Binary zip archive.
1) After the download, unzip the folder and copy it to the folder. (Lets say i have copied to c:\program files\apache-maven-3.52.
2) Setting the path of Maven in environment Variables:
Search the Environment Variable --> Edit the System Environment variables--> Navigate to Advanced tab --> Environment Variables
i) MAVEN_HOME : Click New --> Variable Name : MAVEN_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2
ii) M2_HOME : Click New --> Variable Name : M2_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2
iii) Edit the 'Path' Environment Variable --> %M2_HOME%\bin
Testing whether Maven is installed:
mvn -version
References:-
http://www.baeldung.com/install-maven-on-windows-linux-mac
NOTE : In point iii don't forget to put semicolon(;) before and after.
Open command console
copy this
set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH%
cahnge the path accordingly
click enter
it's all set and now check mvn -version
I had the same problem and fixed the issue by:
Adding the M2_HOME to the USER VARIABLES
Adding the MAVEN_HOME to the USER VARIABLES
Adding the BIN folder to the PATH in the SYSTEM VARIABLES
(conform this video: https://www.youtube.com/watch?v=RfCWg5ay5B0)
Then i could run mvn -version in a NEW command terminal.
The problem get solved when i edit the path variable with ;%Maven_Home%\bin; so i should add the ; before and after it.
Adding
MAVEN_HOME variable (C:\Program Files\apache-maven-3.5.2) and M2_HOME variable (C:\Program Files\apache-maven-3.5.2\bin).
Add %MAVEN_HOME%\bin to the path in system variables .
Then mvn -version in command prompt.
Make sure you download the Binary zip file from https://maven.apache.org/download.cgi. Then it should work fine by adding it to the path variable as mentioned in other answers. I've accidentally downloaded the src.zip file and of course it didn't work.
Additionally I would add this information that worked for me
After I opened the Environment Variables and followed these steps:
System variables > path > edit > add this one: C:\apache-maven-3.6.3\bin > ok button.
Also I would send my System variables you may need
I am using Windows 10
The changes in "System variables" requires system restart to take effect. ( The same for Linux systems also)
After doing changes, you need to reopen CMD window. In my case, my terminal window was opened before updating environment variables, and changes were not reflecting there i.e. mvn -version was returning "...not recognized as an internal or external command".
1) Make sure JDK is installed, and “JAVA_HOME” variable is added as Windows environment variable.
1) Download the Maven zip file, for example : apache-maven-3.5.0-bin.zip. Unzip it to the folder you want to install Maven.
Assume you unzip to this folder – C:\Program Files\Apache\maven
3) Set the environment variables using system properties. Add M2_HOME, M2, MAVEN_OPTS to environment variables.
M2_HOME=C:\Program Files\Apache\maven\apache-maven-3.5.0
M2=%M2_HOME%\bin
MAVEN_OPTS=-Xms256m -Xmx512m
4) Now append M2 variable to System Path.
Append the string ;%M2% to the end of the system variable, Path.
5) Open Command Console and run this command c:\> mvn --version
you will get bellow output :
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17:27:37+05:30)
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.3.3
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_75\jre
Default locale: en_US, platform encoding: Cp1252

MAVEN - Setting Path in Redhat so the maven commands can be run from anywhere

I have just installed Maven on Redhat, the apache-maven-3.3.9 is located in /root/, I ran the following command to set the path (JDK java home path already set and when I type $PATH the below path does show, along with when I type mvn --version):
export PATH=/root/apache-maven-3.3.9/bin:$PATH
The project I want to build with Maven is also in /root/ however, I cannot use the maven commands within the project or anywhere else except for /apache-maven-3.3.9/bin directory.
Any help would be much appreciated!
You need to add it to your ~/.profile file.
export PATH=$PATH:/root/apache-maven-3.3.9/bin
so that when you exit the terminal and start a new terminal instance path is not lost

Error: M2_HOME is set to an invalid directory

I got this error
Error: M2_HOME is set to an invalid directory.
M2_HOME = "C:/Users/joanet/.m2/repository"
Please set the M2_HOME variable in your environment to match the
location of the Maven installation
but C:/Users/joanet/.m2/repository is a valid directory !
Yes, your folder is valid, but this is not the folder you want to point to.
I think it should point actually where the error messages says to you, to your maven installation folder (something like this)
C:\development\maven\apache-maven-3.1.0
You are currently pointing to your local repository, something which is usually configured in the settings.xml of maven (in the conf folder of the previous url route).
Such issue appears also, if you have 2 or more mavens installed. Try to delete old versions to have only latest.
Check the System Variable M2_HOME and PATH values set in different maven installation locations.
If your java version is 8
you can remove "MAVEN_OPTS : -Xms256m - XMX512m" environmental variable and check "mvn -v".
because java 8 does not support for the above config.
This happened to me when I tried to upgrade to new Maven version.
Below are the steps you should follow when setting up Maven on Windows. If something is missing, the above error will trigger (most probably the 2nd or 3rd step may be missing for mentioned error).
Step 1:
First, download(Apache Maven download link:
https://maven.apache.org) and extract it to C:\Program Files
Step 2:
Go to Environment Variables and Define below varibles in System variables
M2_HOME - C:\Program Files\apache-maven-3.3.9 MAVEN_HOME -
C:\Program Files\apache-maven-3.3.9
Step 3:
Make sure to add the maven bin file to Path varible in System variable
C:\Program Files\apache-maven-3.3.9\bin
Step 4:
Once you are done with configurations, make sure to restart the project.
Step 5:
Check whether the Maven is configured successfully using below command
mvn -version

Resources