Gradle not finding java tools.jar


(john kunchandy) #1

I installed Gradle 2.7 in my C:\ directory for Windows 7.
Created a gradle.properties file in the Gradle directory containing the following:
org.gradle.java.home = “c:\Program Files\Java\jdk1.7.0_03”

Include the following the in gradle build file: apply plugin: “java”

When I run “gradle assemble” from the directory containing the build file, I get the following:
> Execution failed for task ‘:compileJava’.
> Could not find tools.jar

I confirmed that the tools.jar file is in the jdk1.7.0.0_03/lib directory.

When i run “gradle tasks” I dont get any extra tasks that should be available with the java plugin.
I would appreciate any suggestions regarding what else I can do to get the gradle build to recognize the tools.jar file?


(davidmichaelkarr) #2

You might try changing that value to “c:/Program Files/Java/jdk1.7.0_03”.


(john kunchandy) #3

Almost a good catch! But changing forward slash still gives error “Could not find tools.jar.”


(Sterling Greene) #4

Don’t use quotes around the path, see How to change JAVA_HOME using gradle.proeprties?


(john kunchandy) #5

Ok, not sure what to make of it. I tried leaving out the quotes but get same error.
I seem to be following the info in the suggested thread.
I don’t have an environment variable set for JAVA_HOME, but would think this is unnecessary
as I am declaring the java location in the properties file. Or do i need it?

I forgot to state in my original text that I am running the gradle build from a Git Bash window.


(john kunchandy) #6

Well, I added a JAVA_HOME env variable and it is working!
I was wrong in assuming that just adding an "org.gradle.java.home"
to gradle.properties file in the gradle directory would be enough.
Thanks!


(john kunchandy) #7

Just for clarity, is setting ‘org.gradle.java.home’ to the location of jdk in gradle.properties an alternative to adding the environment variable JAVA_HOME?

Also, my gradle install is in c:\gradle-2.7 directory. This is where i added the gradle.properties file. Is this the correct location or should the file be in the local build directory?


(john kunchandy) #8
**1. Is setting 'org.gradle.java.home' to the location of jdk in gradle.properties an alternative to adding the environment variable JAVA_HOME?**

     Yes. Gradle will first look for the environment variable JAVA_HOME and if defined, use it .
     If JAVA_HOME is not found, it will look at the value in gradle.properties.

 **2. My gradle install is in c:\gradle-2.7 directory. This is where i added the gradle.properties file. Is this the correct location or should the file be in the local build directory?**

      Neither. The gradle.properties file looked up by gradle is located in the users home directory, in the .gradle subdirectory. (eg. c:/users/me/.gradle/gradle.properties). 

 **3. Should the format of my property be : org.gradle.java.home = "c:\Program Files\Java\jdk1.7.0_03" ?**
     
      No. As stated in the earlier replies it should be without quotes and using forward slashes: 
          org.gradle.java.home = c:/Program Files/Java/jdk1.7.0_03

(Andi) #9

Following properties files specification a colon is also a separator sign (like =). So it must be quoted in property values. A valid configuration entry in gradle.properties is:
org.gradle.java.home = c\:/Program Files/Java/jdk1.7.0_03
Note the backslash in front of the colon of the drive letter.


(keisuke Shimatani) #10

Hi,
Build fails on CentOS7.
JDK8 is installed.
Could you tell me a good measures?

$ ./gradlew clean build -xtest

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:compileJava’.
    Could not find tools.jar. Please check that /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre contains a valid JDK installation.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 0s
2 actionable tasks: 2 executed

$alternatives --config java

3 プログラムがあり ‘java’ を提供します。

選択 コマンド

*+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0. 161-2.b14.el7.x86_64/jre/bin/java)
2 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0. 171-2.6.13.2.el7.x86_64/jre/bin/java)
3 /usr/java/jdk1.8.0_171-amd64/jre/bin/java


(keisuke Shimatani) #11

Build succeeded with the following procedure:

[shimatani@bslpc168 ~/dataset-generator]$sudo alternatives --config java
[sudo] shimatani のパスワード:

3 プログラムがあり ‘java’ を提供します。

選択 コマンド

*+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre/bin/java)
2 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64/jre/bin/java)
3 /usr/java/jdk1.8.0_171-amd64/jre/bin/java

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:3

[shimatani@bslpc168 ~/dataset-generator]$./gradlew clean build -xtest
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

Task :compileJava
注意:入力ファイルの操作のうち、未チェックまたは安全ではないものがあります。
注意:詳細は、-Xlint:uncheckedオプションを指定して再コンパイルしてください。

BUILD SUCCESSFUL in 3s
7 actionable tasks: 7 executed
[shimatani@bslpc168 ~/dataset-generator]$