gradle: java: Cannot find System Java Compiler

10,658

Solution 1

Following Invisible Arrows hint, I did a complete uninstallation of my java packages. Who, however, follows this should know, that the best voted answer there removes many packages you have to reinstall later.

After removing all java footprints I reinstalled java 7 jdk and gradle with

sudo apt-get install openjdk-7-jdk gradle

and now it works.

Solution 2

From the properties you've pasted above, there seem to be two versions of Java installed:

  1. /usr/lib/jvm/java-1.7.0-openjdk-i386 (most likely not JDK, but just JRE)
  2. /usr/lib/jvm/java-7-openjdk-i386

The one pointed by JAVA_HOME seems to be JRE and not JDK. Try changing that to point to /usr/lib/jvm/java-7-openjdk-i386 and then run the Gradle build.

Also, verify that versions returned by java and javac are the same, which would confirm that they are pointing to the same JDK installation.

Share:
10,658
Stefan Bollmann
Author by

Stefan Bollmann

Started with generating plasma waves in C ... working for color in print as living for Heidelberger Druckmaschinen AG ...

Updated on June 04, 2022

Comments

  • Stefan Bollmann
    Stefan Bollmann almost 2 years

    How can I gradle my hello.java project? Right now I get the error message "Cannot find System Java Compiler". However, for me everything seems fine configured on this Ubuntu 14:

    user:~/program/java/src/main/java$ javac hello.java 
    user:~/program/java/src/main/java$ ls
    hello.class  hello.java
    user:~/program/java/src/main/java$ java hello 
    Hello World!
    user:~/program/java/src/main/java$ cd ../../../
    user:~/program/java$ ls
    build  build.gradle  src
    user:~/program/java$ gradle build
    :compileJava FAILED
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':compileJava'.
    > 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.
    
    * Try: ...
    
    BUILD FAILED
    

    My system configuration:

    user:~/program/java$ javac -version
    javac 1.7.0_72
    user:~/program/java$ java -version
    java version "1.7.0_65"
    OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.14.04.1)
    OpenJDK Server VM (build 24.65-b04, mixed mode)
    suser:~/program/java$ echo "$JAVA_HOME"
    /usr/lib/jvm/java-1.7.0-openjdk-i386
    user:~/program/java$ ls -l /etc/alternatives/java
    lrwxrwxrwx 1 root root 41 Jan 10 18:29 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-i386/bin/java
    

    JAVA_HOME is defined in /etc/environment (was restarted) and also in the $HOME/.bashrc.

    So, I think I did the things mentioned in this post. The hints there are similar to most hints I found googling.


    Due to Invisible Arrows answer I changed $JAVA_HOME to /usr/lib/jvm/java-7-openjdk-i386

    user:~/program/java$ echo "$JAVA_HOME"
    /usr/lib/jvm/java-7-openjdk-i386
    

    Still the same error.

  • Stefan Bollmann
    Stefan Bollmann over 9 years
    'ls -l /usr/lib/jv/java-1.7.0-openjdk-i386' gives 'lrwxrwxrwx 1 root root 19 Apr 18 2014 /usr/lib/jvm/java-1.7.0 openjdk-i386 -> java-7-openjdk-i386'. However, I will change that.
  • Invisible Arrow
    Invisible Arrow over 9 years
    Hmmm, that is indeed strange. The other approach is to just remove all existing installations of Java, and re-install it with sudo apt-get install openjdk-7-jdk. Might save a lot of trouble trying to troubleshoot the existing issue :)
  • Fernando Bustos
    Fernando Bustos over 8 years
    I don't know how do that from terminal but in Eclipse is too easy, only need to go to Gradle Task View -> build -> right click->Open Gradle Configuration -> JAVA_HOME -> and put the current value of your enviroment, something like C:\Program Files\Java\jdk1.7.0_79 I hope this help you