JAVA_HOME pointing to JRE not JDK [duplicate] - java

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

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

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.

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

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.

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

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

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

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

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

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.

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.

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

Make sure that you do NOT have a JRE path, if you have delete it.
Add JAVA_HOME in the System variable. Variable value: C:\Program Files\Java\jdk-10.0.2 (location of JDK without bin)
Add M2 in the System variable. Variable value: C:\dev\maven\apache-maven-3.5.4\bin (location of maven with bin)
Add M2_HOME in the System variable. Variable value: C:\dev\maven\apache-maven-3.5.4 (location of maven without bin)
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.

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.

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

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%

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

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

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

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.

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

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.

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 my case the error started showing up as Java version got updated. So JAVA_HOME path became invalid.
Please check
Location referred to in JAVA_HOME exists.
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.)

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

Related

I cannot know where VScode find JAVA_HOME environment variable

enter image description here
I installed and uninstalled jdk-14 and install jdk-13
But vscode recognize JAVA_HOME environment variable as "jdk 14" and this is non-existing path.
Also, I set the JAVA_HOME as jdk-13 path and write to .zshrc too.
Although reloading and restarting vscode, vscode still recognize JAVA_HOME as jdk-14 path.
Where vscode find $JAVA_HOME variable?? There is never my terminal.
File -> Preferences -> Settings
Here search for JAVA_HOME. You should see the below option.
Now search for java.home and you will see the value that VSCode has set already
Hope this helps.
From the picture you have given out. you have set the jdk path for extension correctly, but you really set the 'JAVA_HOME' system environment as 'jdk 14'.
Could you please tell me the meaning of 'vscode recognize JAVA_HOME environment variable as "jdk 14"'? How do you get 'JAVA_HOME' variable?
The 'java.home' was set for the extensions:This JDK will be used to launch the Java Language Server. And by default, the 'java.home' will be used to compile your projects. from:here.
and it really has no relationship to "JAVA_HOME" at all.

Error when starting Liferay 7 (liferay-portal-7.0-ce-ga1): PWC6345: There is an error in invoking javac.A full JDK (not just JRE) is required

I am getting the following error when starting Liferay (liferay-portal-7.0-ce-ga1):
org.apache.jasper.JasperException: PWC6345: There is an error in
invoking javac. A full JDK (not just JRE) is required
I have set my system environment variables correctly:
JAVA_HOME: C:\Program Files\Java\jdk1.7.0_80
JRE_HOME: C:\Program Files\Java\jre7
I have added my JAVA_HOME path to my system Path variable:
....;C:\Program Files\Java\jdk1.7.0_80\bin;
When I run the windows where javac command, I get the following:
C:\Program Files\Java\jdk1.7.0_80\bin\javac.exe
What am I missing?? I have also tried using JDK 1.8 and JDK 1.7.0_79. Same results.
Thanks for your help!
After a lot of trial and error, and a lot of searching and several Windows Environment Setting Changes, I resolved this issue. I will point to the last 2 locations that led me to get over the finish-line because I had done some many things.
1) I made sure my JAVA_HOME pointed to my Java JDK (1.8.0_xx) and my JRE_HOME pointed to my Java JRE (1.8.0_xx)
2) I removed the C:\ProgramData\Oracle\Java\javapath; from my PATH variables (there were 2 PATH variables, removed from both)
3) Made sure my PATH variables (both) at the JDK Bin folder path: C:\Program Files\Java\jdk1.8.0_65\bin;
Then I checked my CMD 'where java' and received the correct response:
C:\Program Files\Java\jdk1.8.0_65\bin\java.exe
4) In Eclipse, under the top menu: Windows > Preferences > Java > Installed JREs
Here, I originally had the jre1.8.0_65, but I added the jdk1.8.0_65 and selected it.
5) Finally, what seemed to make the biggest difference:
Right-Click on your server, and at the bottom, select Properties.
A window will open up, and the 3rd option, there's clickable text "Runtime Environment". Click it and a popup will open, there will be a bottom drop-down under "Select runtime JRE" Here, I selected jdk1.8.0_65
That finally corrected the issue for me. Here are 2 links in reverse order.
http://www.huqiwen.com/2016/05/11/liferay-7-there-is-an-error-in-invoking-javac/
https://web.liferay.com/community/forums/-/message_boards/message/74821940?_19_threadView=tree
In your environment both JRE_HOME and JAVA_HOME are set. In this case Tomcat will prefer the JRE_HOME over the JAVA_HOME. JRE_HOME should point to a JRE while JAVA_HOME should point to a JDK.
You could just delete the JRE_HOME environment variable and Tomcat would automatically switch to JAVA_HOME so the isseue would be solved. If you want to keep the JRE_HOME in Windows you can change the setenv.bat by adding the following line as a first line.
set "JRE_HOME=%JAVA_HOME%"
This change will tell Tomcat that the JRE_HOME should be considered equal to JAVA_HOME and will not change your environmental variables.

