ubuntu Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) a

13,211

Solution 1

It was a problem with an environment variable. After correcting the java_home environment variable in etc/environment and restarting ubuntu, now it runs ok. Thanks for the guidance.

Solution 2

Install a JDK

sudo apt-get install openjdk-7-jdk

EDITED: initial answer had package for jre (not jdk)

Solution 3

None of these worked on my Ubuntu, really. Turns out, there is something like
/usr/lib/jvm/default-java, which is a symbolic link to installed version of java.

The funny thing, this was pointing out to /usr/lib/jvm/java-7-openjdk-i386 (the JDK!), but JAVA_HOME pointed to completely different location - the location where I have my current, up-to-date JDK8 installation.

I simply updated the symlink to point to correct location, but it is likely to be overridden with an update of OpenJDK7... I guess I have to get rid of OpenJDK then.

Solution 4

I was facing the same issue, after seeing this post, I tried doing

gradle -v
java -version
javac -version

javac failed. However, ubuntu prompted me to install javac with the following message

21:52:17->javac
The program 'javac' can be found in the following packages:
* default-jdk
* ecj
* gcj-4.8-jdk
* openjdk-7-jdk
* gcj-4.6-jdk
* openjdk-6-jdk
Try: sudo apt-get install <selected package>

After installing javac using openjdk-7-jdk and adding the following 2 lines to my bashrc, gradle started working

JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/jre"
PATH="$PATH:$JAVA_HOME/bin"

Here, /usr/lib/jvm/java-7-openjdk-amd64/jre is the directory containing java binary found by doing which java

Solution 5

  1. Install JDK

    sudo apt-get install openjdk-7-jdk
    
  2. Make your $JAVA_HOME point to the newly installed JDK

    echo $JAVA_HOME
    # prints nothing
    
    sudo echo 'JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64' >> /etc/profile
    source /etc/profile
    
    echo $JAVA_HOME
    # /usr/lib/jvm/java-7-openjdk-amd64
    
  3. Update your java command symlink

    java -version
    # java version "1.6.0_32"
    # OpenJDK Runtime Environment (IcedTea6 1.13.4) (6b32-1.13.4-1~deb7u1)
    # OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
    which java
    # /usr/bin/java
    ls -l /usr/bin/java
    # lrwxrwxrwx 1 root root 22 Sep 20 21:22 /usr/bin/java -> /etc/alternatives/java
    ls -l /etc/alternatives/java
    # lrwxrwxrwx 1 root root 42 Sep 21 00:01 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
    
    sudo rm /etc/alternatives/java
    sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/bin/java /etc/alternatives/java
    
    java -version
    # java version "1.7.0_65"
    # OpenJDK Runtime Environment (IcedTea 2.5.1) (7u65-2.5.1-5~deb7u1)
    # OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
    
  4. Try again

    gradle compileJava
    # :compileJava
    
    # BUILD SUCCESSFUL
    
    # Total time: 9.397 secs
    
Share:
13,211

Related videos on Youtube

user584910
Author by

user584910

Updated on October 06, 2022

Comments

  • user584910
    user584910 about 1 year

    On ubuntu 12, I am trying to run example program of fuse-jna. I got below error message

    syed@ubuntu:~/Downloads/fuse-jna-master/examples$ ./hellofs.sh ~/hellofs
    :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:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    BUILD FAILED
    

    running java -version command shows me:

    syed@ubuntu:~/Downloads/fuse-jna-master/examples$ java -version
    java version "1.7.0_15"
    OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.10)
    OpenJDK Client VM (build 23.7-b01, mixed mode, sharing)
    

    output of javac -version:

    syed@ubuntu:~/Downloads/fuse-jna-master/examples$ javac -version
    javac 1.6.0_27
    

    these are installed on my system, see the picture here

    http://i40.tinypic.com/2hf2j4z.png

    Please guide me to run this program on Ubuntu

    • andy
      andy almost 10 years
      JDK (not just a JRE), check do you have javac.exe. try run javac
    • Ingo
      Ingo almost 10 years
      It would be interesting to know what the shell scripts is actually doing. Run the script with bash -x to find out. And also what the JAVA_HOME variable is set to.
  • user584910
    user584910 almost 10 years
    it also not solved the issue. I am facing the same error message as i shared in first post.
  • Ian Roberts
    Ian Roberts almost 10 years
    You mean openjdk-7-jdk, the jre is already there by the look of it.
  • Noumenon
    Noumenon about 8 years
    I'm on Windows so I checked all the rest of the Internet before finding your advice to check javac -version. Thanks!