JAVA_HOME 应该指向 JDK 而不是 JRE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43496192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:56:02  来源:igfitidea点击:

JAVA_HOME should point to a JDK not a JRE

javamavenintellij-idea

提问by Abdurakhmon

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. I am using IntelliJ IDEA

我知道已经有类似的问题,但没有用。如何在 Windows 中将 JAVA_HOME 指向 JDK。我正在使用 IntelliJ IDEA

采纳答案by sovas

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

控制面板 -> 系统和安全 -> 系统 -> 高级系统设置 -> 高级 -> 环境变量 -> 新建系统变量

enter image description here

在此处输入图片说明

回答by Dan Mergens

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:javaI received the same error NB: JAVA_HOME should point to a JDK not a JRE.

我正在 Mac OSX 上执行相同的过程。我安装了最新的JDK,然后安装了Maven。有人建议我设置 JAVA_HOME 变量,因此我将其指向 JDK 安装文件夹。运行 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 变量并且它起作用了。

回答by Begineer

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%

回答by Ganesh Wakde

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

如果你有 JAVA_HOME 环境变量没有正确定义运行这个程序需要这个环境变量 注意:JAVA_HOME 应该指向一个 JDK 而不是 JRE 错误所以做一件事...输入 C:>dir/x 你会看到PROGRA~1 or May ~2 and After int 环境变量 Chang The JAVA_HOME Dir like this JAVA_HOME:- C:\PROGRA~1\Java\jdk1.8.0_144\ also Set In Path :-%JAVA_HOME%\bin; 它有效

回答by Olly Dally

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

在 IntelliJ IDEA 中转到File>Project Structure>SDK>JDK home path. 复制它,然后转到 My Computer>Advanced Settings>Environment Variables将 JAVA_HOME 路径更改为您复制的内容。然后打开新的cmd,然后尝试mvn -v

It worked for me !!!

它对我有用!!!

回答by Rui Sun

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. When I run "mvn -version" in command prompt window, it shows "Java home: C:\Program Files\Java\jdk1.8.0_161\jre".

然后我测试编辑 JAVA_HOME="C:\Program Files\Java\jdk1.8.0_161\" 也有效。当我在命令提示符窗口中运行“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 目录。

回答by Gautam Shahi

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_HOMEin system variable

添加JAVA_HOME = C:\Program Files\Java\jdk(version)用户变量,它对我有用。对我来说,它不适用于 bin,即使我JAVA_HOME在系统变量中创建

回答by Nimesh Patel

just remove the semicolon at the end of JAVA_HOMEvariable's value.

只需删除JAVA_HOME变量值末尾的分号。

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

It worked for me.

它对我有用。

回答by Tejashree

I have spent 3 hours for solving the error The JAVA_HOMEenvironment variable is not defined correctly. This environment variable is needed to run this program NB: JAVA_HOMEshould point to a JDK not a JRE

我花了3个小时解决错误JAVA_HOME环境变量没有正确定义。运行此程序需要此环境变量 注意:JAVA_HOME应指向 JDK 而不是 JRE

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

最后我得到了解决方案。请JAVA_HOME通过Browse Directory按钮/选项设置值。尝试找到jdk路径。前任:C:\Program Files\Java\jdk1.8.0_181

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

它将消除分号问题。:D 浏览目录选项

回答by AlTur

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

确保您没有 JRE 路径(如果您已将其删除)。

  1. Add JAVA_HOMEin the System variable. Variable value: C:\Program Files\Java\jdk-10.0.2(location of JDK without bin)
  2. Add M2in the System variable. Variable value: C:\dev\maven\apache-maven-3.5.4\bin(location of maven with bin)
  3. Add M2_HOMEin 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.2and 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%
  1. 添加JAVA_HOME系统变量。变量值:(C:\Program Files\Java\jdk-10.0.2没有bin的JDK的位置)
  2. 添加M2系统变量。变量值:C:\dev\maven\apache-maven-3.5.4\bin(maven 与 bin 的位置)
  3. 添加M2_HOME系统变量。变量值:(C:\dev\maven\apache-maven-3.5.4没有bin的maven的位置)
  4. 在路径系统变量中添加%JAVA_HOME%and%M2%C:\Program Files\Java\jdk-10.0.2and C:\dev\maven\apache-maven-3.5.4\bin--> 对于 Windows 10,只需添加位置。对于其他版本,在变量值字段的末尾添加分号,然后添加位置 Ex:;%JAVA_HOME%;%M2%

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

我没有检查添加或删除 bin 是否会改变结果,但这对我有用。