How do I fix maven error The JAVA_HOME environment variable is not defined correctly?
My JDK is installed at C:\Program Files\Java\jdk1.8.0_144\
.
I had set JAVA_HOME= C:\Program Files\Java\jdk1.8.0_144\
,
and I was getting this error:
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
When I changed the JAVA_HOME
to C:\Program Files\Java\jdk1.8.0_144\jre
, the issue got fixed.
I am not sure how.
Following is the best way to get of the issue , check following on classpath:
Make sure JAVA_HOME system variable must have till jdk e.g
C:\Program Files\Java\jdk1.7.0_80
, don't append bin here.Because MAVEN will look for jre which is under
C:\Program Files\Java\jdk1.7.0_80
Set
%JAVA_HOME%\bin
in classpath .
Then try Maven version .
Hope it will help .
This is how I fixed this issue on Windows 10:
My JDK is located in C:\Program Files\Java\jdk-11.0.2
and the problem I had was the space in Program Files
. If I set JAVA_HOME using set JAVA_HOME="C:\Program Files\Java\jdk-11.0.2"
then Maven had an issue with the double quotes:
C:\Users>set JAVA_HOME="C:\Program Files\Java\jdk-11.0.2"
C:\Users>echo %JAVA_HOME%
"C:\Program Files\Java\jdk-11.0.2"
C:\Users>mvn -version
Files\Java\jdk-11.0.2""=="" was unexpected at this time.
Referring to Program Files
as PROGRA~1
didn't help either. The solution is using the PROGRAMFILES variable inside of JAVA_HOME:
C:\Users>echo %PROGRAMFILES%
C:\Program Files
C:\Program Files>set JAVA_HOME=%PROGRAMFILES%\Java\jdk-11.0.2
C:\Program Files>echo %JAVA_HOME%
C:\Program Files\Java\jdk-11.0.2
C:\Program Files>mvn -version
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T17:06:16+02:00)
Maven home: C:\apache-maven-3.6.2\bin\..
Java version: 11.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"