找不到 tools.jar。请检查 C:\Program Files\Java\jre1.8.0_151 是否包含有效的 JDK 安装
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47291056/
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
Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_151 contains a valid JDK installation
提问by viswesvar sekar
Even though I manually configured JDK project structure file/Project structureit still shows this error FAILURE: Build failed with an exception.
即使我手动配置了 JDK 项目结构文件/项目结构,它仍然显示此错误 FAILURE: Build failed with an exception。
`What went wrong: Execution failed for task ':sample:compileReleaseJavaWithJavac'.
`出了什么问题:任务 ':sample:compileReleaseJavaWithJavac' 执行失败。
Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_151 contains a valid JDK installation.`
找不到 tools.jar。请检查 C:\Program Files\Java\jre1.8.0_151 是否包含有效的 JDK 安装。`
I'm confused why it is still looking for C:\Program Files\Java\jre1.8.0_151 instead of JDK
我很困惑为什么它仍在寻找 C:\Program Files\Java\jre1.8.0_151 而不是 JDK
回答by viswesvar sekar
At last, here I found the solution.
最后,我在这里找到了解决方案。
I added jdk path org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144
to gradle.properties
file and did a rebuild. It works now.
我将 jdk 路径添加org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144
到gradle.properties
文件并进行了重建。它现在有效。
回答by Ton Snoei
I had the same problem and fixed it like this:
我遇到了同样的问题并像这样修复它:
- Install the JDK from the Oracle website with the same version number as the JRE if you didn't already.
- Furthermore add JAVA_HOME to the environment variables of Windows.
- Restart your terminal or development environment to load the new JAVA_HOME value.
- 如果您还没有安装与 JRE 版本号相同的版本号,请从 Oracle 网站安装 JDK。
- 此外,将 JAVA_HOME 添加到 Windows 的环境变量中。
- 重新启动您的终端或开发环境以加载新的 JAVA_HOME 值。
回答by romin21
What I did was I uninstalled Java from my PC, and then downloaded and installed JDK again from Oracle. After this it worked perfectly. I think the problem was because the JRE and JDK update version were different from each other.
我所做的是从我的 PC 上卸载 Java,然后再次从 Oracle 下载并安装 JDK。在此之后,它完美地工作。我认为问题是因为 JRE 和 JDK 更新版本彼此不同。
回答by Marco Aurélio
Just had this happen to me.
刚好发生在我身上。
Apparently Java's automatic updater installed and configured a new version of the JRE for me, while leaving the old JDK intact. So even though I did have a JDK, it didn't match the currently "active" JRE, which was causing the error.
显然,Java 的自动更新程序为我安装并配置了新版本的 JRE,同时保留了旧的 JDK。因此,即使我确实有 JDK,它也与导致错误的当前“活动”JRE 不匹配。
Download a matching versionof the JDKto the JRE you currently have installed,(In OP's case 151) That should do the trick.
将匹配版本的 JDK下载到您当前安装的 JRE,(在 OP 的情况下为 151)这应该可以解决问题。
回答by Anup Singh
ERROR: Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_121 contains a valid JDK installation
Copy tools.jarfrom C:\Program Files\Java\jdk1.8.0_121\lib
to C:\Program Files\Java\jre1.8\lib
.
将tools.jar从复制C:\Program Files\Java\jdk1.8.0_121\lib
到C:\Program Files\Java\jre1.8\lib
。
It's resolved the problem now.
现在已经解决了这个问题。
回答by vishal jangid
Please make sure both JDK and jre are on same version for example if you have JRE version 1.8.0_201then JDK version should be 1.8.0_201version.
请确保 JDK 和 jre 的版本相同,例如,如果您的 JRE 版本为1.8.0_201,则 JDK 版本应为 1.8.0_201版本。
回答by matb
for tools.jar is in C:\Program Files\Java\jdk1.8.0_201\lib. I changed installed jre in eclipse. Windows->Preferences->Java->installed JREs and make default jre to point to where your jdk is.
tools.jar 在 C:\Program Files\Java\jdk1.8.0_201\lib 中。我在 Eclipse 中更改了已安装的 jre。Windows->Preferences->Java->installed JREs 并使默认 jre 指向您的 jdk 所在的位置。
回答by sunny prakash
This happens when JDK and JRE have different versions installed on your system. Update the JDK with the matching version of JRE. Also verify that System variable path has bin value from same JDK version.
当 JDK 和 JRE 在您的系统上安装了不同的版本时,就会发生这种情况。使用匹配版本的 JRE 更新 JDK。还要验证系统变量路径是否具有来自相同 JDK 版本的 bin 值。
回答by cblanto7
This can occur if your path is too long as well. I solved this by moving my java install to
如果您的路径太长,也会发生这种情况。我通过将我的 java 安装移动到
C:\Java\jdk1.8.0_211
C:\Java\jdk1.8.0_211
回答by Michael Almpertis
What worked for me was updating Android Studio and updating JAVA_HOME and ANDROID_HOME environment variables. I believe it was caused due to the fact that I updated Java Version (through updater) but did not update jdk.
对我有用的是更新 Android Studio 并更新 JAVA_HOME 和 ANDROID_HOME 环境变量。我相信这是因为我更新了 Java 版本(通过更新程序)但没有更新 jdk。