Setting up the path for Maven 3.0.4, win7

2020-05-24 20:14发布

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.

标签: maven-3
10条回答
forever°为你锁心
2楼-- · 2020-05-24 20:17

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.

查看更多
聊天终结者
3楼-- · 2020-05-24 20:18

Yes, Appending that path C:\programfiles\maven\bin to path variable in system variables is enough, it will work. No need to add user variables.

查看更多
放荡不羁爱自由
4楼-- · 2020-05-24 20:28

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
查看更多
该账号已被封号
5楼-- · 2020-05-24 20:28

Version that I always use. Double click and you get the maven up and running

@echo off
title Maven 3.0.5
set JAVA_HOME=C:\Users\hutingung\Development\jdk\jdk1.6.0_33
set MAVEN_OPTS=-Xmx1024m -Xms512m -XX:MaxPermSize=192m -Dfile.encoding=utf-8
set MAVEN_HOME=C:\Users\hutingung\Development\tools\apache-maven-3.0.5\bin
set PATH=%MAVEN_HOME%;%JAVA_HOME%\bin;%PATH%
@cmd /k
查看更多
做个烂人
6楼-- · 2020-05-24 20:29

I followed all the steps but it was not working for me. But as soon i have set the JAVA_HOME Path, in Command prompt just type:

C:>SET JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_91

It is working fine in fraction of seconds. Thanks Everyone.

查看更多
做个烂人
7楼-- · 2020-05-24 20:32

If, like me, you are running mvn -version from the command prompt, and then adding any missing environment variables from the GUI, it is possible that you just have to reload the command prompt after adding the environment variables.

Just exit and run cmd.exe

查看更多
登录 后发表回答