【发布时间】:2016-06-07 02:41:40
【问题描述】:
我已经搜索了一整天,并尝试了几乎所有建议的解决方案,没有一个适用于我的 Eclipse,完全不知道出了什么问题,当我尝试通过构建时它一直说“找不到 tools.jar”摇篮。
我做了什么:
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 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 主页内容:
路径环境变量:
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 的确切位置,以及 JAVA_HOME 的设置。删除“tools.jar”的依赖项。你不需要那个。显示您的整个构建脚本和构建结果。
-
@DavidM.Karr 感谢您的建议,我已经更新了问题,
-
路径必须到 bin,而不是 lib。
-
@DavidM.Karr 我已经尝试过了,仍然是同样的错误。无论如何,
tools.jar在lib文件夹中,而不是在bin文件夹中。