[java] JAVA_HOME should point to a JDK not a JRE

I am trying to set up maven for my project and I am getting this error

"JAVA_HOME should point to a JDK not a JRE"

I know there are already similar question but it did not work. How can I point JAVA_HOME to JDK in windows. I am using IntelliJ IDEA

This question is related to java maven intellij-idea

The answer is


Just as an addition to other answers

For macOS users, you may have a ~/.mavenrc file, and that is where mvn command looks for definition of JAVA_HOME first. So check there first and make sure the directory JAVA_HOME points to is correct in that file.


I added JAVA_HOME path in user variable and omit the "/bin". I tried every method given here but only this worked for me.


In addition to sovas' response on how to add the JAVA_HOME variable, if it was working before and stopped working, ensure that the path still exists. I updated Java recently which deleted the old version, invalidating my JAVA_HOME environment variable.


Be sure to use the correct path!

I mistakenly had written C:\Program Files\Java\. Changing it to C:\Program Files\Java\jdk\11.0.6\ fixed the issue.

In cmd I then checked for the version of maven with mvn -version.


Windows 10 Home for me:

I'm studying maven through a udemy course. First time environment variables were ok. I had on JAVA_HOME on SYSTEM VARIABLE like this:

D:\Install\Java\jdk-12.0.1;D:\Install\apache-maven-3.5.4-bin\apache-maven-3.5.4

After some days, don't know what's happened, I began to receive:

C:\Users\Franco>mvn -version

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

After trying all above, I tried to delete jdk the entry on SYSTEM VARIABLES, and putting it on USER VARIABLES, so now I have:

JAVA_HOME on USER VARIABLES: D:\Install\Java\jdk-12.0.1

JAVA_HOME on SYSTEM VARIABLES: D:\Install\apache-maven-3.5.4-bin\apache-maven-3.5.4

now restarting CMD I have:

C:\Users\Franco>mvn -version

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)

Maven home: D:\Install\apache-maven-3.5.4-bin\apache-maven-3.5.4\bin\..

Java version: 12.0.1, vendor: Oracle Corporation, runtime: D:\Install\Java\jdk-12.0.1

Default locale: en_US, platform encoding: Cp1252

OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

In Mac OS the hierarchy library > java > JavaVirtualMachines - (inside this folder there are different versions of jdk) select your desired version and inside jdk-version folder there is a contents folder inside contents you'll find "Home" folder while declaring $JAVA_HOME you haVE TO GIVE THAT HOME PATH for example-

(normal shell commands) open terminal type vi .bash_profile (to open file name bash_profile) press "i" to enable insert mode give java home path as-

export JAVA_HOME=/Library/java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home

After editing press esc to exit editing mode then :wq to quit and save

This will remove JAVA_HOME should point to a JDK not a JRE error and also saves you from future errors


do it thru cmd -

echo %JAVA_HOME% set set JAVA_HOME=C:\Program Files\Java\jdk1.8.0 echo %JAVA_HOME%


I am going through the same process on Mac OSX. I installed the latest JDK, then installed Maven. Someone suggested I set the JAVA_HOME variable so I pointed it to the JDK installation folder. When running Maven mvn compile exec:java I received the same error NB: JAVA_HOME should point to a JDK not a JRE.

All I did was unset the JAVA_HOME variable and it worked.


In IntelliJ IDEA go to File>Project Structure>SDK>JDK home path. Copy it and then go to My Computer>Advanced Settings>Environment Variables Change the JAVA_HOME path to what you have copied. Then open new cmd, and try mvn -v

It worked for me !!!


I met the same problem. (Window 10 environment) I solved it by deleting the JAVA_HOME="C:\Program Files\Java\jdk1.8.0_161\bin" in the User Variables instead of adding to the System Variables directly.

Then I test that editing JAVA_HOME="C:\Program Files\Java\jdk1.8.0_161\" worked too. When I run "mvn -version" in command prompt window, it shows "Java home: C:\Program Files\Java\jdk1.8.0_161\jre".

In conclusion, I guess the JAVA_HOME shouldn't include bin directory.


just remove the semicolon at the end of JAVA_HOME variable's value.

