Unable to find any JVMs matching version "1.8.0_40" when open terminal on macOS
Solution 1
@sideshowbarker, you're right. I checked all shell initialization files and found the java version was set as 1.8.0_40 in /etc/profile
.
Thanks again.
Solution 2
MacOS X does not come with Java Development Kits (JDKs) pre-installed.
Run java -version
in the terminal and you may be prompted to install Java. Unless you already have JVM installed, in which case you will see the build version number.
Next, you will be prompted to visit the Java SE Development Kit Downloads page. Download one of the JDK (Java Development Kits) with a file extension ending in <filename>.tar.gz
.
Then run tar -xf <filename>.tar.gz
.
Rename the newly created directory to JAVA_HOME
.
Solution 3
i solved this using this command in terminal
brew install --cask homebrew/cask-versions/adoptopenjdk8
Solution 4
please use like brew cask install adoptopenjdk8
to install deprecated java version, esp. for Android Studio.
use java_home -V
to show all install version of java, like:
/usr/libexec/java_home -V
Matching Java Virtual Machines (5):
12.0.2, x86_64: "Java SE 12.0.2" /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
12.0.1, x86_64: "OpenJDK 12.0.1" /Library/Java/JavaVirtualMachines/openjdk-12.0.1.jdk/Contents/Home
1.8.0_222, x86_64: "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
1.6.0_65-b14-468, x86_64: "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
1.6.0_65-b14-468, i386: "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
and within .zshrc
or .bash_profile
for setting default jdk, like use command setjdk 1.8
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
function setjdk() {
export JAVA_HOME=`/usr/libexec/java_home -v $@`
}
and with recent java/jdk v12, the Android Studio CLI not work:
$setjdk 12
$avdmanager
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213)
at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 5 more
Brooklyn Knightley
Updated on July 05, 2022Comments
-
Brooklyn Knightley almost 2 years
I have installed jdk1.8.0_121 already and JAVA_HOME seems correct. But when I open terminal, it always reminds me "Unable to find any JVMs matching version "1.8.0_40"".
jdk1.8.0_40 was installed Previously but I hava already uninstalled this version.
Does anyone know how to remove this annoying reminder? Thanks a lot.
-
jmk over 5 yearsCould you please elaborate, what you id exactly?
-
giorgio79 over 3 years