我已经谷歌搜索了一整天,尝试了几乎所有建议的解决方案,但没有任何一个适用于我的Eclipse,完全不知道出了什么问题,当我尝试通过Gradle进行构建时,它一直报错“找不到tools.jar”。
我做了以下尝试:
1)在系统环境变量中添加Java Home(指向我的JDK)。
2)将包含tools.jar的路径添加到“Path”系统环境变量中。
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 dependencies
中。
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 Home内容:
路径环境变量:
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
(堆栈跟踪太长,我将其缩短。)
tools.jar
在lib
文件夹中,并不在bin
文件夹中。 - Sam YC