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

StackOverflow https://stackoverflow.com/questions/20715586

  •  20-09-2022
  •  | 
  •  

Question

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

Was it helpful?

Solution 3

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.

OTHER TIPS

Install a JDK

sudo apt-get install openjdk-7-jdk

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

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.

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

  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
    

To be more specific try adding a gradle.properties file and specify org.gradle.java.home there. It worked for me when I had this same problem.

https://docs.gradle.org/current/userguide/build_environment.html

For me the problem was I had JRE but not JDK. Earlier I used to have below output

$ java -version
java 18.0.1.1 2022-04-22
Java(TM) SE Runtime Environment (build 18.0.1.1+2-6)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.1.1+2-6, mixed mode, sharing)

As soon I installed JDK my output changes as below

$ sudo apt install default-jre
$ java -version
openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.21.04)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.21.04, mixed mode, sharing)

This solved the problem. I also added last 2 lines to file etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
JAVA_HOME="/usr/lib/jvm/jdk-18"
PATH="$PATH:$JAVA_HOME/bin"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top