Bazel: Launcher can't find Java 8 when installer runs

Created on 18 Feb 2016  路  9Comments  路  Source: bazelbuild/bazel

It is both the Java on my path and set in JAVA_HOME, not sure what's going on here:

$ java -version
openjdk version "1.8.0-google-v7"
OpenJDK Runtime Environment (build 1.8.0-google-v7-112381132-112193401)
OpenJDK 64-Bit Server VM (build 25.51-b03, mixed mode)
$ which java
/usr/local/buildtools/java/jdk/bin/java
$ export JAVA_HOME=/usr/local/buildtools/java/jdk
$ sudo ./bazel-0.2.0rc1-installer-linux-x86_64.sh 
Bazel installer
---------------

# Release 0.2.0 (2016-02-18)
...
## Build informations
   - [Build log](http://ci.bazel.io/job/Bazel/JAVA_VERSION=1.8,PLATFORM_NAME=linux-x86_64/367/)
   - [Commit](https://github.com/bazelbuild/bazel/commit/b78baea)
Uncompressing......Java version is 1.7.0_95 while at least 1.8 is needed.
Please set JAVA_HOME.
P1 bug

Most helpful comment

For those running RHEL/CentOS, this happens when you have java-1.8.0-openjdk installed but do not have java-1.8.0-openjdk-devel installed (but do have java-1.6.0-openjdk-devel installed). Installing java-1.8.0-openjdk-devel should fix it

All 9 comments

The message is coming from Bazel launcher.

Root has the wrong installation:

 $ sudo bash -c 'export | grep JAVA_HOME'
declare -x SUDO_COMMAND="/bin/bash -c export | grep JAVA_HOME"
$ sudo bash -c 'java -version'
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

Not sure we can do anything here. Closing as WAI, feel free to re-open if you have an idea on how to do better.

Hi, what was the workaround for this? I'm having the exact same issue, have openjdk 1.8.0 installed, but the installer wants to use 1.7.0_95, despite my having set JAVA_HOME otherwise.

You can export the variable and then use sudo -E, see http://stackoverflow.com/a/8633575 for an example (and some other options).

That did the trick, thanks!

The thread might be closed already but for those struggling with the problem, if you $ "strace bazel", you will see from where the program is actually fetching the java binary, like: "access("/usr/lib64/jvm/java/bin/java", X_OK) = 0" in my case. After that it was easy to correct the problem on my system.
Thanks

I solved mine using "sudo update-alternatives --config javac" and set it to the right option. (Note: it is for javac not java).

I solved mine using these steps:
http://dataracer.io/docs/2017/01/27/java-macos.html (website down)
Set JAVA_HOME environment variable. Add JAVA_HOME to your ~.bash_profile:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0_131)

Test Java. Verify JAVA_HOME is set:
echo $JAVA_HOME.
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home

'java -version'
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

For those running RHEL/CentOS, this happens when you have java-1.8.0-openjdk installed but do not have java-1.8.0-openjdk-devel installed (but do have java-1.6.0-openjdk-devel installed). Installing java-1.8.0-openjdk-devel should fix it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ajaysaini-sgvu picture ajaysaini-sgvu  路  3Comments

davidzchen picture davidzchen  路  3Comments

f1recracker picture f1recracker  路  3Comments

ob picture ob  路  3Comments

GaofengCheng picture GaofengCheng  路  3Comments