Unable to install Maven on Windows: “JAVA_HOME is

2020-01-27 14:13发布

I followed the Maven tutorial to the letter but I still can't get Maven installed on Windows.

When I run the following in command prompt:

E:\Documents and Settings\zach>mvn --version

I get:

'mvn' is not recognized as an internal or external command, operable program or batch file.

I navigated to the maven install folder and ran mvn --version and got:

E:\java resources\apache-maven-2.2.0\bin>mvn --version
ERROR: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "E:\Sun\SDK\jdk\bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation

but when I run java -version I get:

java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode)

So I do have Java installed. Anyone know what the problem is?

标签: java maven-2
16条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-01-27 14:29

The problems are to do with your paths.

  1. Make sure that the directory "E:\java resources\apache-maven-2.2.0\bin" is on your command search path.
  2. Make sure that the JAVA_HOME variable refers to the home directory for your Java installation. If you are executing Java from "E:\Sun\SDK\jdk\bin", then the JAVA_HOME variable needs to point to "E:\Sun\SDK\jdk".

    NB: JAVA_HOME should NOT end with "\bin"1.

  3. Make sure that you haven't put a semicolon in the JAVA_HOME variable2.

    NB: JAVA_HOME should be a single directory name, not "PATH-like" list of directory names separated by semicolons.

Also note that you could run into problems if you have ignored this advice in the Maven on Windows instructions about spaces in key pathnames.

"Maven, like many cross-platform tools, can encounter problems when there are space characters in important pathnames."

"You need to install the Java SDK (e.g. from Oracle's download site), and you should install it to a pathname without spaces, such as c:\j2se1.6."'

"You need to unpack the Maven distribution. Don't unpack it in the middle of your source code; pick some location (with no spaces in the path!) and unpack it there."

The simple remedy for this would be to reinstall Java or Maven in a different location so that there isn't a space in the path


1 - .... unless you have made an insane choice for the name for your installation location.

2 - Apparently a common "voodoo" solution to Windows path problems is to whack a semicolon on the end. It is not recommended in general, absolutely does not work here.

查看更多
家丑人穷心不美
3楼-- · 2020-01-27 14:29

JAVA_HOME should be like this C:\PROGRA~1\Java\jdk

Hope this will work!

查看更多
放荡不羁爱自由
4楼-- · 2020-01-27 14:31

I was facing the same issue and just updated the JAVA_HOME worked for me.

previously it was like this: C:\Program Files\Java\jdk1.6.0_45\bin Just removed the \bin and it worked for me.

查看更多
5楼-- · 2020-01-27 14:32

This seems to be old post but still I wanted to share how this issue got fixed for me.

For users, who do not have admin access and when they open a command prompt, it runs under the user privilege. It means, you may have path like C:\Users\

so when trying C:\Users\XYZ>mvn --version , it actually search the JAVA_HOME path from user variables not system variables in Environment Variables.

So, In order to fix this, we need to create a environment variable for JAVA_HOME in user variables.

Hope, this helps someone.

查看更多
迷人小祖宗
6楼-- · 2020-01-27 14:33

I had the same issue and none of the above answers fixed it for me because my env variables were all set. I had just reinstalled my Java.

What worked was to

  1. go to the C:\path\to\apache-maven-3.0.4\bin and open the mvn.bat file.
  2. Find the line that looks like this @SET JAVA_HOME=C:\progra~1\java\jdk1.7.0_03
  3. Correct it to the right path

I don't know if this is Windows specific, but it might help someone!

查看更多
Anthone
7楼-- · 2020-01-27 14:33

I am using Windows 7, the problem I had was simple:

I had this for my JAVA_HOME environment variable value:

"C:\Program Files\Java\jdk1.7.0_51;"

when it wants:

"C:\Program Files\Java\jdk1.7.0_51"

the semi-colon strikes again!

:)

This is how I solved this problem, so this should be one possible solution.

查看更多
登录 后发表回答