[英]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我正在尝试为我的项目设置 maven,但出现此错误
"JAVA_HOME should point to a JDK not a JRE" “JAVA_HOME 应该指向 JDK 而不是 JRE”
I know there are already similar question but it did not work.我知道已经有类似的问题,但没有用。 How can I point JAVA_HOME to JDK in windows.
如何在 Windows 中将 JAVA_HOME 指向 JDK。 I am using IntelliJ IDEA
我正在使用 IntelliJ IDEA
I am going through the same process on Mac OSX.我正在 Mac OSX 上执行相同的过程。 I installed the latest JDK, then installed Maven.
我安装了最新的JDK,然后安装了Maven。 Someone suggested I set the JAVA_HOME variable so I pointed it to the JDK installation folder.
有人建议我设置 JAVA_HOME 变量,因此我将其指向 JDK 安装文件夹。 When running Maven
mvn compile exec:java
I received the same error NB: JAVA_HOME should point to a JDK not a JRE
.当运行 Maven
mvn compile exec:java
我收到同样的错误NB: JAVA_HOME should point to a JDK not a JRE
。
All I did was unset the JAVA_HOME variable and it worked.我所做的只是取消设置 JAVA_HOME 变量并且它起作用了。
do it thru cmd -通过 cmd 来做 -
echo %JAVA_HOME% set set JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0 echo %JAVA_HOME%
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.
(Window 10环境)我通过删除用户变量中的JAVA_HOME="C:\\Program Files\\Java\\jdk1.8.0_161\\bin"而不是直接添加到系统变量中来解决它。
Then I test that editing JAVA_HOME="C:\\Program Files\\Java\\jdk1.8.0_161\\" worked too.然后我测试编辑 JAVA_HOME="C:\\Program Files\\Java\\jdk1.8.0_161\\" 也有效。 When I run "mvn -version" in command prompt window, it shows "Java home: C:\\Program Files\\Java\\jdk1.8.0_161\\jre".
当我在命令提示符窗口中运行“mvn -version”时,它显示“Java home:C:\\Program Files\\Java\\jdk1.8.0_161\\jre”。
In conclusion, I guess the JAVA_HOME shouldn't include bin directory.总之,我猜 JAVA_HOME 不应该包含 bin 目录。
I added JAVA_HOME path in user variable and omit the "/bin".我在用户变量中添加了 JAVA_HOME 路径并省略了“/bin”。 I tried every method given here but only this worked for me.
我尝试了这里给出的所有方法,但只有这对我有用。
我的JAVA_HOME
设置正确,但我通过as Administrator
运行Command Prompt
解决了这个问题
I have spent 3 hours for solving the error The JAVA_HOME
environment variable is not defined correctly.我花了3个小时解决错误
JAVA_HOME
环境变量未正确定义。 This environment variable is needed to run this program NB: JAVA_HOME
should point to a JDK not a JRE运行此程序需要此环境变量 注意:
JAVA_HOME
应指向 JDK 而不是 JRE
Finally I got the solution.最后我得到了解决方案。 Please set the
JAVA_HOME
value by Browse Directory
button/option.请通过
Browse Directory
按钮/选项设置JAVA_HOME
值。 Try to find the jdk path.尝试找到jdk路径。 Ex:
C:\\Program Files\\Java\\jdk1.8.0_181
例如:
C:\\Program Files\\Java\\jdk1.8.0_181
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-在 Mac OS 中,层次结构库 > java > JavaVirtualMachines - (在这个文件夹中有不同版本的 jdk)选择你想要的版本,在 jdk-version 文件夹中有一个内容文件夹,你会在声明 $ 时找到“Home”文件夹JAVA_HOME 你必须给那个 HOME PATH 例如-
(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- (普通shell命令)打开终端类型vi .bash_profile(打开文件名bash_profile)按“i”启用插入模式给java主路径作为-
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编辑完成后按 esc 退出编辑模式,然后 :wq 退出并保存
This will remove JAVA_HOME should point to a JDK not a JRE error and also saves you from future errors这将删除 JAVA_HOME 应该指向 JDK 而不是 JRE 错误,并且还可以避免将来出现错误
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;如果你有 JAVA_HOME 环境变量没有正确定义运行这个程序需要这个环境变量 注意:JAVA_HOME 应该指向一个 JDK 而不是 JRE 错误所以做一件事...输入 C:>dir/x 你会看到PROGRA~1 或 May ~2 和 int 环境变量更改之后 JAVA_HOME 目录像这样 JAVA_HOME:- C:\\PROGRA~1\\Java\\jdk1.8.0_144\\ 也设置在路径 :-%JAVA_HOME%\\bin; And it Works
它有效
Make sure that you do NOT have a JRE path, if you have delete it.确保您没有 JRE 路径(如果您已将其删除)。
JAVA_HOME
in the System variable.JAVA_HOME
。 Variable value: C:\\Program Files\\Java\\jdk-10.0.2
(location of JDK without bin)C:\\Program Files\\Java\\jdk-10.0.2
(没有bin的JDK的位置)M2
in the System variable.M2
。 Variable value: C:\\dev\\maven\\apache-maven-3.5.4\\bin
(location of maven with bin)C:\\dev\\maven\\apache-maven-3.5.4\\bin
(maven与bin的位置)M2_HOME
in the System variable.M2_HOME
。 Variable value: C:\\dev\\maven\\apache-maven-3.5.4
(location of maven without bin)C:\\dev\\maven\\apache-maven-3.5.4
(maven不带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.C:\\Program Files\\Java\\jdk-10.0.2
和C:\\dev\\maven\\apache-maven-3.5.4\\bin
添加%JAVA_HOME%
和%M2%
--> 对于 Windows 10,只需添加位置。 For other version, at the end of the Variable Value field add semicolon then the location Ex: ;%JAVA_HOME%;%M2%
;%JAVA_HOME%;%M2%
I did not check if the addition or removal of bin changes the result but nonetheless this works for me.我没有检查添加或删除 bin 是否会改变结果,但这对我有用。
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 .除了sovas关于如何添加
JAVA_HOME
变量的回复外,如果之前在工作并且停止工作,请确保路径仍然存在。 I updated Java recently which deleted the old version, invalidating my JAVA_HOME
environment variable.我最近更新了 Java,它删除了旧版本,使我的
JAVA_HOME
环境变量无效。
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%
This worked for me for Windows 10, Java 8_144. 这对我来说适用于 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
例如 C:\\Progra~1\\Java\\jdk1.8.0_65
Be sure to use the correct path!一定要使用正确的路径!
I mistakenly had written C:\\Program Files\\Java\\
.我错误地写了
C:\\Program Files\\Java\\
。 Changing it to C:\\Program Files\\Java\\jdk\\11.0.6\\
fixed the issue.将其更改为
C:\\Program Files\\Java\\jdk\\11.0.6\\
修复了该问题。
In cmd
I then checked for the version of maven
with mvn -version
.在
cmd
我使用mvn -version
检查了maven
的版本。
For mac OS, this worked for me... none of the above solutions对于 mac OS,这对我有用……以上解决方案都没有
$ vim .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
$ source .bash_profile
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.对于 macOS 用户,您可能有一个
~/.mavenrc
文件,这是 mvn 命令首先查找 JAVA_HOME 定义的地方。 So check there first and make sure the directory JAVA_HOME points to is correct in that file.所以首先检查那里并确保 JAVA_HOME 指向的目录在该文件中是正确的。
In IntelliJ IDEA go to File>Project Structure>SDK>JDK home path
.在 IntelliJ IDEA 中,转到
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.复制它然后转到
My Computer>Advanced Settings>Environment Variables
将JAVA_HOME路径更改为您复制的内容。 Then open new cmd, and try mvn -v
然后打开新的cmd,并尝试
mvn -v
It worked for me !!!它对我有用!!!
Add JAVA_HOME = C:\\Program Files\\Java\\jdk(version)
in User variable, it works for me.在 User 变量中添加
JAVA_HOME = C:\\Program Files\\Java\\jdk(version)
,它对我有用。 For me, it doesn't work with bin and even if I create JAVA_HOME
in system variable对我来说,它不适用于 bin,即使我在系统变量中创建
JAVA_HOME
just remove the semicolon at the end of JAVA_HOME
variable's value.只需删除
JAVA_HOME
变量值末尾的分号。
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.我有这个问题,但对于 Mac Os,我将 .bash_profile 中的 JAVA_HOME 变量设置为
export JAVA_HOME=$(/usr/libexec/java_home)
然后保存。 After that ran source ~/.bash_profile
finally mvn -version
and it fixed the issue.之后运行
source ~/.bash_profile
最后mvn -version
并解决了这个问题。 Hope that helps希望有帮助
Windows 10 Home for me:我的 Windows 10 家庭版:
I'm studying maven through a udemy course.我正在通过 udemy 课程学习 maven。 First time environment variables were ok.
第一次环境变量没问题。 I had on JAVA_HOME on SYSTEM VARIABLE like this:
我在 SYSTEM VARIABLE 上的 JAVA_HOME 是这样的:
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:尝试完上述所有操作后,我尝试删除系统变量上的 jdk 条目,并将其放在用户变量上,所以现在我有:
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:现在重新启动 CMD 我有:
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"
First, ensure that the Maven bin is in your Environmental Variable PATH entry.首先,确保 Maven bin 在您的环境变量 PATH 条目中。
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%.如果是,请确保您的条目没有出现乱序,并且 JAVA_HOME 位于列表中的 Path 之前,或者任何引用 %JAVA_HOME% 的条目之前。 I was getting the same error when I was trying to check my maven version.
当我尝试检查我的 Maven 版本时,我遇到了同样的错误。
I have a few extra path variables that reference %JAVA_HOME%, or a different version of a JDK and Maven was mixed in between.我有一些额外的路径变量引用 %JAVA_HOME%,或者中间混合了不同版本的 JDK 和 Maven。 I moved my Maven path entry below my %JAVA_HOME% one and now everything is working when I use Maven from cmd.
我将我的 Maven 路径条目移到了我的 %JAVA_HOME% 下方,现在当我从 cmd 使用 Maven 时一切正常。
But it is Windows, so perhaps my just opening and closing the Environment Variables setting somehow made everything better.但它是 Windows,所以也许我只是打开和关闭环境变量设置以某种方式使一切变得更好。
In my case the error started showing up as Java version got updated.在我的情况下,错误开始显示为 Java 版本更新。 So JAVA_HOME path became invalid.
因此 JAVA_HOME 路径无效。
Please check请检查
(A better fix would be to set java update such that it auto upgrades the JAVA_HOME reference.) (更好的解决方法是设置 java update 使其自动升级 JAVA_HOME 引用。)
假设 Java JDK 安装在 C:\\Windows\\System32 中,将此目录添加到您的Path环境变量中,它应该可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.