简体   繁体   中英

gradle: java: Cannot find System Java Compiler

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:

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.

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

user:~/program/java$ echo "$JAVA_HOME"
/usr/lib/jvm/java-7-openjdk-i386

Still the same error.

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.

After removing all java footprints I reinstalled java 7 jdk and gradle with

sudo apt-get install openjdk-7-jdk gradle

and now it works.

From the properties you've pasted above, there seem to be two versions of Java installed:

  1. /usr/lib/jvm/java-1.7.0-openjdk-i386 (most likely not JDK, but just JRE)
  2. /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.

Also, verify that versions returned by java and javac are the same, which would confirm that they are pointing to the same JDK installation.

对我来说,我必须去Window-> Preferences并在Git-> Arguments中,将其设置为“ Workspace JRE”,我已经在Eclipse的Java->“ Installed JRE”设置中进行了设置,而不是默认选项“ Use Gradle wrapper's”。默认'。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM