Windows 10 Gradle:JAVA_HOME设置为无效目录 [英] Windows 10 Gradle: JAVA_HOME is set to an invalid directory
问题描述
我试图同时在 Git Bash 和 PowerShell 中运行./gradlew bootRun
,并出现以下错误:ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre1.8.0_121
I was trying to run ./gradlew bootRun
in both Git Bash and PowerShell, and got this error: ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre1.8.0_121
gradlew 文件位于从git克隆的项目目录中.这是 Spring官方指南的一个练习项目.还有一个 gradle.bat 文件,其内容如下:
The gradlew file is inside the project directory that cloned from git. It is a practice project from Spring official guide. There's also a gradle.bat file with these lines:
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%\bin\java.exe
我还尝试运行 Eclipse EE ,这没有问题.环境设置应该没问题.
I also tried to run Eclipse EE, which got no problem. The environment setting should be no problem.
推荐答案
看起来您的JAVA_HOME变量解析为JRE安装目录.但是当您谈论Gradle时,您肯定会尝试构建/编译代码.
Looks like your JAVA_HOME variable resolves to a JRE installation directory. But as you're talking about Gradle, you're surely trying to build/compile code.
如果已安装JDK,请更改JAVA_HOME变量以指向它.文件夹名称通常应以"jdk"开头.否则,您必须安装Java开发工具包.
If you have a JDK installed, change JAVA_HOME variable to point to it. The folder name should typically start with "jdk". Otherwise, you have to install a Java Development Kit.
您还可以尝试在命令行(SET JAVA_HOME=<path to the jdk directory>
)上运行gradle之前手动导出变量
You could also try exporting the variable manually before running gradle on the command line (SET JAVA_HOME=<path to the jdk directory>
)
这篇关于Windows 10 Gradle:JAVA_HOME设置为无效目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!