ubuntu 找不到系统 Java 编译器。确保您已经安装了 JDK(不仅仅是 JRE)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20715586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:46:52  来源:igfitidea点击:

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

javaubuntuopenjdk

提问by user584910

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

在 ubuntu 12 上,我正在尝试运行 fuse-jna 的示例程序。我收到以下错误消息

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 -versioncommand shows me:

运行java -version命令显示我:

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:

的输出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

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

Please guide me to run this program on Ubuntu

请指导我在 Ubuntu 上运行这个程序

采纳答案by user584910

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.

这是环境变量的问题。更正etc/environment中的java_home环境变量,重启ubuntu后,运行正常。感谢您的指导。

回答by stevedbrown

Install a JDK

安装 JDK

sudo apt-get install openjdk-7-jdk

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

编辑:初始答案有 jre 包(不是 jdk)

回答by Pawe? Dyda

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.

这些都不适用于我的 Ubuntu,真的。原来,有类似的东西
/usr/lib/jvm/default-java,它是到已安装的 java 版本的符号链接。

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

有趣的是,这指向/usr/lib/jvm/java-7-openjdk-i386(JDK!),但JAVA_HOME指向完全不同的位置 - 我当前安装最新 JDK8 的位置。

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.

我只是更新了符号链接以指向正确的位置,但它很可能会被 OpenJDK7 的更新覆盖......我想我那时必须摆脱 OpenJDK。

回答by Max Jindal

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

javac 失败。但是,ubuntu 提示我安装 javac 并显示以下消息

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

使用 openjdk-7-jdk 安装 javac 并将以下两行添加到我的 bashrc 后,gradle 开始工作

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

这里,/usr/lib/jvm/java-7-openjdk-amd64/jre 是包含通过执行 which java 找到的 java 二进制文件的目录

回答by e18r

  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
    
  1. 安装JDK

    sudo apt-get install openjdk-7-jdk
    
  2. 使您的 $JAVA_HOME 指向新安装的 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. 更新您的 java 命令符号链接

    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. 再试一次

    gradle compileJava
    # :compileJava
    
    # BUILD SUCCESSFUL
    
    # Total time: 9.397 secs
    

回答by SallyRothroat

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.

更具体地说,尝试添加一个 gradle.properties 文件并在那里指定 org.gradle.java.home 。当我遇到同样的问题时,它对我有用。

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

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