Announcement Announcement Module
No announcement yet.
STS with Gradle - Java_HOME not found Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • STS with Gradle - Java_HOME not found

    Hello There,

    I tried the gradle-sts documentation .

    When I am building Gradle I get :

    Cause: Unable to find a javac compiler; is not on the classpath.
    Perhaps JAVA_HOME does not point to the JDK.
    It is currently set to "C:\Program Files\Java\jre6"
    Now I am using all default Gradle option so not sure what going wrong.

    My STS version is 2.9.1


  • #2
    This could be either one of two problems:
    1) you have only a JRE installed on your system. Gradle needs a JDK (JRE doesn't have the javac compiler, which gradle needs).
    2) you have both a JRE and a JDK installed, but gradle doesn't find the JDK because it only looks in the 'standard' location where it just finds the JRE.

    Depending on what you have installed on your system you may be able to decide which of the two cases you are in.

    If you are in case 1) you will need to install a JDK. (Then you might end up in case 2)

    If you are in case 2) please take a look at this issue:

    In short, only recently has it become possible to tell Gradle from within STS which JAVA_HOME to use. You will need to install a nightly snapshot of the gradle-sts tools to get this option. Or you can try some of the workarounds suggested in the issue.



    • #3
      Hey Kris,

      I have JDK installed in seperate location :

      Attachment Attachment

      I am not able to set JVM_OPTION from gradle preference page as bug 2276 suggests.

      Please suggest.

      Attached Files


      • #4
        Ok , I updated the STS Gradle with nightly build plugin I see java _home option. When I select it and give workspace jre ,it takes that. But gradle build still fails with java_home error . When I go back to to preference page . I see in java home section of Gradle preference it show -use gradle wrapper's default . Why it is not remembering the option.

        Attached Files


        • #5
          Hi Priyanka,

          I don't know why it is not remembering the option. It could be a bug. This preference page is really brand new and I bet that you are one of the first few people to actually use it. So if it was a bug in my implementation, I wouldn't be too surprised.

          Could you be more precise on what you did? I just tried to set the option. Click 'Apply' button. Then close the prefs dialog. When I reopen it it is still set.

          I also then closed my STS and reopened it (to verify if perhaps the settings where not actually persisted on disk between sessions). But that also seems to work for me.

          But maybe there is some sequence of steps where the prefs are not properly saved. Or maybe this could be a Windows <-> Linux bug. Or perhaps you accidentally clicked 'Cancel' instead of 'Apply'.



          • #6
            I played with it a bit more and found a potential problem with the UI. Maybe that is what happened for you.

            When I type some text in the combo box after selecting the JRE. E.g. add a couple of extra spaces at the end of the workspace JRE name...

            Then close and reopen the prefs page... Then it will be reset to 'use gradle wrapper's default'. This is because the selected name with the extra text added no longer corresponds to a valid JRE name.

            This shows I really should add some validation logic to the UI to prevent this from happening (or at least have some error message when an invalid name is present in the combo box.



            • #7
              OK Here are set of steps :-

              Gradle Preferences -> Java Home select Workspace JRE :
              hit Appy than OK

              Go to build.gradle ->Run As Gradle Build ... ->Run

              Error comes back->
              Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
              Could not execute build using Gradle distribution ''.

              Again go back to Gradle preference -> See Java Home the check box of use Gradle wrapper's default is selected .

              It is not remembering the option.


              • #8
                The steps you did should work. If they don't, this is a bug. Unfortunately, when I do the same steps it does work for me.
                Also I had at least one Windows user confirm to me that it worked for them. So this makes it all the more puzzling.

                I don't know what we can do to figure out why its not working for you.

                I did however already patch up the UI a little and fixed (

                It should be already on the nightly update site. It may be useful if you could update to this latest version. It can't really promise it will help, but I'm not sure what else to try at the moment. While you try that, I'll give it some more thought.


                PS: Does the name of the JRE or its path contain any special or funny characters (often when something hits a particular user only, it is because of something like that triggering a bug that others are not hitting, so its worth checking).


                • #9
                  Hey Kris,

                  I got the latest nightly build and now it is remembering the jre preferences. Also I am able to the gradle build.



                  • #10
                    Glad to hear it! Thanks for letting me know.