我已经用谷歌搜索了一整天,并尝试了几乎所有建议的解决方案,没有一个适用于我的 Eclipse,完全不知道出了什么问题,当我尝试通过构建时它一直说“找不到 tools.jar” Gradle 。
我做了什么:
1)在系统环境变量中添加Java Home(指向我的JDK)。
2)在Path
系统环境变量中添加路径(包含tools.jar)。
3) 在项目文件夹中创建一个dependencies.gradle
文件,指示Gradle查找tools.jar(compile files("${System.properties['java.home' ]}/../lib/tools.jar")
)
4) 直接把compile files("${System.properties['java.home']}/../lib/tools.jar")
放到build. gradle 依赖项
那里。
5) 在项目首选项中,转到 Java -> Build Path -> Classpath
变量,添加 JAVA_HOME
变量。
6) 将项目构建路径指向 JDK 而不是 JRE。
这些都不起作用!我还能尝试什么?
PS:Eclipse 版本 Mars 4.5.2,Gradle 版本 1.12
build.gradle 内容(这个构建脚本是eclipse自动生成的):
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.5
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
Java 主页内容:
路径环境变量:
C:\Program Files\Java\jdk1.7.0_67\lib
在 Eclipse 控制台中显示错误:
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not find tools.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 0.152 secs
[sts] Build failed
org.gradle.tooling.BuildException: Could not execute build using Gradle
installation 'C:\buildtools\gradle-2.12'.
Caused by: java.lang.IllegalStateException: Could not find tools.jar
(stacktrace 太长,我缩短了。)
最佳答案
好的,我的问题终于解决了。很简单,我重新安装了JDK。不知何故,愚蠢的 Eclipse(或 Gradle 插件,我仍然不确定哪个出了问题)无法识别我的旧 JDK 路径。
在我重新安装JDK后(借此机会,我也将JDK 7升级到8),我什至不需要Java_home环境变量,它可以工作。
关于java - Eclipse Gradle 构建 "Could not find tools.jar",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37669664/