set JAVA_HOME as C:\Program Files\Java\jdk1.8.0_171

It worked for me.


Under System Variables add below

JAVA_HOME = C:\Program Files\Java\jdk1.8.0_201

JDK_HOME = %JAVA_HOME%\bin

M2_HOME = C:\apache-maven-3.6.0

MAVEN_BIN = %M2_HOME%\bin

MAVEN_HOME = %M2_HOME%

Under path Add these

%M2_HOME%

%JDK_HOME%

if You have 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 Error so do one thing ...type C:>dir/x and you will see the PROGRA~1 or May ~2 and After int Environment Variable Chang The JAVA_HOME Dir Like This JAVA_HOME:- C:\PROGRA~1\Java\jdk1.8.0_144\ also Set In Path :-%JAVA_HOME%\bin; And it Works


Assuming that Java JDK is installed in C:\Windows\System32, add this directory to your Path environment variable and it should work


For mac OS, this worked for me... none of the above solutions

$ vim .bash_profile

export JAVA_HOME=$(/usr/libexec/java_home)

$ source .bash_profile

Add JAVA_HOME = C:\Program Files\Java\jdk(version) in User variable, it works for me. For me, it doesn't work with bin and even if I create JAVA_HOME in system variable


I have spent 3 hours for solving the 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

Finally I got the solution. Please set the JAVA_HOME value by Browse Directory button/option. Try to find the jdk path. Ex: C:\Program Files\Java\jdk1.8.0_181

It will remove the semicolon issue. :D Browse Directory option


Make sure that you do NOT have a JRE path, if you have delete it.

  1. Add JAVA_HOME in the System variable. Variable value: C:\Program Files\Java\jdk-10.0.2 (location of JDK without bin)
  2. Add M2 in the System variable. Variable value: C:\dev\maven\apache-maven-3.5.4\bin (location of maven with bin)
  3. Add M2_HOME in the System variable. Variable value: C:\dev\maven\apache-maven-3.5.4 (location of maven without bin)
  4. Add %JAVA_HOME% and %M2% in Path System Variable or C:\Program Files\Java\jdk-10.0.2 and C:\dev\maven\apache-maven-3.5.4\bin --> For windows 10, just add the location. For other version, at the end of the Variable Value field add semicolon then the location Ex: ;%JAVA_HOME%;%M2%

I did not check if the addition or removal of bin changes the result but nonetheless this works for me.


First, ensure that the Maven bin is in your Environmental Variable PATH entry.

If it is, make sure your entries aren't somehow out of order, and that JAVA_HOME is before Path in the list, or any entry that references %JAVA_HOME%. I was getting the same error when I was trying to check my maven version.

I have a few extra path variables that reference %JAVA_HOME%, or a different version of a JDK and Maven was mixed in between. I moved my Maven path entry below my %JAVA_HOME% one and now everything is working when I use Maven from cmd.

But it is Windows, so perhaps my just opening and closing the Environment Variables setting somehow made everything better.


I had this issue but for Mac Os, I set the JAVA_HOME variable in the .bash_profile to be export JAVA_HOME=$(/usr/libexec/java_home) then save. After that ran source ~/.bash_profile finally mvn -version and it fixed the issue. Hope that helps


My JAVA_HOME was set correctly but I solved this issue by Command Prompt as Administrator


This worked for me for Windows 10, Java 8_144.

If the path contains spaces, use the shortened path name. For example, C:\Progra~1\Java\jdk1.8.0_65


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException

Examples related to intellij-idea

IntelliJ: Error:java: error: release version 5 not supported Has been compiled by a more recent version of the Java Runtime (class file version 57.0) Error: Java: invalid target release: 11 - IntelliJ IDEA IntelliJ can't recognize JavaFX 11 with OpenJDK 11 Error: JavaFX runtime components are missing, and are required to run this application with JDK 11 ERROR Source option 1.5 is no longer supported. Use 1.6 or later Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 How to configure "Shorten command line" method for whole project in IntelliJ intellij idea - Error: java: invalid source release 1.9 Failed to resolve: com.google.android.gms:play-services in IntelliJ Idea with gradle