Reputation: 3070
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
Upvotes: 116
Views: 289307
Reputation: 1076
In case you have the same error on Win10 and OpenJDK. The cause of my issue is that the OpenJDK installation set the JAVA_HOME variable for me, but set it pointing to a wrong path:
When I manually edited this environment variable, the path was pointing to:
• C:\Program Files\Eclipse Foundation\jdk-16.0.2.7-hotspot (Wrong)
Instead I changed it to:
C:\Program Files\Eclipse Adoptium\jdk-17.0.2.8-hotspot (Correct)
Upvotes: 0
Reputation: 2307
you should only add this path to Manage Jenkins -> Global Tool Configuration -> JDK
for java 11
/usr/lib/jvm/java-11-openjdk-amd64
for java 8
/usr/lib/jvm/java-8-openjdk-amd64
And then use same in your jenkins jobs accordingly
Upvotes: 1
Reputation: 3901
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
Upvotes: 1
Reputation: 41
In my case the error started showing up as Java version got updated. So JAVA_HOME path became invalid.
Please check
(A better fix would be to set java update such that it auto upgrades the JAVA_HOME reference.)
Upvotes: 0
Reputation: 1842
My JAVA_HOME
was set correctly but I solved this issue by running Command Prompt
as Administrator
Upvotes: 5
Reputation: 331
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.
Upvotes: 3
Reputation: 129
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
Upvotes: 4
Reputation: 31
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
.
Upvotes: 3
Reputation: 1598
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"
Upvotes: 0
Reputation: 11
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%
Upvotes: 1
Reputation: 41
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
Upvotes: 4
Reputation: 617
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.
Upvotes: 0
Reputation: 418
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
Upvotes: 1
Reputation: 91
I added JAVA_HOME path in user variable and omit the "/bin". I tried every method given here but only this worked for me.
Upvotes: 9
Reputation: 1190
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
Upvotes: 0
Reputation: 1378
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.
Upvotes: 1
Reputation: 11
Make sure that you do NOT have a JRE path, if you have delete it.
JAVA_HOME
in the System variable. Variable value: C:\Program Files\Java\jdk-10.0.2
(location of JDK without bin)M2
in the System variable. Variable value: C:\dev\maven\apache-maven-3.5.4\bin
(location of maven with bin)M2_HOME
in the System variable. Variable value: C:\dev\maven\apache-maven-3.5.4
(location of maven without bin)%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.
Upvotes: 1
Reputation: 810
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
Upvotes: 6
Reputation: 1578
Control Panel -> System and Security -> System -> Advanced system settings -> Advanced -> Environment Variables -> New System Variable
Upvotes: 96
Reputation: 1
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.
Upvotes: 0
Reputation: 455
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
Upvotes: 0
Reputation: 111
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.
Upvotes: 11
Reputation: 1
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 !!!
Upvotes: 0
Reputation: 11
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
Upvotes: 1
Reputation: 181
do it thru cmd -
echo %JAVA_HOME% set set JAVA_HOME=C:\Program Files\Java\jdk1.8.0 echo %JAVA_HOME%
Upvotes: 9
Reputation: 589
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.
Upvotes: 49