Reputation: 1122
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?
Upvotes: 27
Views: 311878
Reputation: 2933
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.
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
Path update: C:\Program Files\JetBrains\IntelliJ IDEA 2023.1.3\plugins\maven\lib\maven3
After defining system variable MAVEN_HOME
find variable path
and add this line to the list
%MAVEN_HOME%\bin
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.
Upvotes: 32
Reputation: 221
i do like this , i use with intellij
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.1.2\plugins\maven\lib\maven3
and you also need to add this in the Path variable
click Path -> Edit -> New -> and paste it so it references to just created
%M2_HOME%\bin
Upvotes: 0
Reputation: 24192
maven should be on the system's PATH
if you wish to execute it from any place. add %M2_HOME%\bin
to the PATH
Upvotes: 14
Reputation: 541
Try these steps...
cmd : mvn -version
go apache-maven folder > bin
copy the path and go System properties > environment variables > system variables
path > edit > [paste the file path]
next restart your machine.
Upvotes: 1
Reputation: 57
To solve this problem please follow the steps below:
Upvotes: 4
Reputation: 1
I did all of this in Windows 10 and still had a problem. In the end it turned out that the path to the Maven home folder was not exactly what was expected in many of these answers as it turned out to be /apache-maven-3.6.3-bin/apache-maven-3.6.3. Once I corrected this for both the system variables and the PATH variable, it worked. In short, if you have set the environment variables up as directed and it still won't work, I would double check to make sure the variables really point to the exact path to the Maven home folder and the bin folder on your machine.
Upvotes: 0
Reputation: 150
The following helped me in Win10.
%M3_HOME%\bin;
as value for Path variable under User Variables.M3_HOME
variable under System Variables.%M3_HOME%\bin;
as value for Path variable under System Variables.mvn -version
It will work.
Upvotes: 3
Reputation: 400
Go to Environment Variable and paste the following:
Under System Variable: Step 1: New --> New User Variable 1. Variable name: MAVEN_HOME 2. Variable_value : D:\apache-maven-3.5.2
Step 2: 1. Go to the path --> and paste this - %MAVEN_HOME%\bin
Upvotes: 1
Reputation: 101
In Windows 10, I had to run the windows command prompt (cmd) as administrator. Doing that solved this problem for me.
Upvotes: 8
Reputation: 936
Here is the best Maven-Environment Setup tutorial for Windows, Unix and Mac Operating systems.
But in the last you have to set value of PATH
variable as ";%M2_HOME%\bin"
instead of "%M2%"
, because PATH
variable is not able to reduce the value using "%M2%"
Upvotes: 1
Reputation: 11387
In windows 7, I Got it resolved after adding the environment variables in system level.
If you do not have enough permission try to set the %JAVA_HOME%
and the %M2_HOME%
in System variables instead of User Variables.
Upvotes: 5
Reputation: 103
First of all make sure you java is working or not run this command in cmd
C:\>java -version
if it's working it will show this output:-
C:\>java -version
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) Client VM (build 25.74-b02, mixed mode)
step 1. First set your java_home[C:\Program Files\Java\jdk1.8.0_74] path in user variable.
step 2. Then set MAVEN_HOME[C:\Program Files\maven\apache-maven-3.3.9] path in system variable and make sure your maven folder should be present in C folder only.
step 3. Then set M2 path in system variable and give maven bin location there i.e.[C:\Program Files\maven\apache-maven-3.3.9\bin].
Step 4. Then set new system variable i.e. variable name = MAVEN_OPTS in and variable value =-Xms256m -Xmx512m
Step 5. Then edit path/system path variable be care full don't remove anything from there simply add java_home path i.e=;C:\Program Files\Java\jdk1.8.0_74 and M2 variable=;%M2% in the end.
Step 6. To make sure maven is now working or not run this command in cmd
> C:\>mvn --version
if it's working it will show this result :-
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-
7+05:30)
Maven home: C:\Program Files\maven\apache-maven-3.3.9\bin\..
Java version: 1.8.0_74, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_74\jre
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "dos"
Upvotes: 10
Reputation: 915
Go to the shell (cmd for windows) and set the path variable manually from there. It works often from there. Read more at http://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/
Upvotes: 1
Reputation: 991
got it solved by first creating new "Path" variable under User variables (note that after fresh windows install Path variable is not created as User variable, only as system) after that, I appended %M2% (pointing to maven dir/bin) to (freshly created) user Path variable. after that restarted cmd window and it worked like a charm.
Upvotes: 1
Reputation: 51
After setting the path with the Maven bin location close the prompt window and restart it. Use the echo %path%
command to make sure the path is set with Maven variables then run the command mvn -version
. Somehow if the path is set when the prompt window is running it does not pick the new variables.
Upvotes: 5
Reputation: 1122
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
Upvotes: 27
Reputation: 2164
I prefer adding path to ~/.bashrc.
vim ~/.bashrc, then add these lines:
export M2_HOME=/usr/local/apache-maven-your_maven_path&version
export M2=$M2_HOME/bin
Upvotes: 0