Windows 10 Gradle: JAVA_HOME is set to an invalid directory

ε祈祈猫儿з 提交于 2020-03-01 21:02:52

问题


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

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 

I also tried to run Eclipse EE, which got no problem. The environment setting should be no problem.


回答1:


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.

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.

You could also try exporting the variable manually before running gradle on the command line (SET JAVA_HOME=<path to the jdk directory>)




回答2:


In addition to Ernest's answer, the JAVA_HOME it wants is the actual directory, not the bin folder like the path wants for javac. Took me a while to work that out



来源:https://stackoverflow.com/questions/44081972/windows-10-gradle-java-home-is-set-to-an-invalid-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!