Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up the path for Maven 3.0.4, win7

Tags:

maven-3

I have been trying to install Maven v 3.0.4 on my machine win 7 for the first time.I have a problem setting the path environment System variable I have the following 4 entries :

PATH
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_04;C:\Program Files\apache-maven-3.0.4\bin;M2_HOME;%M2%


M2_HOME
C:\Program Files\apache-maven-3.0.4\bin

M2
%M2_HOME%\bin

JAVA_HOME
C:\Program Files\Java\jdk1.7.0_04\bin

when I do mvn --version

I get the error:

JAVA_HOME not found in your environment, please set the JAVA_HOME variable in your environment to match the location of your java installation

The java -version displays the java version fine,

what am I doing so horribly wrong? Is the PATH ok?

Help appreciated, thanks.

like image 295
MegaPixel Avatar asked Jun 07 '12 19:06

MegaPixel


People also ask

Do we need to set path for Maven?

If it is set, edit the path and append the path of maven. Here, we have installed JDK and its path is set by default, so we are going to append the path of maven. The path of maven should be %maven home%/bin. For example, E:\apache-maven-3.1.

Where is Maven installed on Windows?

There is no default installation location for maven. It is distributed as a zip file. If you're sure you have maven on your machine, you need to search where you extracted it. You should search for "mvn.


4 Answers

It is only necessary to set the path to the Maven binary and to the JDK correctly:

set PATH %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_04\bin;C:\Program Files\apache-maven-3.0.4\bin

Furthermore you need to set the JAVA_HOME correctly which is done under windows like this:

SET JAVA_HOME=C:\Program Files\Java\jdk1.7.0_04

Be aware of setting JAVA_HOME to the root of the installed JDK and not to bin folder it. The settings of M2 and M2_HOME is not necessary.

like image 164
khmarbaise Avatar answered Oct 25 '22 05:10

khmarbaise


from command prompt run the following

set M2_HOME= C:\Program Files\apache-maven-3.0.4
set PATH=%PATH%;%M2_HOME%\bin
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_04
set PATH=%PATH%;%JAVA_HOME%\bin
cmd.exe
mvn -version
like image 39
Sin2 Avatar answered Oct 25 '22 05:10

Sin2


The environmental variables should point to the installation directory of each program respectively, and their corresponding bin folders should be added to the PATH:

  • Make sure that your JAVA_HOME points to the C:\Program Files\Java\jdk1.7.0_04 (or whatever directory you have installed your JDK to).

  • Add the %JAVA_HOME%\bin folder to your PATH (e.g. by replacing the part with C:\Program Files\Java\jdk1.7.0_04). Make sure that you use ; to separate different path components.

  • Likewise, the M2_HOME variable should be assigned Maven's installation directory, e.g. C:\Program Files\apache-maven-3.0.4 and you should add %M2_HOME%\binto the PATH (the part with C:\Program Files\apache-maven-3.0.4\bin;M2_HOME;%M2% can be removed.

The advantage of adding the environmental variables %JAVA_HOME%\bin and %M2_HOME%\bin on the path rather than the fully qualified path is that it will be easy to update Java and Maven (or to have several versions installed in parallell). All you need to do is to update the environmental variable, and the PATH variable will fallow automatically.

like image 7
matsev Avatar answered Oct 25 '22 05:10

matsev


I ran into the same issue as the original poster. I checked, double checked, and triple checked everything to conform to what everyone has (correctly) indicated the setup needs to be. I still got the same error. In the end, I ran SET JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45 from the command line and then ran the mvn command and viola.

So, for what ever reason, pss's suggestion did the trick. Obviously, this doesn't really change what everyone else said, because that's exactly what my environment variables look like...just had to hit the JAVA_HOME from the command line.

Oddness.

like image 6
Brad Ellis Avatar answered Oct 25 '22 05:10

Brad Ellis