I have read similar questions about this problem but it is not working anyways.
I've extracted maven 3.3.3 to D:\Maven (Java already installed and works fine) then added 2 system variables:
Variable
Value
M2
%M2_HOME%\bin
M2_HOME
D:\Maven
I've also appended next in the path:
%M2%
But it is still not working.
I can execute mvn -version from the D:\Maven\bin but can't do this from another directory.
Don't put extra space in your path after D:\Maven\bin; in D:\Maven\bin; D:\Program Files\NodeJS; Please don't make any space in path variable.
Normally, To set mvn in command line in windows :
Set JAVA_HOME property in system environment
eg. JAVA_HOME=C:\Program Files\Java\jdk1.8.0_65
Set M2_HOME property in system environment
eg. M2_HOME=D:\apache-maven-3.3.3
Finally add maven to PATH
;%M2_HOME%\bin; add this at the end of PATH property of system environment
Now Try mvn -version
Try to put full maven path upto bin like "C:\Users\ABC\Downloads\maven-2.0.5-bin\maven-2.0.5\bin" directly into path variable of os, then you will be able to understand where problem exists.
One mistake I did was, There will two environment variables section
One can be accessed via admin while the other one doesn't require any.
Please specify the paths in the second place
It will work for sure., also try echo %M2_HOME% to check whether you have configured correctly..before jumping to mvn install
Hope this helps for someone who has to use admin rights
I installed ant in my system, when I run ant command, I get following error:
Error: JAVA_HOME is not defined correctly. We cannot execute
/usr/lib/jvm/java-6-sun/bin/bin/java
Please suggest what should I do?
Set the environment variable JAVA_HOME to the installation directory of your JDK, which is: /usr/lib/jvm/java-6-sun
It looks like you have set it to /usr/lib/jvm/java-6-sun/bin (note the /bin at the end); the ant command appends another /bin so that you get .../bin/bin/java which is incorrect.
In your Java installation directory, u can see a jre subdirectory that contains the bin directory that contains java and related executables.
So you should probably be setting JAVA_HOME to /usr/lib/jvm/jdk/jre rather than /usr/lib/jvm/jdk.
I have problem with MAVEN path
i have already set all the path but not working please see the below path
Path
....;C:\Program Files\Java\jdk1.6.0_20\bin;D:\apache-maven-3.2.1\bin
JAVA_HOME
C:\Program Files\Java\jdk1.6.0_20
MAVEN_HOME
D:\apache-maven-3.2.1
When i try to run mvn --version it will give error of JAVA_HOME please see the error
Error: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jdk1.6.0_20\bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
But javac is working fine
JAVA_HOME needs to point to the folder which contains bin/, lib/, etc.
Your variable points inside of Java's home folder.
Change JAVA_HOME C:\Program Files\Java\jdk1.6.0_20\bin to C:\Program Files\Java\jdk1.6.0_20.
PATH and JAVA_HOME are two different things:
With PATH you tell the system where to search for commands. There you should have
PATH=...;C:\Program Files\Java\jdk1.6.0_20\bin;
With JAVA_HOME you define where your Java has been installed. Applications using JAVA_HOME add the bin and/or lib directories. There you should have
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
Try the following in a DOS-Box:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
set MAVEN_HOME=D:\apache-maven-3.2.1
set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin
mvn --version
Once you have identified the JRE installation path:
Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced tab.
Click the Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
If your Java installation directory has a space in its path name, you should use the shortened path name (e.g. C:\Progra~1\Java\jre6) in the environment variable instead.
Icon
Note for Windows users on 64-bit systems
Progra~1 = 'Program Files'
Progra~2 = 'Program Files(x86)'
Click OK.
Click Apply Changes.
Close any command window which was open before you made these changes, and open a new command window. There is no way to reload environment variables from an active command prompt. If the changes do not take effect even after reopening the command window, restart Windows.
If you are running the Confluence EAR/WAR distribution, rather than the regular Confluence distribution, you may need to restart your application server.
You required to set or make sure about 3 variables environment behaviour:
1. M2_HOME: set this environment variable to point out to apache maven directory. Note: must not be point to bin directory.
JAVA_HOME: This environment variable must be point to jdk folder, not include bin directory.
path: your system/user path variable must be pointing to bin directory of java environment.
this works fine for me.
first set all these things
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
set MAVEN_HOME=D:\apache-maven-3.2.1
set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin
check
mvn --version
if still not working then delete path in environment variables again create it as
PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin
close previously opened cmd prompt
open new cmd
and check
mvn --version
I am setting Environment Variable, Still OS cant recognise. Check this out you will get it.
https://www.dropbox.com/s/raqr4wbtoxxz0b8/1.JPG
I tried with Admin privileges also still same but when I enter
echo %java_home%
or
echo %jre_home%
It is showing path corretly. Why isnt javac command working.
Any Help will be appreciated.
You don't have javac in your path. Setting the JAVA_HOME and/or JRE_HOME environment variables (which aren't needed any more, for the most part) does nothing to the PATH which the command shell uses to find executables.
Put the relevant JDK bin directory in your PATH environment variable instead - and unless you actually need JRE_HOME and JAVA_HOME for some reason, I'd get rid of them. If you do need them, get rid of the "bin" part - it should just be the root JRE directory, e.g.
c:\Program Files\Java\jdk1.7.0_45
Your path JAVA_HOME should be, for example
C:\Program Files\Java\jdk.1.7.0_45
And your Path variable should be
...;%JAVA_HOME%\bin
javac is in the bin folder which should be on your path.
That has nothing to do with Java environment variables.
When you type javac, or any other command, Windows will search the folders in the %PATH% environment variable to find an EXE file with that name.
You need to add your JDK directory to %PATH%.
You also need to restart cmd to pick up the changes.
Include the JRE/JDK path in System variables->PATH as well
After adding path varaibles,restart the cmd
You must restart cmd for new variables to be picked up. And java bin folder needs to be included in path. When you type javac it goes through all folders defined in path to find it.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I've followed the official installation instructions here for Windows XP. But sometimes when I execute mvn --version, I receive the error message,
'mvn' not recognized as an internal or external command
I've even rebooted my machine a couple times, but the OS does not always recognize the maven command. But when I execute either, cd %M2_HOME%, or cd %M2% it brings me to the installation directory. I've also made sure to add the user variable M2 to the Path system variable.
So, what gives?
Way around would be moving M2 from user variables to system variables
Looks like maven is not present in your PATH. Add the absolute maven home\bin location to your PATH.
I had this same problem, restart the command prompt and then check try mvn --version. It was probably set and working the whole time but command prompt needed to be restarted to be able to access the new system variable.
Download apache-maven-3.3.9-bin.zip file and extract it.
Then set system variable M2_HOME = B:\sql software\apache-maven-3.3.9 or as appropriate
Also set variable M2 = %M2_HOME%\bin
Open CMD and write mvn
I solved thank you
Just adding some more info that solved the problem for me:
Make sure that the %M2% and %M2_HOME% variables doesn't have the semicolon (;) at the end. This should only be used if there are more than one location in that path, which is not the case;
Also, make sure that in the "Path" variable, there aren't any spaces between the various paths, separated by the semicolon.
Thanks to Pawan Valecha and Abhijeet Sawant for the tips.
Heres what i did wrong:
1) make sure its NOT in a [C:\Program Files (x86)] it should be in [C:\Program Files] i am not 100% if that could break it but you never know.
2) There were 3 things i needed to do in my Environment Variables to get it to work
Create a user var like this [ M2 = %M2_HOME% ]
Create a user var like this [M2_HOME = C:\Program Files\Apache Software Foundation\apache-maven-3.2.2]
Edit the PATH to [What ever is already in here +];%M2%
same problem.
and I solved it by:
add C:\Program Files\apache-maven-3.3.9\bin; to PATH
run cmd as administrator
and then mvn --version works.
Maven should be configured in the following way (can be user variables or system):
- M2: %M2_HOME%\bin
- M2_HOME: (your directory to Maven's root, not \bin)
- PATH: %PATH%;%M2%
You should then be able to run mvn from the command prompt.
I've suffered from this problem and found that, for some reason or other, environment variables were simply not being parsed (executing cd %M2% told me that there was no folder %M2% in the current directory). In the end adding the explicit path to Maven's executable worked for me:
C:\apache-maven-3.1.0\bin
You need to set M2 and M2_HOME.
I was facing same problem and issue was I had put one extra space in PATH variable after semicolon. Just removed space from path and it worked. (Windows 7 machine)
Installtion Steps
Download Binary zip archive or tar.gz.
Copy in the respective folder. Example - C:\apache-maven-3.3.9
Add Variable (either user or system) M2_HOME = C:\apache-maven-3.3.9
Add Variable (either user or system) MAVEN_HOME = C:\apache-maven-3.3.9
Update Variable PATH with C:\apache-maven-3.3.9\bin
Open CMD and Type mvn -v or mvn --version it should give the below response
C:\Users\XXXXXXX>mvn --version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:4
7+05:30)
Maven home: C:\apache-maven-3.3.9
Java version: 1.8.0_40, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_40\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 8", version: "6.2", arch: "amd64", family: "dos"
**Make sure all variables have correct values using echo %M2_HOME% on CMD
I solved this by creating all under user variables (including the PATH variable).
This is because the system variables do not "translate" the user variables.
So if you only want to use maven in your account, you need to add another PATH variable as a user variable, not system variable.
As others have done, creating new System variables M2 and M2_HOME solved the problem. Just making User variables M2 and M2_HOME on my Windows XP machine led to maven not being recognised from the command line. I then deleted the User variables, created copies as System variables and it all came to life.
This was apache-maven-3.0.4 with XP sp3.
So the instructions in: http://maven.apache.org/download.cgi seem incorrect.
Running command prompt as Administrator solved the problem for me. I did not have to move M2 or M2_HOME under system variables.
Most probably you may have not installed maven correctly.
use this to download maven. Download the latest (Binary tar.gz) file.It worked for me.
I had the same issue, there was no issue in my syntax, but when I moved the M2, M2_HOME, JAVA_HOME environment variables from user to system it started working. Path variables stayed the same.
Add your Maven bin path to the System variable as given below
Go to the
> Enviornment Variables > set Path=D:\apache-maven-3.2.1\bin
or if path is already set than append the path with ";"
restart command and try
running maven to win 7
unzip apache-maven to directory C:\Program Files\apache-maven-3.2.1
go to [Enviroment Variables] set [path] C:\Program Files\apache-maven-3.2.1\bin;
open cmd and type C:\Program Files\apache-maven-3.2.1> mvn -version
I had similar issue on Windows 7. At first I setup M2, M2_HOME under User variable but when I echoed %PATH% , I did not see maven bin directory listed under PATH. Then I setup M2, M2_HOME under system variable and it worked.
Delete M2 and M2_HOME from user variables and move to system variables. That will solve the problem
Had the same problem,
mvn --version
worked but
maven --version
did not. I prefer using 'mvn' over 'maven' anyway so all is well. I also logout/login in to be sure.
Make sure that you haven't renamed some folder which falls in the path of the M2 environment variable. In case you have, then change your M2 and/or M2_HOME accordingly.
It doesn't matter whether M2 or M2_HOME are System Variable or User Variables as long as you are logged in with the same user under whose scope the environment variables are.
I have got it solved by adding Path variable in user variables as %JAVA_HOME%\bin;%M2_HOME%\bin;
The accepted answer didn't help but simple step below fix it !
Under system PATH:
instead of using M2%, use %M2_HOME%\bin, as simple as that.
N.B my %M2_HOME% is pointing to %MV3_HOME% instead of actual absolute path bcos I have multiple version of maven installed and trying to be clever (switch between maven versions on the same box for different project).
A temporary work around would be to set the path from the terminal itself. Worked for me after that. Running as administrator also works. Both M2 and M2_HOME are already set as system variables in my case.
I was facing the same issue while executing the command mvn -version; however, I checked I had also set the mvn options in the environment variables setting, which gave me some Heap memory issue on the command prompt. So, I removed the maven options that I had set and then it worked fine for me.
I was facing the same issue and then I closed and reopened cmd.exe to get mvn -vto propagate to my command prompt.
If cmd was open when you set the variables they will not be available in that session.
Assuming you've created the variable path for maven as follows:
Under System path, click new then edit as follows:
Variable name: MAVEN_HOME
Variable value: C:\Program Files\apache-maven-3.5.3\bin
Then continue with these instructions:
Under System Path, update variable path by clicking on edit and add:
C:\Program Files\apache-maven-3.5.3\bin;
immediately after:
C:\Program Files\Java\jdk\1.8.0_161\bin;
remember to add semi-colon ; after \bin as included above and then run your cmd prompt and type:
mvn -v