gradle:java:找不到系统 Java 编译器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27879358/
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
gradle: java: Cannot find System Java Compiler
提问by Stefan Bollmann
How can I gradle my hello.java project? Right now I get the error message "Cannot find System Java Compiler". However, for me everything seems fine configured on this Ubuntu 14:
我怎样才能 gradle 我的 hello.java 项目?现在我收到错误消息“找不到系统 Java 编译器”。但是,对我来说,在这个 Ubuntu 14 上一切配置都很好:
user:~/program/java/src/main/java$ javac hello.java
user:~/program/java/src/main/java$ ls
hello.class hello.java
user:~/program/java/src/main/java$ java hello
Hello World!
user:~/program/java/src/main/java$ cd ../../../
user:~/program/java$ ls
build build.gradle src
user:~/program/java$ gradle build
: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: ...
BUILD FAILED
My system configuration:
我的系统配置:
user:~/program/java$ javac -version
javac 1.7.0_72
user:~/program/java$ java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.14.04.1)
OpenJDK Server VM (build 24.65-b04, mixed mode)
suser:~/program/java$ echo "$JAVA_HOME"
/usr/lib/jvm/java-1.7.0-openjdk-i386
user:~/program/java$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 41 Jan 10 18:29 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-i386/bin/java
JAVA_HOME is defined in /etc/environment (was restarted) and also in the $HOME/.bashrc.
JAVA_HOME 定义在 /etc/environment(已重新启动)和 $HOME/.bashrc 中。
So, I think I did the things mentioned in this post. The hints there are similar to most hints I found googling.
所以,我想我做了这篇文章中提到的事情。那里的提示类似于我在谷歌上找到的大多数提示。
Due to Invisible Arrows answer I changed $JAVA_HOME to /usr/lib/jvm/java-7-openjdk-i386
由于 Invisible Arrows 答案,我将 $JAVA_HOME 更改为 /usr/lib/jvm/java-7-openjdk-i386
user:~/program/java$ echo "$JAVA_HOME"
/usr/lib/jvm/java-7-openjdk-i386
Still the same error.
还是一样的错误。
回答by Stefan Bollmann
Following Invisible Arrows hint, I did a complete uninstallation of my java packages.Who, however, follows this should know, that the best voted answer there removes many packages you have to reinstall later.
按照 Invisible Arrows 提示,我完全卸载了我的 java 包。但是,遵循此规则的人应该知道,那里的最佳投票答案会删除您稍后必须重新安装的许多软件包。
After removing all java footprints I reinstalled java 7 jdk and gradle with
删除所有java足迹后,我重新安装了java 7 jdk和gradle
sudo apt-get install openjdk-7-jdk gradle
and now it works.
现在它起作用了。
回答by Invisible Arrow
From the properties you've pasted above, there seem to be two versions of Java installed:
从上面粘贴的属性来看,似乎安装了两个版本的 Java:
/usr/lib/jvm/java-1.7.0-openjdk-i386
(most likely not JDK, but just JRE)/usr/lib/jvm/java-7-openjdk-i386
/usr/lib/jvm/java-1.7.0-openjdk-i386
(很可能不是 JDK,而只是 JRE)/usr/lib/jvm/java-7-openjdk-i386
The one pointed by JAVA_HOME
seems to be JRE and not JDK.
Try changing that to point to /usr/lib/jvm/java-7-openjdk-i386
and then run the Gradle build.
所指的JAVA_HOME
似乎是 JRE 而不是 JDK。尝试将其更改为指向/usr/lib/jvm/java-7-openjdk-i386
,然后运行 Gradle 构建。
Also, verify that versions returned by java
and javac
are the same, which would confirm that they are pointing to the same JDK installation.
此外,验证java
和返回的版本javac
是否相同,这将确认它们指向相同的 JDK 安装。
回答by armyofda12mnkeys
For me, I had to go to Window->Preferences and in Git->Arguments, set it to 'Workspace JRE' which I already have setup in Eclipse's Java->'Installed JRE' settings, versus the default option 'Use Gradle wrapper's default'.
对我来说,我必须转到 Window->Preferences 并在 Git->Arguments 中将其设置为“Workspace JRE”,我已经在 Eclipse 的 Java->“Installed JRE”设置中设置了它,而不是默认选项“Use Gradle wrapper's”默认'。