You have to install the full JDK, not only the JRE.
I had the same issue and solved by installing JDK.
Please use this link to download the latest JDK version 22.
Answer from MrDEV on Stack OverflowYou have to install the full JDK, not only the JRE.
I had the same issue and solved by installing JDK.
Please use this link to download the latest JDK version 22.
After installing openjdk with brew and runnning brew info openjdk I got this:
==> openjdk: stable 21 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/opt/homebrew/Cellar/openjdk/21 (600 files, 331MB)
Poured from bottle using the formulae.brew.sh API on 2023-09-26 at 11:06:55
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/openjdk.rb
License: GPL-2.0-only with Classpath-exception-2.0
==> Dependencies
Build: autoconf ✔, pkg-config ✔
Required: giflib ✔, harfbuzz ✔, jpeg-turbo ✔, libpng ✔, little-cms2 ✔
==> Requirements
Build: Xcode (on macOS) ✘
Required: macOS >= 10.15 (or Linux) ✔
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.
If you need to have openjdk first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include"
And from that I got this command here, and after running it I got Java working
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Can't find Java runtime on macOS (when installed using Homebrew)
In Terminal getting error: The operation … - Apple Community
Cannot find java runtime on MacOS (M1 silicon) after installing openjdk - Stack Overflow
macos - How to brew install java? - Stack Overflow
Videos
It seems that you are missing Java environment variable to make your program work.
What you can try:
Solution 1
Try to run caver_analyst with the --jdkhome switch, followed by (I guess) the path to a valid JDK as suggested in your error message. It should solve your problem.
Solution 2
Usually, the path to Java must be defined in a JAVA_HOME environment variable. Yours is obviously not defined, so let's define it manually :
- Open a Terminal
- Go to your home directory with command
cd - Look for a file called ".zshrc" in this directory:
you@yourmac ~ % ls .zshrc
.zshrc
- If it does not exist i.e. if the command
ls .zshrcgives you a "No such file or directory" message, create the file:touch .zshrc - Get the path to Java and keep it somewhere :
which java - Open the newly created file (it's a hidden file so you will have to show hidden files. Alternatively, you can edit the file in command line with
nano .zshrc) - At the end of the file, add the following line :
export JAVA_HOME="/Path/to/your/java/home"and replace /Path/to/your/java/home with the path that you got at step 5. - Save, close the file, reboot your laptop.
This file will be automatically read and its instructions executed when you open your profile. The "export" instruction creates an environment variable. You can verify if it was successfully created with echo $JAVA_HOME, echo being a command to display something. The "$" in front of the variable tells echo to look for a variable.
I hope this helps, but if it doesn't, please don't hesitate to share the error messages and step where it fails here...
I had to
- Install Java 8, eg
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
- add $JAVA_HOME to my ~/.zshrc
export JAVA_HOME='/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home'
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
- remove any other jdk installs
ls /Library/Java/JavaVirtualMachines
sudo rm -rf NONJDK8.jdk
The 3rd bit is important! It did not work until I removed other-versioned jdks.
I also ran into this today.
After installing openjdk with brew install openjdk, I got this too:
java --version
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
It seems there is already system-wide default java command/alias (I had no previous Java install), so let's show the details:
which java
/usr/bin/java
However reading the output of the brew install log one can see:
==> openjdk
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
so, if you do not have another existing Java system-wide installation just run (and type your mac user password):
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Password:
Now it works:
java --version
openjdk 21.0.2 2024-01-16
OpenJDK Runtime Environment Homebrew (build 21.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 21.0.2, mixed mode, sharing)
Since you installed Java previously with homebrew, you can use the brew info command to see the details of your installation:
% brew info java
openjdk: stable 15.0.1 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/usr/local/Cellar/openjdk/15.0.1 (614 files, 324.9MB)
Poured from bottle on 2020-12-09 at 09:06:07
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk.rb
License: Cannot Represent
Turns out java has been moved into brew core recently, so the correct command as of August 2022 is:
brew install java
Then check your installation by running
java -version
If the result does not looks like this:
openjdk 18.0.2 2022-07-19
OpenJDK Runtime Environment Homebrew (build 18.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.2+0, mixed mode, sharing)
but like this:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Then you also need to create a symlink for the system Java wrappers to find this JDK:
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk.jdk
As an add-on to the accepted answer: to install a certain version of Java, e.g. version 11, run:
brew install openjdk@11
And symlink it:
sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk-11.jdk