ubuntu找不到System Java Compiler。确保您已安装JDK(而不仅仅是JRE)a

时间:2013-12-21 04:54:20

标签: java ubuntu openjdk

在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

运行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)

javac -version的输出:

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

这些已安装在我的系统上,请参见此处的图片

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

请指导我在Ubuntu上运行此程序

6 个答案:

答案 0 :(得分:5)

安装JDK

sudo apt-get install openjdk-7-jdk

编辑:初步答案包含jre(不是jdk)

的包

答案 1 :(得分:3)

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

答案 2 :(得分:3)

这些都不适用于我的Ubuntu,真的。事实证明,有类似的东西 /usr/lib/jvm/default-java,这是安装的java版本的符号链接。

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

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

答案 3 :(得分:2)

在看到这篇文章后,我遇到了同样的问题,我试着做了

gradle -v
java -version
javac -version

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>

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

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

这里,/ usr / lib / jvm / java-7-openjdk-amd64 / jre是包含java二进制文件的目录,通过做哪个java

答案 4 :(得分:2)

  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
    

答案 5 :(得分:0)

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

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