JAVA_HOME should point to a JDK not a JRE

JavaWindowsMavenIntellij Idea

Java Problem Overview


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

Java Solutions


Solution 1 - Java

Control Panel -> System and Security -> System -> Advanced system settings -> Advanced -> Environment Variables -> New System Variable

enter image description here

Solution 2 - Java

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.

Solution 3 - Java

do it thru cmd - > echo %JAVA_HOME% > set set JAVA_HOME=C:\Program Files\Java\jdk1.8.0 > echo %JAVA_HOME%

Solution 4 - Java

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.

Solution 5 - Java

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

Solution 6 - Java

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

Solution 7 - Java

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

Solution 8 - Java

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

Solution 9 - Java

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.

Solution 10 - Java

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

Solution 11 - Java

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.

Solution 12 - Java

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:\PROGRA1\Java\jdk1.8.0_144
also Set In Path :-%JAVA_HOME%\bin; And it Works

Solution 13 - Java

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.

Solution 14 - Java

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.

Solution 15 - Java

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%

Solution 16 - Java

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

Solution 17 - Java

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 !!!

Solution 18 - Java

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

Solution 19 - Java

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.

Solution 20 - Java

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

Solution 21 - Java

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"

Solution 22 - Java

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.

Solution 23 - Java

In my case the error started showing up as Java version got updated. So JAVA_HOME path became invalid.

Please check

  1. Location referred to in JAVA_HOME exists.
  2. If it's like my case, update the value from the old path to the new path.

(A better fix would be to set java update such that it auto upgrades the JAVA_HOME reference.)

Solution 24 - Java

Even after trying this solution from sovas which is accepted if it does not work

RESTART intellij / CMD prompt instead of trying on the existing opened

i was trying the command from terminal under intellij but still getting same problem.

Do reopen cmd / INTELLIJ and the variable will get reloaded. It fixed the problem for me (ofcourse after correcting the Path to JDK not jre and removing the bin

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbdurakhmonView Question on Stackoverflow
Solution 1 - JavasovasView Answer on Stackoverflow
Solution 2 - JavaDan MergensView Answer on Stackoverflow
Solution 3 - JavaBegineerView Answer on Stackoverflow
Solution 4 - JavaRui SunView Answer on Stackoverflow
Solution 5 - JavaZoe ZoeView Answer on Stackoverflow
Solution 6 - JavaTejashreeView Answer on Stackoverflow
Solution 7 - JavaArchmedeView Answer on Stackoverflow
Solution 8 - JavaVIKAS KESHARWANIView Answer on Stackoverflow
Solution 9 - JavaMelikaView Answer on Stackoverflow
Solution 10 - JavanitiView Answer on Stackoverflow
Solution 11 - Java黄锐铭View Answer on Stackoverflow
Solution 12 - JavaGanesh WakdeView Answer on Stackoverflow
Solution 13 - JavaAlTurView Answer on Stackoverflow
Solution 14 - JavaMatthew WooView Answer on Stackoverflow
Solution 15 - Javamanoj kalisettyView Answer on Stackoverflow
Solution 16 - JavaRahulDeep AttriView Answer on Stackoverflow
Solution 17 - JavaOlly DallyView Answer on Stackoverflow
Solution 18 - JavaGautam ShahiView Answer on Stackoverflow
Solution 19 - JavaNimesh PatelView Answer on Stackoverflow
Solution 20 - JavaSalma ElshahawyView Answer on Stackoverflow
Solution 21 - JavaFalcoView Answer on Stackoverflow
Solution 22 - JavaSentientFleshView Answer on Stackoverflow
Solution 23 - JavaDeeksha Singh ThakurView Answer on Stackoverflow
Solution 24 - JavaGaurav KhuranaView Answer on Stackoverflow