Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to install Maven on Windows: "JAVA_HOME is set to an invalid directory"

Tags:

java

maven-2

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?

like image 620
hello_world_infinity Avatar asked Jul 26 '09 08:07

hello_world_infinity


People also ask

What directory should JAVA_HOME be set to?

Traditionally, JAVA_HOME is set to the JRE or SDK main directory.

How do you fix please set the JAVA_HOME variable in your environment to match the location of your Java installation?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.

Is JAVA_HOME necessary for Maven?

How does Maven verify the JAVA_HOME path? Before running any goals, Maven checks for the existence of the java command in the path specified by JAVA_HOME or by asking the OS for a default JDK installation. If the executable is not found, Maven terminates with the error.


2 Answers

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.

like image 173
Stephen C Avatar answered Sep 28 '22 07:09

Stephen C


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

JAVA_HOME should be set to E:\Sun\SDK\jdk. PATH should be set to include %JAVA_HOME%\bin.

like image 39
dfa Avatar answered Sep 28 '22 07:09

dfa