How to set environment variable for ant

I am trying to build my first android app using phonegap and for that i need jdk environment,node.js,ant.
And I am able to install jdk but for Apache ant I have tried many forum and tutorials for setting the path but not able to succeeded on this.
I set my varialbe like this....
Variable Name :- ANT_HOME
Variable Value:- C:\JAVA\ant\bin
Variable Name :- JAVA_HOME
Variable Value:- C:\Program Files\Java\jdk1.7.0_60\jre\bin\
But still i am getting "unalbe to locate tools.jar. Expected to find in C:\ProgramFiles\java\jre7\lib\tools.jar
BuildFile: build.xml doest not exists.
Build Failed.
PLEASE HELP ME OUT FROM THIS ANONYMOUS TROUBLES..
See HERE for Ant, jdk, tools.jar related instructions.
for Ant:
ANT_HOME set to C:\JAVA\ant and add ;%ANT_HOME%\bin to the PATH variable
for JDK:
JAVA_HOME set to "C:\Program Files\Java\jdk1.7.0_60\" (with the quotes if you have space(s) in your file path) and add ;%JAVA_HOME%\bin to your PATH variable.
close any command-prompt window(s) that were open prior to the changes above. Only command windows opened after the changes will have the updated environment variables.
JAVA_HOME should be the JDK installation directory (in your case C:\Program Files\Java\jdk1.7.0_60\. Then you add %JAVA_HOME%\bin to the path.
For java, see Update the PATH Environment Variable (Microsoft Windows).
You can follow a similar procedure to add ANT_HOME to your path. ANT_HOME should be C:\JAVA\ant and then you add %ANT_HOME%\bin to the path.
If echo %PATH% shows the correct values for both ant and java then you need to check your Cordova configuration as it appears your configuration is pointing to a Java Runtime Environment (JRE) instead of a Java Development Kit (JDK).
This can be done in 2 different ways:
1: From Command Prompt.
C:>set ANT_HOME=C:\Program Files\Ant Files\apache-ant-1.10.5
C:>set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181
C:>set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin
C:> ant -version
Apache Ant(TM) version 1.10.5 compiled on July 10 2018
2: By setting environment variables.
Right click on This PC > Properties > Advanced system settings > Environment Variables > User variables > New > Variable name:**ANT_HOME & for **Variable value:**C:\Program Files\Ant Files\apache-ant-1.10.5 > **OK.
Now goto System variables to add bin path. System variables > double click on Path >New > C:\Program Files\Ant Files\apache-ant-1.10.5\bin >New >C:\Program Files\Java\jdk1.8.0_181\bin>OK.
Now lets check whether it is installed correctly or not.
goto Command Prompt > and type ant -version.
C:> ant -version
Apache Ant(TM) version 1.10.5 compiled on July 10 2018
That's it. Let me know if still getting any difficulties.

Error in setting JAVA_HOME

I have recently downloaded Maven and followed the instructions given on this this page. I already have ant installed on my machine.
Now, if I want to verify that Maven is installed perfectly or not it is giving me error that JAVA_HOME is not set correctly, but same works perfectly fine for ANT.
For Maven I tried :
1. open cmd
2. type mvn -version
3. Error appeared :
C:\Users\Admin>mvn -version
ERROR: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jre7\bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation
For ANT I tried and worked :
1. open cmd
2. type mvn -version
3. Apache Ant(TM) version 1.9.1 compiled on May 15 2013
I went to the directory to check that java.exe is actually there in that directory or not and it was there. I checked the environment variables they set fine. I restarted the system and checked again but same problem. Please let me know what am I missing.
JAVA_HOME should point to jdk directory and not to jre directory. Also JAVA_HOME should point to the home jdk directory and not to jdk/bin directory.
Assuming that you have JDK installed in your program files directory then you need to set the JAVA_HOME like this:
JAVA_HOME="C:\Program Files\Java\jdkxxx"
xxx is the jdk version
Follow this link to learn more about setting JAVA_HOME:
http://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/index.html
Do not include bin in your JAVA_HOME env variable
Follow the instruction in here.
JAVA_HOMEshould be like this
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_07
JAVA_HOME = C:\Program Files\Java\jdk(JDK version number)
Example: C:\Program Files\Java\jdk-10
And then restart you command prompt it works.
Just remember to add quotes into the path if you have a space in your path to java home.
C:\Program Files\java\javaxxx\ doesn't work
but
"C:\Program Files\java\javaxxx\" does.
The JAVA_HOME should point to the JDK home rather than the JRE home if you are going to be compiling stuff, likewise - I would try and install the JDK in a directory that doesn't include a space. Even if this is not your problem now, it can cause problems in the future!
You are pointing your JAVA_HOME to the JRE which is the Java Runtime Environment. The runtime environment doesn't have a java compiler in its bin folder.
You should download the JDK which is the Java Development Kit. Once you've installed that, you can see in your bin folder that there's a file called javac.exe. That's your compiler.
JAVA_HOME should point to jdk directory like in the image with new variable, like below
PATH should point to jdk bin like below
Run the below command in your terminal and restart it.
> set JAVA_HOME="C:\Program Files\Java\jdk-xx.xx"
xx.xx is the java version

How to locate my java jdk folder and edit the path variable - integration maven

i have Windows Vista and i'm trying to install maven and test it.
But i realised that i have a problem with JAVA and i have to solve first.
I do Start->Run->cmd
and i type in the command line,
C:\>mvn clean
i get the following error
ERROR: JAVA_HOME not found in your environment.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation
So i say: Let's set the PATH for Java and i did:
Start->Control Panel->System->Advanced System Settings->Environment Variable->System Variables
Edit the PATH variable
C:\Program Files\Java\jdk1.6.0_32;C:\apache-maven-3.0.4\bin;
But then i get the same error when i do:
C:\>mvn clean
Then i typed in the cmd prompt:
C:\>java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b11)
and i realise that the Java version that is running is not located under the
"C:\Program Files\Java" directory
The only JDKs i have are:
jdk1.6.0_29
jdk1.6.0_32
Then i did Run->cmd
C:\>where java
C:\Windows\System32\java.exe
(Recently i downloaded IDE Eclipse and IDE IntelliJ and i don't know if these apps
come with the JDK).
Where can i find my JDK installation in Windows and set the path in environmental variables?
Go to
Start->Control Panel->System->Advanced System Settings->Environment Variable->user variables
Click on new button
give the
variable name : JAVA_HOME
variable value: C:\Program Files\Java\jdk1.6.0_32
in that way you setup your java home and try
Also make sure to take new command prompt after you did any changes in environment variables
Eclipse comes bundled with a JDK, I believe you need a seperate one to run maven.
My environment variables look like this.
JAVA_HOME = C:\Program Files\Java\jdk1.6.0_33
Path = (tacked on the end) ;%JAVA_HOME%\bin;C:\Program Files\Spring Tools Suite\apache-maven-3.0.3\bin
This is all working but as you can see I got maven by installing STS. It's just an eclipse distro which comes bundled with maven (among other things).
You can also set java home from command line prompt. But this will be valid only in your session and it will be gone once you close your command line session.
Hope it helps.
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_33
Late to the game, but run this in an elevated command prompt:
setx /M JAVA_HOME "path_to_Java"
This will set the path for your machine and not the user. Remove /M to have it set just for the user account.
The guide at SS64 (and setx /?) say you're supposed to have the /M switch at the end, but my personal experience is that it doesn't always work at the end.

Categories