java groovy - Gradle does not find tools.jar

compile before (17)

I got the same error using Eclipse trying to execute a Gradle Task. Every time I run a command (i.e. war) the process threw an exception like:

Could not find tools.jar. Please check that C:\Program Files\Java\Jre8" is a valid JDK install.

I tried the solution listed in this post but none of them solved this issue. Here my solution :

  1. Go to the "Gradle Task" view
  2. Right Click on the task you want to execute
  3. Select Open Gradle Run Configuration
  4. In the tab "Java Home" select your local JDK repository then click OK

Run again, Enjoy!

I am using javadoc doclets with gradle, so I need to use the package tools.jar, which is in the lib folder from the jdk (1.6.0_26 in my case).

The point is that gradle does not take it automatically, so I was adding that tools package to my libs folder, and then adding it to dependencies.gradle .

Now I want to take it directly from my JDK home into my dependencies.gradle. Is there a way to do that? I have tried the next in my dependencies.gradle:

compile files("${['java.home']}/lib/tools.jar")

But it does not find it while compiling.

On windows 10, I encounter the same problem and this how I fixed the issue;

  1. Access Advance System Settings>Environment Variables>System Variables
  2. Select PATH overwrite the default C:\ProgramData\Oracle\Java\javapath
  3. With your own jdk installation that is JAVA_HOME=C:\Program Files\Java\jdk1.8.0_162

I had this problem when I was trying to run commands through CLI.

It was a problem with system looking at the JRE folder i.e. D:\Program Files\Java\jre8\bin. If we look in there, there is no Tools.jar, hence the error.

You need to find where the JDK is, in my case: D:\Program Files\Java\jdk1.8.0_11, and if you look in the lib directory, you will see Tools.jar.

What I did I created a new environment variable JAVA_HOME:

And then you need to edit your PATH variable to include JAVA_HOME, i.e. %JAVA_HOME%/bin;

Re-open command prompt and should run.

Found it. System property 'java.home' is not JAVA_HOME environment variable. JAVA_HOME points to the JDK, while java.home points to the JRE. See that page for more info.

Soo... My problem was that my startpoint was the jre folder (C:\jdk1.6.0_26\jre) and not the jdk folder (C:\jdk1.6.0_26) as I thought(tools.jar is on the C:\jdk1.6.0_26\lib folder ). The compile line in dependencies.gradle should be:

compile files("${['java.home']}/../lib/tools.jar")

I just added a file with the following content:\\Program Files\\Java\\jdk1.8.0_45

I was struggling as well for this Solution. Found a better way to it with Gradle as described here. We can get the JVM/JDK information from Gradle itself.

dependencies {
   runtime files(org.gradle.internal.jvm.Jvm.current().toolsJar)

So simple.

It may be two years too late, but I ran into the same problem recently and this is the solution I ended up with after finding this post:


dependencies {
  compile (
    files(((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs()),

It should work if java.home points to a directory that's not under the JDK directory and even on Mac OS where you'd have classes.jar instead of tools.jar.

I had a similar case using Ubuntu. The machine had only the JRE installed. So, I just executed the command below to install the JDK.

sudo apt install openjdk-8-jdk

On my system (Win 10, JRE 1.8.0, Android Studio 3.1.2, Gradle 4.1) there is no tools.jar in the JRE directory (C:\Program Files\Java\jre1.8.0_171).

However, I found it in C:\Program Files\Android\Android Studio\jre\lib and tried setting JAVA_HOME=C:\Program Files\Android\Android Studio\jre

That works (for me)!

This worked for me:

I was getting message

Execution failed for task ':app:compileDebugJavaWithJavac'.

Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_121 contains a valid JDK installation.

  • In Android Studio, check your SDK Location.
  • File, Project Structure, SDK Location, JDK Location.
  • Example: C:\android-studio\android-studio\jre
  • Copy the tools.jar file in the C:\android-studio\android-studio\jre\lib folder into the C:\Program Files\Java\jre1.8.0_121\lib folder.
  • Retry.

If you use terminal to build and you have this error you can point to jdk bundled with android studio in your file:

Add this to\Program Files\Java\jdk1.8.0_91


Open /etc/environment in any text editor like nano or gedit and add the following line:



  1. Start the System Control Panel applet (Start - Settings - Control Panel - System).
  2. Select the Advanced tab.
  3. Click the Environment Variables button.
  4. Under System Variables, click add button, then past the following lines:

    in Variable Name : JAVA_HOME

    in Variable Value : C:\Program Files\Java\jdk1.x.x_xxx

    where x.x_xxx jdk version you can get your jdk version from here C:\Program Files\Java

  5. Under System Variables, select Path, then click Edit,then click new button then past the following line:


Did you make sure that tools.jar made it on the compile class path? Maybe the path is incorrect.

task debug << {
    configurations.compile.each { println it }

Like other answers I set property in file. But path with \ separators did not work (building on windows 10):

Java home supplied via '' is invalid. Invalid directory: C:Program FilesJavajdk1.8.0_65

So instead of\Program Files\Java\jdk1.8.0_65

i had to use Files/Java/jdk1.8.0_65

then the build was successful

Problem is that project is build with JRE instead of JDK and since I was building it from eclipse this also worked:

  • In Window>Preferences>Gradle>Arguments specify Workspace JRE and specify your JDK.
  • In Window>Preferences>Java>InstalledJREs specify your JDK as default

It's the new build tool that Google wants to use for Android. It's being used due to it being more extensible, and useful than ant. It is meant to enhance developer experience.

You can view a talk by Xavier Ducrohet from the Android Developer Team on Google I/O here.

There is also another talk on Android Studio by Xavier and Tor Norbye, also during Google I/O here.

java gradle groovy build