简体   繁体   English

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

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

On ubuntu 12, I am trying to run example program of fuse-jna.在 ubuntu 12 上,我正在尝试运行 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:运行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 上运行这个程序

Install a JDK安装 JDK

sudo apt-get install openjdk-7-jdk

EDITED: initial answer had package for jre (not jdk)已编辑:最初的答案有 jre 包(不是 jdk)

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.更正etc/environment中的java_home环境变量并重启ubuntu后,现在运行正常了。 Thanks for the guidance.感谢您的指导。

None of these worked on my Ubuntu, really.这些都不能在我的 Ubuntu 上运行,真的。 Turns out, there is something like原来,有类似的东西
/usr/lib/jvm/default-java , which is a symbolic link to installed version of java. /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_HOME pointed 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。

I was facing the same issue, after seeing this post, I tried doing我遇到了同样的问题,看到这个帖子后,我试着做

gradle -v
java -version
javac -version

javac failed. javac 失败。 However, ubuntu prompted me to install javac with the following message但是,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 并将以下 2 行添加到我的 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 二进制文件的目录

  1. Install JDK安装 JDK

     sudo apt-get install openjdk-7-jdk
  2. Make your $JAVA_HOME point to the newly installed JDK让你的 $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. Update your java command symlink更新您的 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. 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.更具体地说,尝试添加一个 gradle.properties 文件并在那里指定 org.gradle.java.home。 It worked for me when I had this same problem.当我遇到同样的问题时,它对我有用。

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

For me the problem was I had JRE but not JDK.对我来说,问题是我有 JRE 但没有 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安装 JDK 后,我的输出更改如下

$ 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我还将最后两行添加到文件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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法获得System Java Compiler。请使用JDK,而不是JRE - Cannot get the System Java Compiler. Please use a JDK, not a JRE Eclipse,AppEngine:java.lang.RuntimeException:无法获取System Java编译器。 请使用JDK,而不是JRE - Eclipse, AppEngine: java.lang.RuntimeException: Cannot get the System Java Compiler. Please use a JDK, not a JRE Mac-GAE:无法获取System Java编译器。 请使用JDK,而不是JRE - Mac - GAE: Cannot get the System Java Compiler. Please use a JDK, not a JRE Google App Engine JSP无法部署:java.lang.RuntimeException:无法获取System Java Compiler。请使用JDK,而不是JRE - Google App Engine JSP can't deploy: java.lang.RuntimeException: Cannot get the System Java Compiler. Please use a JDK, not a JRE 将Java Appp部署到App Engine时出错? 无法获得System Java Compiler。 请使用JDK,而不是JRE? - Error When Deploying Java Appp to App Engine? Can not get the System Java Compiler. Please use a JDK, not JRE? 系统无法获取Java编译器,请使用jre的jdk intead - system cannot get java compiler please use jdk intead of jre 在非JDK /非JRE安装系统中运行Java应用程序的问题 - Problem in Running Java Application in Non JDK/ Non JRE installed system 获取java.lang.RuntimeException:无法获取System Java编译器。 可能是什么原因呢? - Getting java.lang.RuntimeException: Cannot get the System Java Compiler. What could be the reason for it? 即使您在系统上安装了 JDK,是否也需要 Java SE 来安装 Netbeans? - Is Java SE required to install Netbeans even if you have JDK installed on the system? 如何分辨已安装的Java的差异-JDK或JRE - How to tell the diffarences of installed java - JDK or JRE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM