Reputation: 11617
I have googled for whole day, and tried almost all the suggested solutions, none is working for my eclipse, totally have no idea what went wrong, it kept saying "Could not find tools.jar" when I try to build via Gradle.
What I did:
1) Add Java Home (point to my JDK) in System environment variables.
2) Add the path (which contain tools.jar) in the Path
system environment variables.
3) Create a dependencies.gradle
files in project folder, to instruct Gradle to look for tools.jar (compile files("${System.properties['java.home']}/../lib/tools.jar")
)
4) Directly put the compile files("${System.properties['java.home']}/../lib/tools.jar")
in the build.gradle dependencies
there.
5) In project preferences there, go Java -> Build Path -> Classpath
Variables, add in JAVA_HOME
variable.
6) Point the project build path to JDK instead of JRE.
None of these is working! What else I could try?
PS: Eclipse version Mars 4.5.2, Gradle version 1.12
build.gradle content (this build script is generated automatically by 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'
}
}
}
The Java Home content:
Path environment variable:
C:\Program Files\Java\jdk1.7.0_67\lib
Error showing in eclipse console:
: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 too long, I shorten it.)
Upvotes: 14
Views: 24667
Reputation: 80
I'm using Eclipse 2019-09 and i fixed this problem just by forcing Eclipse not to use the Gradle wrapper in : "windows > preferences > Gradle".
In the "Local installation directory" field, you then point to "your_gradle_folder/bin".
The Gradle preferences menu differs from an Eclipse version to another i guess reading anij answer.
Upvotes: 0
Reputation: 5495
I came across this "tools.jar can't be found " issue after installing a recent java update.
Seems that Oracle doesn't bundle the tools.jar with the JRE.
To resolve - i copied the tools.jar from a previous version to the java/jren_nn/lib folder of the current JRE. then I restarted eclipse
Upvotes: 1
Reputation: 3774
This is a common problem, It happens always because eclipse has got JAVA_HOME or JDK_HOME configured to JRE location which doesn't have tools.jar and hence the issue. For this particular case: Eclipse generally uses Gradle(STS) or Buildship plugins for gradle build, since these use eclipse provided settings so your build fails.
Now considering above facts. There are couple of solutions which can work:
On the similar note, You might even hit this issue even for regular Eclipse based Java project. Again solution is same.
Upvotes: 2
Reputation: 1480
In my situation in which the OP's solution didn't work either, the answer was
Right click on gradle task in Eclipse/Gradle Tasks plugin window
Open tab 'Java Home'
Set Java home to C:\Program Files\Java\jdk1.8.0_131\jre
directory may vary depending on the jdk version
Upvotes: 2
Reputation: 89
I had the same problem. I believe it is caused by the JRE that gradle is configured to use rather than the eclipse/STS JRE. On my machine, gradle had defaulted to using the wrong JRE. When gradle is installed (even via buildship) it puts a .gradle directory in your home directory (C:/Users/username) on Windows. You can create a gradle.properties file in .gradle and specify the JRE/JDK you want gradle to use as in this example:
org.gradle.java.home=C:/Program Files/Java/jdk1.8.0
This would probably be revealed by using the command line approach recommended by robyjwilkins. It should avoid the need to re-install a JDK.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
Upvotes: 5
Reputation: 1372
Step 1: open eclipse.
Step 2: open Window -> Preferences
Step 3: go to Gradle (STS) -> Arguments
Step 4: choose proper JDK version for Java Home option. (see image below)
Upvotes: 4
Reputation: 678
My answer is that I needed to run Eclipse with the JDK bundled JRE instead of the standalone system JRE.
Modify eclipse.ini
to change the vm eclipse(.exe) finds. ie:
-vm
C:\Program Files\Java\jdk1.8.0_92\jre\bin\java.exe
Upvotes: 2
Reputation: 11617
OK, I got my problem solved finally. It is very easy, I re-installed the JDK. Somehow the stupid Eclipse (or Gradle plugin, I still not sure which goes wrong) just can't recognize my old JDK path.
After I re-installed JDK (take this chance, I upgrade JDK 7 to 8 also), I don't even need Java_home environment variable, it works.
Upvotes: 7
Reputation: 5652
I would recommend getting your build to run from the command line before trying to use the eclipse gradle build. It looks like there is a problem with your classpath, but its not clear exactly what the problem is. It would be helpful to initially remove eclipse from the mix and get the build working without eclipse. At the command line cd to the folder where the build.gradle script is stored and run
> gradle clean build
or
> ./gradlew clean build
If this works ok but the eclipse build still fails than you will know that the problem lies somewhere in your eclipse config. If building the project with gradle from the command line does not work then there is an underlying problem with you project or gradle setup. There is plenty of documentation available which will explain how to build the project with gradle from the command line.
Upvotes: 2