Gradle does not find tools.jar

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

The thing is that gradle does not accept it automatically, so I added this toolkit to my libs folder and then added it to dependencies.gradle.

Now I want to transfer it directly from my JDK home to my dependencies. Is there any way to do this? I tried the following in my .gradle dependencies:

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

But he does not find it at compilation.

+144
java build groovy gradle
Jul 05 2018-12-12T00:
source share
21 answers

Found. The system property "java.home" is not a JAVA_HOME environment variable. JAVA_HOME points to the JDK, and java.home points to the JRE. See this page for more details.

Su ... My problem was that my starting point 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 in the folder C: \ jdk1.6.0_26 \ lib). The compilation line in .gradle dependencies should be:

 compile files("${System.properties['java.home']}/../lib/tools.jar") 
+74
Jul 05 2018-12-12T00:
source share

I had this problem when I tried to run commands through the CLI.

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

You need to find where the JDK , 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 JAVA_HOME environment variable: enter image description here

And then you need to change your PATH variable to enable JAVA_HOME, i.e. %JAVA_HOME%/bin; enter image description here

Open a command prompt and execute it.

+125
Feb 25 '16 at 9:25
source share

I got the same error using Eclipse trying to complete the Gradle task. Every time I run a command (i.e. War), the process throws an exception, for example:

Could not find tools.jar. Verify that C: \ Program Files \ Java \ Jre8 "is a valid JDK installation.

I tried the solution indicated in this post, but none of them solved this problem. Here is my solution:

  • Go to the Gradle Task view>
  • Right click on the task you want to complete
  • Select Open Gradle Run Configuration
  • On the Java Home Page tab, select the local JDK repository, then click OK

Run again, enjoy!

+68
Aug 19 '16 at 13:21
source share

I added a gradle.properties file with the following contents:

 org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_45 
+43
Jun 29 '16 at 12:30
source share

I had a similar case using Ubuntu . Only JRE was installed on the machine. So, I just ran the command below to install the JDK .

sudo apt install openjdk-8-jdk

+24
Jul 27 '17 at 15:47
source share

I also fought for this decision. Found the best way to do this with Gradle, as described here . We can get JVM / JDK information from Gradle itself.

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

So simple.

+17
Mar 11 '16 at 11:44
source share

Add this to gradle.properties :

org.gradle.java.home = C: \ Program Files \ Java \ jdk1.8.0_91

+15
Aug 08 '16 at 9:25
source share

On CentOS7, the development package will install tools.jar. File is missing in java-1.8.0-openjdk

sudo yum install java-1.8.0-openjdk-devel

+12
Mar 19 '18 at 21:19
source share

It may have been two years already, but I have encountered the same problem recently, and this is the solution I encountered after I found this post :

 import javax.tools.ToolProvider dependencies { compile ( files(((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs()), ... } } 

It should work if java.home points to a directory that is not in the JDK directory, and even on Mac OS, where you will have a .jar class instead of tools.jar.

+11
Mar 02 '15 at 8:31
source share

On Windows 10, I am facing the same problem, and here is how I fixed the problem;

  1. Access Advance System Settings>Environment Variables>System Variables
  2. Select PATH to overwrite C:\ProgramData\Oracle\Java\javapath
  3. With your own jdk installation, which is JAVA_HOME = C:\Program Files\Java\jdk1.8.0_162
+8
Feb 13 '18 at 17:56
source share

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

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

This is suitable for me)!

+4
May 22 '18 at 10:04
source share

Linux

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

 JAVA_HOME="/usr/lib/jvm/open-jdk" 

Windows

  • Launch the System Control Panel applet (Start - Settings - Control Panel - System).
  • Click the Advanced tab.
  • Click on the environment Variable.
  • In the System Variables section, click the Add button, and then the following lines:

    in variable name: JAVA_HOME

    in variable value: C:\Program Files\Java\jdk1.x.x_xxx

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

  • In the System Variables section, select Path, then Edit, then click Create, and then the following line:

    %JAVA_HOME%/bin;

+3
Nov 13 '17 at 11:35
source share

With Centos 7, I found that only the JDK has tools.jar , and the JRE does not . I installed the Java 8 JRE ( yum install java-1.8.0-openjdk ), but not the JDK ( yum install java-1.8.0-openjdk-devel ).

Installing the latter solves the problem. Also, be sure to set JAVA_HOME .

+3
Aug 16 '18 at 14:46
source share

Like the other answers, I set the org.gradle.java.home property in the gradle.properties file. But the path with \ separators did not work (based on windows 10):

A Java home shipped via 'org.gradle.java.home' is not valid. Disabled Directory: C: Program FilesJavajdk1.8.0_65

So instead

org.gradle.java.home = C: \ Program Files \ Java \ jdk1.8.0_65

I had to use

org.gradle.java.home = C: / Program Files / Java / jdk1.8.0_65

then the assembly was successful

The problem is that the project is being built with the JRE instead of the JDK, and since I created it from eclipse, this also worked:

  • In the window> Settings> Gradle> Arguments define the JRE workspace and specify your JDK.
  • In the window> Preferences> Java> Installed JREs I will indicate your default JDK
+2
Sep 10 '16 at 4:48
source share

In my case (Windows 10), after updating Java, I lost the Enviroment variables, so I corrected the added variables again based on the following steps https://confluence.atlassian.com/doc/setting-the-java_home-variable-in-windows- 8895.html

+2
Apr 25 '17 at 14:19
source share

This worked for me:

I get a message

Could not complete task ': app: compileDebugJavaWithJavac'.

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

  • In Android Studio, check the location of your SDK.
  • File, project structure, SDK location, JDK location.
  • Example: C: \ android-studio \ android-studio \ jre
  • Copy the tools.jar file to the C: \ android-studio \ android-studio \ jre \ lib folder to the C: \ Program Files \ Java \ jre1.8.0_121 \ lib folder.
  • Try again.
+2
Jan 07 '18 at 2:26
source share

Did you make sure tools.jar did this on the way to compiling the class? Perhaps the path is wrong.

 task debug << { configurations.compile.each { println it } } 
+1
Jul 05 2018-12-12T00:
source share

Adding the JDK path through the JAVA_HOME tab in the "Open Gradle Run Configuration" will solve the problem.

+1
Dec 18 '17 at 3:35
source share

If you use the terminal for assembly and you have this error, you can point to jdk bundled with android studio in your gradle.properties file:

 org.gradle.java.home=/usr/local/android-studio/jre 
+1
Jun 21 '18 at 12:21
source share

I tried most of the best options, but it seems that I have something wrong with setting up the environment, so they did not help. What solved the problem for me was to reinstall jdk1.8.0_201 and jre1.8.0_201 and this solved the error for me. Hope this helps someone.

0
Feb 22 '19 at 18:17
source share

I solved the problem as follows:

0
Mar 13 '19 at 17:17
source share



All Articles