Programing

Gradle이 tools.jar을 찾을 수 없습니다

lottogame 2020. 6. 9. 07:37
반응형

Gradle이 tools.jar을 찾을 수 없습니다


gradle과 함께 javadoc doclet을 사용하고 있기 때문에 jdk (내 경우 1.6.0_26)의 lib 폴더에있는 tools.jar 패키지를 사용해야합니다.

요점은 gradle이 자동으로 가져 가지 않으므로 해당 도구 패키지를 libs 폴더에 추가 한 다음 dependencies.gradle에 추가하는 것입니다.

이제 JDK 집에서 직접 dependencies.gradle로 가져 가고 싶습니다. 그렇게 할 수있는 방법이 있습니까? 나는 내 의존성에서 다음을 시도했다.

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

그러나 컴파일하는 동안 찾지 못합니다.


CLI를 통해 명령을 실행하려고 할 때이 문제가 발생했습니다.

JRE 폴더를 보는 시스템에 문제가있었습니다 D:\Program Files\Java\jre8\bin. 우리가 거기를 보면 Tools.jar오류 가 없으므로 오류가 발생합니다.

JDK내 경우에는 위치를 찾아야 D:\Program Files\Java\jdk1.8.0_11합니다. lib디렉토리를 보면을 볼 수 Tools.jar있습니다.

내가 한 일은 새로운 환경 변수를 만들었습니다 JAVA_HOME.여기에 이미지 설명을 입력하십시오

그런 다음 JAVA_HOME을 포함하도록 PATH 변수를 편집해야합니다. %JAVA_HOME%/bin; 여기에 이미지 설명을 입력하십시오

명령 프롬프트를 다시 열고 실행해야합니다.


그것을 발견. 시스템 특성 'java.home'은 JAVA_HOME 환경 변수가 아닙니다. JAVA_HOME은 JDK를 가리키고 java.home은 JRE를 가리 킵니다. 자세한 내용은 해당 페이지 를 참조하십시오.

Soo ... 내 문제는 내 시작점이 jre 폴더 (C : \ jdk1.6.0_26 \ jre)이고 jdk 폴더 (C : \ jdk1.6.0_26)가 아니라고 생각했다. : \ jdk1.6.0_26 \ lib 폴더). dependencies.gradle의 컴파일 라인은 다음과 같아야합니다.

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

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 just added a gradle.properties file with the following content:

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

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


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.


Add this to gradle.properties:

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


In CentOS7 the development package will install tools.jar. The file is not present in java-1.8.0-openjdk

sudo yum install java-1.8.0-openjdk-devel


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:

import javax.tools.ToolProvider

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.


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

With Centos 7, I have found that only JDK has tools.jar, while JRE has not. I have 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, remember to set JAVA_HOME.


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)!


Linux

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

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

Windows

  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:

    %JAVA_HOME%/bin;


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.

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

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

So instead of

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 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

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


If you use terminal to build 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

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 }
}

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


I solved problem on this way:


나는 최고의 옵션을 대부분 시도했지만 환경 설정에 문제가있어 도움이되지 않은 것 같습니다. 무엇 나를 위해 문제를 해결하는 것이었다 다시 설치 jdk1.8.0_201 하고 jre1.8.0_201이 나를 위해 오류를 해결했다. 누군가에게 도움이되기를 바랍니다.

참고 URL : https://stackoverflow.com/questions/11345193/gradle-does-not-find-tools-jar

반응형