can't avdmanager and other SDK tools with same java version [duplicate] - java

When installing the android sdk tools the following error is emitted:
java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
Why is this happening and how can it be fixed?
Debug output:
$ java --version
java 9
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
$ brew cask install android-sdk
==> Caveats
We will install android-sdk-tools, platform-tools, and build-tools for you.
You can control android sdk packages via the sdkmanager command.
You may want to add to your profile:
'export ANDROID_SDK_ROOT=/usr/local/share/android-sdk'
This operation may take up to 10 minutes depending on your internet connection.
Please, be patient.
==> Satisfying dependencies
==> Downloading https://dl.google.com/android/repository/sdk-tools-darwin-3859397.zip
Already downloaded: /Users/tomasnovella/Library/Caches/Homebrew/Cask/android-sdk--3859397,26.0.1.zip
==> Verifying checksum for Cask android-sdk
==> Installing Cask android-sdk
==> 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.SdkManagerCli.main(SdkManagerCli.java:117)
==> at com.android.sdklib.tool.SdkManagerCli.main(SdkManagerCli.java:93)
==> Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
==> at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
==> at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
==> at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
==> ... 5 more
Error: Command failed to execute!
==> Failed command:
/usr/local/Caskroom/android-sdk/3859397,26.0.1/tools/bin/sdkmanager tools platform-tools build-tools;26.0.1
==> Standard Output of failed command:
==> Standard Error of failed command:
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.SdkManagerCli.main(SdkManagerCli.java:117)

Just had this error, solved by downloading the Android SDK Command-line Tools (latest) on Android Studio, under Preferences > Appearance & Behavior > System Settings > Android SDK > SDK Tools and re-running flutter doctor --android-licenses
Finally, add the new tools to your PATH, in your .bashrc, .zshrc or similar, before the obsolete tools:
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin

I had a similar problem this morning (trying to build for Android using Unity3D). I ended up uninstalling JDK9 and installing Java SE Development Kit 8u144.
brew cask uninstall java # uninstall java9
brew tap homebrew/cask-versions
brew cask install java8 # install java8
touch ~/.android/repositories.cfg # without this file, error will occur on next step
brew install --cask android-sdk

I also had this error
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.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 5 more
then instead of uninstalling the latest java environment, (in my case it is java 13)
and installation of java 8,
I have done the following steps
open the android studio > go to configure > select sdk manager > go to sdk tools > make a tick on android sdk command line tools >apply > and wait for installation
restart the command line tool
enter the command flutter doctor
enter the command flutter doctor --android-licenses
and accept all the licenses by typing y.

To solve this error, you can downgrade your Java version.
Or exports the following option on your terminal:
Linux/MAC:
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
Windows:
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
If this does not work try to exports the java.xml.bind instead.
Linux:
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.xml.bind'
Windows:
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.xml.bind
And to save it permanently you can exports the JAVA_OPTS in your profile file on Linux (.zshrc, .bashrc and etc.) or add it as an environment variable permanently on Windows.
ps. This doesn't work for Java 11/11+, which doesn't have Java EE modules. For this option is a good idea, downgrade your Java version or wait for a Flutter update.
Ref: JDK 11: End of the road for Java EE modules

set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
This fixed the problem on Windows for me.
Source 1, source 2

Update 2019-10:
As stated in the issue tracker, Google has been working on a new Android SDK Command-line Tools release that runs on current JVMs (9, 10, 11+) and does not depend on deprecated JAXB EE modules!
You can download and use the new Android SDK Command-line Tools inside Android Studio or by manually downloading them from the Google servers:
SDK Tools for Linux
SDK Tools for Mac OS
SDK Tools for Windows
For the latest versions check the URLs inside the repository.xml.
If you manually unpack the command line tools, take care of placing them in a subfolder inside your $ANDROID_HOME (e.g. $ANDROID_HOME/cmdline-tools/...).
Update 2021-03:
The latest stable command-line tools are available at Googles Downloads-Website. These tools are newer than those linked above.

If you don't want to change your Java version (I don't), you can temporarily change the version in your shell:
First run
/usr/libexec/java_home -V
Then pick a major version if you have it installed, otherwise install it first:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
Now you can run sdkmanager.

When using Linux, an easy option is installation of JDK version 8 then selecting it as the default using:
sudo update-alternatives --config java

On Mac/Linux use the following command:
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
Works for both JDK 9 and 10, without patching any script (sdkmanager, avdmanager).
For Java 11 see: https://stackoverflow.com/a/51644855/798165

You need to add the following to your Profile (Works on MacOS):
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
No need to patch anything.

While building the flutter application an error occurred saying android sdk licenses not accepted. So, while accepting the license this error occurred.
Reason for this error in my case was I haven't installed sdkmanager command line tools which is required to accept the license.
So, to install command line tools easiest way is:
Open android studio.
Open SDK Manager (refer image below):
Select SDK tools inside it in bar.
Tick the option Android SDK Command-line Tools (latest)
Apply it.
Run flutter doctor -android-licenses if using flutter or you can continue with the process where the error occurred.

I found two answers that worked for me, without having to uninstall JDK 10 (or 9), which I need for create-react-app. Both JDK 9 and 10 are incompatible with android-sdk !
Siu Ching Pong -Asuka Kenji- suggests modifying the sdkmanager script, replacing this line:
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME"'
with:
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
Note that this mod will be overwritten when updating sdkmanager.
Check out his post, and the one he links to, for more details.
This solution was also one of the solutions mentioned in this github issues thread.
German's post indicates the source of the conflict, and presents fix that will not not be overwritten by updates.
He suggests renaming /Library/Java/JavaVirtualMachines/Info.plist as a means of obscuring it from the script that looks for the highest version of Java that resides on your system. In this way, JDK 8 is returned as the default.
Referring to JDK 10 explicitly, or by setting it to $JAVA_HOME, you can use JDK 10 , instead of the default, whenever needed.
Details are in his post.

Strangely Java9 is not compatible with android-sdk
$ 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:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 5 more
Combined all commands into one for easy reference:
$ sudo rm -fr /Library/Java/JavaVirtualMachines/jdk-9*.jdk/
$ sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
$ sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
$ /usr/libexec/java_home -V
Unable to find any JVMs matching version "(null)".
Matching Java Virtual Machines (0):
Default Java Virtual Machines (0):
No Java runtime present, try --request to install
$ brew tap caskroom/versions
$ brew cask install java8
$ touch ~/.android/repositories.cfg
$ brew cask install android-sdk
$ echo 'export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"' >> ~/.bash_profile
$ java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
$ avdmanager
Usage:
avdmanager [global options] [action] [action options]
Global options:
-s --silent : Silent mode, shows errors only.
-v --verbose : Verbose mode, shows errors, warnings and all messages.
--clear-cache: Clear the SDK Manager repository manifest cache.
-h --help : Help on a specific command.
Valid actions are composed of a verb and an optional direct object:
- list : Lists existing targets or virtual devices.
- list avd : Lists existing Android Virtual Devices.
- list target : Lists existing targets.
- list device : Lists existing devices.
- create avd : Creates a new Android Virtual Device.
- move avd : Moves or renames an Android Virtual Device.
- delete avd : Deletes an Android Virtual Device.

I faced the same problem. Though I am a little bit backdated developer (Still using windows to develop :P)
To solve this issue on windows :
STEP 1: Install jdk 8 if it wasn't installed (jdk 9 or 11 doesn't work but you may have them installed for using in other dev uses).
Very simple using Chocolatey:
choco install jdk8
(If installed using Chocolatey, skip steps 2 and 3)
STEP 2: Go to the Environment variables settings and set JAVA_HOME TO jdk 8's installation directory.
STEP 3: Go to path variable and add bin directory of jdk 8 and move it to top.
STEP 4: Close any open terminal sessions and restart a new session
OPTIONAL STEP 5: Depending on your objective in the terminal run (may need to add sdkmanager to path or just navigate to the directory):
sdkmanager --update
That's all! :O Enjoy fluttering! :D

Since Java 11 has removed JavaEE you'll need to download some jars and add to the classpath:
JAXB:
https://javaee.github.io/jaxb-v2/
JAF:
https://www.oracle.com/technetwork/articles/java/index-135046.html
Then edit sdkmanager.bat so that set CLASSPATH=... ends with ;%CLASSPATH%
Set CLASSPATH to include JAXB and JAF:
set CLASSPATH=jaxb-core.jar;jaxb-impl.jar;jaxb-api.jar;activation.jar
Then sdkmanager.bat will work.

I ran into same issue when running:
$ /Users/<username>/Library/Android/sdk/tools/bin/sdkmanager "platforms;android-28" "build-tools;28.0.3"_
I solved it as
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
$ ls /Library/Java/JavaVirtualMachines/
jdk-11.0.1.jdk
jdk1.8.0_202.jdk
Change Java to use 1.8
$ export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home'
Then the same command runs fine
$ /Users/<username>/Library/Android/sdk/tools/bin/sdkmanager "platforms;android-28" "build-tools;28.0.3"

In my case, I need both JDK 8 (trying to use the AVD and SDK manager in Qt under ubuntu) and 11 for different tools. Removing version 11 is not an option.
The 'JAVA_OPTS' solutions did not do anything. I don't really like the export JAVA_HOME, as it might force you do launch whatever tool calls these utils from the same shell (like Qt), or force you to make this permanent, which is not convenient.
So for me the solution is quite simple. Add something like this in the second line of ~/Android/tools/bin/sdkmanager and ~/Android/tools/bin/avdmanager:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
(or whatever the path is to your rev 8 jdk).
With this, these command line tools work in a stand alone mode, they work also when called by other tools such as Qt, and jdk 11 is still the system default for others. No need to mix libs etc...
The only downside is that any update to these command line tools will erase these modifications, which you will have to put back in.

As of the latest version of the Android command-line tools (2.1 as of this writing), it is no longer necessary to patch sdkmanager nor to downgrade to an ancient version of Java.
Simply update your SDK packages and switch your command-line tools to the latest release, which will track new versions as they come:
sdkmanager --update
sdkmanager 'cmdline-tools;latest'
sdkmanager --uninstall 'cmdline-tools;1.0'
You may need to provide the full path to sdkmanager if it's not on your PATH, and you may need to adjust your PATH afterwards if it was referring to the 1.0 tools explicitly.

In my case, I have Java 14 and need Java 8.
I'm in a Arch Linux and has installed jdk8-openjdk jre8-openjdk https://www.archlinux.org/packages/extra/x86_64/java8-openjdk/
For Debian users https://wiki.debian.org/Java, or Fedora https://docs.fedoraproject.org/en-US/quick-docs/installing-java/.
Install Java 8 (or desired version, in this case jdk8-openjdk jre8-openjdk) using your package manager before doing the following steps.
1. Figuring out where is my Java:
# which java
/usr/bin/java
2. Checking java files:
I can see all java files here are links to /usr/lib/jvm/default[something]. This means that the java command is linked to some specific version of java executable.
# ls -l /usr/bin/java*
lrwxrwxrwx 1 root root 37 May 16 06:30 /usr/bin/java -> /usr/lib/jvm/default-runtime/bin/java
lrwxrwxrwx 1 root root 30 May 16 06:30 /usr/bin/javac -> /usr/lib/jvm/default/bin/javac
lrwxrwxrwx 1 root root 32 May 16 06:30 /usr/bin/javadoc -> /usr/lib/jvm/default/bin/javadoc
lrwxrwxrwx 1 root root 30 May 16 06:30 /usr/bin/javah -> /usr/lib/jvm/default/bin/javah
lrwxrwxrwx 1 root root 30 May 16 06:30 /usr/bin/javap -> /usr/lib/jvm/default/bin/javap
3. Checking the default and default-runtime
Here I could see the default version was linked to 14 (unique installed version).
# cd /usr/lib/jvm
# ls -l
lrwxrwxrwx 1 root root 14 Aug 8 20:44 default -> java-14-openjdk
lrwxrwxrwx 1 root root 14 Aug 8 20:44 default-runtime -> java-14-openjdk
drwxr-xr-x 7 root root 4096 Jul 19 22:38 java-14-openjdk
drwxr-xr-x 6 root root 4096 Aug 8 20:42 java-8-openjdk
4. Switching the default version
First, remove the existing default and default-runtime which linked to java-14 version.
# rm default default-runtime
Then, create new links to the desired version (in this case, java-8).
# ln -s java-8-openjdk default
# ln -s java-8-openjdk default-runtime
The strategy is to make links to the desired version of software (java8 in this case) using ln -s above. Then, this links are linked to the binaries inside the java bin directory (without changing the $PATH environment variable!)
Or you might be wanted to change the Java version using archlinux-java command instead with more safely approach: https://wiki.archlinux.org/index.php/Java

TLDR; Try setting JAVA_HOME worked fine for me on OSX
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
To install the JDKs 8 ( LTS ) from AdoptOpenJDK:
# brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk/openjdk/adoptopenjdk8

This question has numerous answers, and they're all different due to users installing different toolchains and using different Java versions.
The recommended way of using Android development toolchain, or at least the one that I suggest to use, is to follow what's stated in Android Studio documentation:
You should always keep your Build Tools component updated by downloading the latest version using the Android SDK Manager.
Android studio allows you to easily manage installed SDKs & build tools, yes, it requires some space on your hard drive, but it will save you some time. Once you get familiar with how it works, then you can think of installing command-line tools only.
If there's no particular reason of using older Java version, use the latest (stable) version, you will have interesting new features, and also the compiled application will benefit from all the new optimizations.
Fresh install
Delete your local Android folder, usually in the home directory
Download Android studio
Once installed, open Settings, Search Android SDK and open it
In SDK Platforms select the target Android version for your app
In SDK Tools tab, select Android SDK Build-Tools, Android SDK Command-line Tools (latest), Android Emulator, Android SDK Platform-Tools
Before pressing OK, check that Android SDK Location path is correct for you
Press OK and let Android Studio download & install everything
(Optional) if you need to use the installed binaries from command line, be sure to add their folder into your PATH variable. If you use Android studio, it's should not be required though.
I've got Java 14 installed on my machine, anyway you can use the jre shipped with Android Studio.

For Linux users (I'm using a Debian Distro, Kali)
Here's how I resolved mine.
If you don't already have jdk-8, you want to get it at oracle's site
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
I got the jdk-8u191-linux-x64.tar.gz
Step 1 - Installing Java
Move and unpack it at a suitable location like so
$ mv jdk-8u191-linux-x64.tar.gz /suitablelocation/
$ tar -xzvf /suitablelocation/jdk-8u191-linux-x64.tar.gz
You should get an unzipped folder like jdk1.8.0_191
You can delete the tarball afterwards to conserve space
Step 2 - Setting up alternatives to the default java location
$ update-alternatives --install /usr/bin/java java /suitablelocation/jdk1.8.0_191/bin/java 1
$ update-alternatives --install /usr/bin/javac javac /suitablelocation/jdk1.8.0_191/bin/javac 1
Step 3 - Selecting your alternatives as default
$ update-alternatives --set java /suitablelocation/jdk1.8.0_191/bin/java
$ update-alternatives --set javac /suitablelocation/jdk1.8.0_191/bin/javac
Step 4 - Confirming default java version
$ java -version
Notes
In the original article here: https://forums.kali.org/showthread.php?41-Installing-Java-on-Kali-Linux,
the default plugin for mozilla was also set. I assume we don't really need the plugins as we're
simply trying to develop for android.
As in #spassvogel's answer, you should also place a #repositories.cfg file in your ~/.android directory
as this is needed to update the tools repo lists
Moving some things around may require root authority. Use sudo wisely.
For sdkmanager usage, see official guide: https://developer.android.com/studio/command-line/sdkmanager

In my case I didn't have the required sdk version installed on my machine.
So make sure that you have installed the sdk version which is given in the error.
Here you can navigate check & install via Android Studio.

For windows machine uninstall the JDK if its more than 1.8.172.
Install JDK 1.8.172
I was facing the same issue in windows 10 with java 10. I uninstalled the java 10 and installed java8 its working fine for me now :)

Run java -version and javac -version commands in a command line to make sure that they come from the same JDK (eg: version 1.8.0_181)
If not, you have to modify PATH variable so that it only points to a single JDK. If you are not sure how to, just uninstall all other Java instances except for Java 8 (Add/Remove Programs in Windows). As for today, both Unity and Android recommends that you use JDK 8.
With Java 8, it is not necessary to export java.se.ee module as shown in some of the other answers. You may also remove any JAVA_OPTS or other environment variables that you have set.

Downgrade your java version.Whatever system or ide.
Make sure java version is not higher than 8
In my case.I change the ide java verion.This solves my issue.

I had recently solved this problem by uninstalling the higher version of JDK and installing JDK 8. After installing the JDK you need to give the path. Then you need to open command prompt in "C:\Users\Milan Adhikari\AppData\Local\Android\Sdk\tools" and run "sdkmanager --update" which will update your sdk and then you need to run "flutter doctor --android-licenses" in cmd and accept all the licenses.
Now your problem should be solved.

Best way is to use below command
$ wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
$ unzip \platform-tools-latest-linux.zip
$ sudo cp platform-tools/adb /usr/bin/adb
$ sudo cp platform-tools/fastboot /usr/bin/fastboot
Now run adb version to verify it’s been updated.

No need to uninstall your other java version(s) that's already installed on your machine. Whenever required, you can conveniently use the utility 'update-alternatives' to choose the Java runtime that you wish to activate. It will automagically update the required symbolic links.
You just need to run the below command and select the version of your choice. That's all!
sudo update-alternatives --config java

As #steven pointed out, install Java 8 (here a link for Ubuntu 16.04, 18.04 and 20.04/20.10 https://computingforgeeks.com/how-to-install-java-8-on-ubuntu/) and then set it as the default Java version with this command:
sudo update-alternatives --config java

Related

macOS - How to install Java 17

Could someone please let me know the steps to install Java on a Mac.
I did brew install java
I get this
Warning: openjdk 17.0.1 is already installed and up-to-date.
To reinstall 17.0.1, run:
brew reinstall openjdk
If I do java -version, I get this.
openjdk version "13.0.8" 2021-07-20
If I have navigate to /Library/Java, I have 2 empty directories.
Where is java 17 installed??
In 2023, even if you can use just brew..
brew install openjdk#17
Java will be installed here:
/usr/local/opt/openjdk#17/bin/java
For the system Java wrappers to find this JDK, symlink it with:
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
...give a try to sdkman, it's far better than brew
curl -s "https://get.sdkman.io" | bash
then open a new shell and try list to see what you could install ;-)
sdk list java
At time of writing you could use:
sdk install java 17.0.4.1-tem
Java will be installed here:
/Users/freedev/.sdkman/candidates/java/17.0.4.1-tem
Java doesn't mind if you install multiple versions. This is often required; java is not backwards compatible (it tries to change little, but e.g. the java8 to java9 transition broke a ton of stuff, much of it needless and much of it not reasonably expectable or fixable by libraries and apps, so a bunch of java apps and libraries only run on java8 - just an example).
So, yes, you have installed JDK17. Also, yes, if you just run java without specifying which one you want, you so happen to get java13 here.
To see all installed javas, you can run:
/usr/libexec/java_home -V
to 'override', you can use something like (depends on which shell you're using on your mac):
export JAVA_HOME=`/usr/libexec/java_home -v 17`
(the backticks mean: Run this then take the output of it and treat that as the 'value' of the expression. here, assign it to the JAVA_HOME env var. -v 17 requests a path to java 17. The -V option lists all and is meant for your eyeballs, not for scripts. The -v option is mostly for scripting, and that's how we're using it here).
JAVA_HOME decides which java is used by some things, but the java you get when you just type java is /usr/bin/java, and that executable is actually just a wrapper that picks a java to run from amongst all installed versions. It uses JAVA_HOME to decide which java to actually run. There are wrappers for all the common commands (javac, too). You can always run e.g. which javac to see what that actually runs; you probably see /usr/bin/javac. Everything in /usr/bin is one of these wrapper thingies that looks at JAVA_HOME and then runs the binary it finds there.
To specify version 17
brew install openjdk#17
Later I add create a link:
sudo ln -sfn /usr/local/opt/openjdk#17/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk-17.jdk
And use jenv to control which java version to use
To used the version installed by homebrew rather than the one installed by the OS you can get detailed information from homebrew by typing
brew info java
Currently it states
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"
For Homebrew, the package that installs the new AdoptOpenJDK is named as temurin. So you need to use below command:
brew install --cask temurin17
If you get any error like temurin cask not available then update brew using below commands:
brew update
brew tap homebrew/cask-versions
To switch quickly between different versions of java add the entries in bashrc as per your jdk versions like:
alias j8="export JAVA_HOME=`/usr/libexec/java_home -v 1.8`; java -version"
alias j17="export JAVA_HOME=`/usr/libexec/java_home -v 17`; java -version"
Steps to install
You asked:
let me know the steps to install Java on a Mac.
Download an installer free-of-cost from vendors such as Adoptium, Azul Systems, Bellsoft, Amazon, Oracle, Microsoft, SAP, and others.
Run installer app.
Quit the installer app when done.
Verify installation by typing on a command-line in Terminal.app:java --version
Delete installer app that you downloaded.
Configure your IDE to use that new Java implementation you installed.
Java location
You asked:
Where is java 17 installed??
/Library/Java/JavaVirtualMachines/
In the Finder, choose Go > Go to Folder, and paste /Library/Java/JavaVirtualMachines/.
Note that this is not the Library folder within your home folder. We are not referring to /Users/your_user_name/Library/…. We are referring to the root Library folder that applies across all the user accounts on this Mac.
You said:
I did brew install java
No need for the Homebrew package manager. If you already enjoy using the brew tool, proceed. But if new to Homebrew, skip it if your only goal is to install Java. Just use an installer for Java as you would for many Mac apps.
JavaFX
You added a tag for javafx.
Be aware that for JavaFX, you have two options:
Include the necessary OpenJFX libraries within your development project and within your final app, or …
Use a JDK that includes the JavaFX/OpenJFX libraries.
At least two vendors provide JDK installers that include the JavaFX/OpenJFX libraries:
Azul Systems (ZuluFX)
Bellsoft (LibericaFX)
This answer is specifically if you use Intellij on a Mac
Within IntelliJ, you can use the IDE to add new JDKs of selected versions from common vendors. Instructions for this are here:
Setup the project JDK
When setting up the JDK, you can either:
Select a pre-existing JDK which has been registered with the IDE OR
Use the Add JDK option to add a new JDK which you previously downloaded and installed using the method outlined in Basil's answer OR
Use the Download JDK option to choose a vendor and version of the JDK that the IDE will automatically download, install and make available for selection.
The JDKs installed by Idea will be located in the same location as outlined in Basil's answer for a manual install /Library/Java/JavaVirtualMachines/.
One common issue is that the version of the JDK registered for the project differs from the default version used in the terminal. This can sometimes mean that the app works when run in Idea, then fails when run in the terminal (or, at least that it is executed against a version of the JDK you didn't expect).
To select the version of the JDK to run in the terminal, configure the Java home setting as outlined in rzwitserloot's answer.
export JAVA_HOME=`/usr/libexec/java_home -v 17`
Also, some tools such as the openjfx maven plugin will not use the java version selected in Idea when executing a call to a JDK tool like jlink, but will instead have their own mechanism for finding a JDK to use (e.g. look at JAVA_HOME or use the Maven toolchains plugin). So it is always good to check the JAVA_HOME variable and ensure that it is set to a reasonable value, both for terminal execution and for effective use of Java development tools that may rely on it.
I think that answers here are not fully out of topic, but from my point of view, my case is exactly the same as that of the author. I had already installed java 8, 11, and 13. All of them resides at:
/Library/Java/JavaVirtualMachines/
Nevertheless when I tried to find the path of JDK 17 it resides:
/usr/local/Cellar/openjdk
I use Mac OS Big Sur and the JDK was installed with homebrew
Brew now supports searching old formulae and allowing you to install a specific version. I'm using Homebrew 3.5.2-117-gb941470
Create a local tap: brew tap-new --no-git local/openjdk
Ask Brew to find the formulae of the version you want: brew extract --version 17.0.2 openjdk local/openjdk
Install Java 17 using your new local tap: brew install openjdk#17.0.2
Link the JDK into the MacOS JVM Dir: sudo ln -sfn /usr/local/opt/openjdk#17.0.2/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk17.0.2.jdk
Check Java 17 is available: /usr/libexec/java_home -V
Set Java Home: export JAVA_HOME=$(/usr/libexec/java_home -v17)
Check current version of Java is correct...
$ java --version
openjdk 17.0.2 2022-01-18
The following method installs Java without the need for any additional tools or package managers.
Go to https://jdk.java.net/17/ and download the latest macOS archive.
Download the latest Adoptium release for the Java 17 branch by going to https://adoptium.net/temurin/releases/ and be sure to select the tar.gz version.
The archive is either for x64 (Intel CPU) or for AArch64 (Apple Silicon / M1 CPU).
Then, open a Terminal, and extract the downloaded archive to the system path for Java virtual machines:
cd Downloads
tar xzf OpenJDK17U-jdk_aarch64_mac_hotspot_17.0.5_8.tar.gz -C /Library/Java/JavaVirtualMachines

How to switch between different java versions in Linux?

I manually installed Java 8 and installed Java 11 via command line (open-jdk). I'm a noob at linux and don't know how to switch between the versions.
I ran the following commands to change the default version.
update-alternatives --config java
Returns:
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
1 /opt/java/jdk1.8.0_211/bin/java 1 manual mode
2 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
And
update-alternatives --config javac
Returns:
There is only one alternative in link group javac (providing /usr/bin/javac): /usr/lib/jvm/java-11-openjdk-amd64/bin/javac
Nothing to configure.
You can use SDKMan which allow us to do the same, SDKMan is a free to use open-sourced tool which helps us to install and manage parallel versions of around 29 Software Development Kits such as Java, Groovy, Scala, Kotlin and Ceylon. Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x.
And it also sets the _HOME and PATH environment variables automatically.
You can install SDKMan by running below commands
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
You can list all versions of Java using
$ sdk list java
And you can install different-different Java versions using sdk install command
e.g.
$ sdk install java 9.0.4-open
$ sdk install java 11.0.2-open
And you can switch between them using sdk use and sdk default commands, You can read more about it on my blog How to Install Multiple Versions of Java on the Same Machine.

Even though JRE 8 is installed on my MAC -" No Java Runtime present,requesting to install " gets displayed in terminal

Even though JRE 8 is installed on my MAC OS Yosemite 10.10.3,while running the Android present in tools in sdk - the error - " No Java Runtime present,requesting to install " gets displayed in terminal- how do i solve this issue?
I wanted to install Xamarin test recorder - after installing they
asked me to install Android sdk
SDK is downloaded in Library/Developer/Xamarin/android-sdk
Now when I run Android present in tools folder - I get the error -
No Java run time
I've installed JRE 8 with get the verified
java version from their site
Can someone please help!!
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 19.
After installing openjdk with brew and runnning brew info openjdk I got this
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
2021 solution
TL;DR
brew install temurin
Details
On an M1 Mac/Apple Silicon (running Big Sur), I had already openjdk installed. As signaled in a previous answer by Mohammed, openjdk is keg-only with brew, and hence requires adding a symlink.
After following this, it solved the No Java Runtime present error, but rJava was complaining about missing libjvm.dylib and that existing libraries were for the wrong architecture:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(jvm, FALSE)
error: unable to load shared object '/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib':
dlopen(/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib, 10):
no suitable image found. Did find:
/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib:
mach-o, but wrong architecture
Installing Eclipse Temurin (previously AdoptOpenJDK) (and removing the previously created symlink in /Library/Java/JavaVirtualMachines/openjdk.jdk) immediately solved both issues seamlessly.
Just run brew install temurin and everything should be OK.
I didn't need the full JDK, I just needed to make JRE work and none of the other answers provided above worked for me.
Maybe it used to work, but now (1st Jul 2018) it isn't working. I just kept getting the error and the pop-up.
I eventually solved this issue by placing the following JAVA_HOME export in ~/.bash_profile:
export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Hope this helps someone.
I'm running Mac OS High Sierra.
I just had to do the following on Mac:
brew install openjdk
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
export JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home"
java --version
If you came across the error when tried to generate a jks file (keystore), so try adding
/Applications/Android\ Studio.app/Contents/jre/Contents/Home/bin/keytool
before running the command, like so:
/Applications/Android\ Studio.app/Contents/jre/Contents/Home/bin/keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Since it sounds like your JAVA_HOME variable is not set correctly, follow the instructions for setting that.
Setting JAVA_HOME environment variable on MAC OSX 10.9
I would imagine once you set this, it will stop complaining.
Maybe someone is still having the same issue. You can install openjdk using homebrew, and then add the new JDK bin directory to the front of your path:
cd ~
brew install openjdk
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> .bash_profile
source .bash_profile
Pre-Requisite:
I already had java11 installed on my machine using brew.
Step-1: brew info java11
output:
/opt/homebrew/Cellar/openjdk#11
USER1-MacBook-Pro JavaVirtualMachines % brew info java11
openjdk#11: stable 11.0.12 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/opt/homebrew/Cellar/openjdk#11/11.0.12 (670 files, 273.0MB)
Poured from bottle on 2021-10-09 at 13:07:04
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk#11.rb
License: GPL-2.0-only
==> Dependencies
Build: autoconf ✔
==> Requirements
Build: Xcode ✘
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk#11 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have openjdk#11 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk#11/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk#11 you may need to set:
export CPPFLAGS="-I/opt/homebrew/opt/openjdk#11/include"
==> Analytics
install: 44,188 (30 days), 149,578 (90 days), 433,845 (365 days)
install-on-request: 19,074 (30 days), 63,262 (90 days), 187,286 (365 days)
build-error: 0 (30 days)
Step-2: Append openJDK path to existing path.
echo 'export PATH="/opt/homebrew/opt/openjdk#11/bin:$PATH"' >> ~/.zshrc
Step-3: Source existing shell or open new terminal to validate changes
source ~/.zshrc
Step-4: Check path is added
which java
output: /opt/homebrew/opt/openjdk#11/bin/java
Step-5:
java --version
openjdk 11.0.12 2021-07-20
OpenJDK Runtime Environment Homebrew (build 11.0.12+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode)
working by following command
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
TL;DR
For JDK 11 try this:
To handle this problem in a clean way, I suggest to use brew and jenv.
For Java 11 follow this 2 steps, first :
JAVA_VERSION=11
brew reinstall jenv
brew reinstall openjdk#${JAVA_VERSION}
jenv add /usr/local/opt/openjdk#${JAVA_VERSION}/
jenv global ${JAVA_VERSION}
And add this at end of your shell config scripts ~/.bashrc or ~/.zshrc
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"
Problem solved!
Then restart your shell and try to execute java -version
Note: If you have this problem, your current JDK version is not existent or misconfigured (or may be you have only JRE).
In 2022:
No need to download Java anymore, once Android Studio is installed.
Even though Java 11 is embedded with Android Studio now, on Mac sometimes this problem arises and the Java runtime is not found.
So, I have solved this problem by doing these two steps:
In Android Studio go to File > Project Structure. If, under the SDK entry, you can see there is no default SDK selected, but a text in red "No SDK", click on it and you will find an SDK / JDK list, select one of them. Thats it.
Make sure you run Android Studio from Application Folder.
For this copy the Android Studio launcher to the Application folder. Then in the Finder, go to the Application folder. Right-click on it. Click on "Show package contents", then navigate up to jre folder. Copy the folder and paste it into your home folder.
Now setup the path from the terminal: you can create a folder named java_jre, and the path must be set to jre/contents/Home :
Noors-Mac-mini:bin noorhossain$ export JAVA_HOME="/Users/noorhossain/java_jre/jre/Contents/Home"
// now checking the version :
Noors-Mac-mini:bin noorhossain$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7772763, mixed mode)
I solved the problem by installing oracle-sdk with brew.
brew install oracle-jdk --cask
In 2022, only if Android studio is installed:
Check if JDK is installed in Android studio. In Android Studio go to File > Project Structure. Under the SDK entry, if there is no default JDK selected, select from the list, or if there isn't any, add JDK and then apply to install.
After the JDK is installed in Android studio, you just need to add the JDK path directly from your Android Studio. Run the below command in the terminal and that's it.
echo 'export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"' >> ~/.zshrc
Now, check if it's working.
❯ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7772763, mixed mode)
No need to install any package from brew or create any symlink. The Java is already embedded with the Android studio and we can use this directly for our system.
In newer versions of OS X (especially Yosemite, EL Capitan), Apple has removed Java support for security reasons.
To fix this you have to do the following.
Download Java for OS X 2015-001 from this link: https://support.apple.com/kb/dl1572?locale=en_US
Mount the disk image file and install Java 6 runtime for OS X.
After this you should not be seeing any of the below messages:
- Unable to find any JVMs matching version "(null)"
- No Java runtime present, try --request to install.
This should resolve the issue for the pop-up shown below:
Below is worked for me on macos mojave 10.14.6 version
I installed current jdk(https://www.oracle.com/java/technologies/javase-downloads.html)
Then do respectively;
vim .bash_profile
add "export JAVA_HOME=$(/usr/libexec/java_home)" to bash_profile
source .bash_profile
it is done. And you can check the version with java -version command.
If you are having this issue for the same reason that I am, I can tell you why it is happening. I just don't know how to fix it yet.
Here it is:
I am using JDK version 1.8 on MacOS Big Sur. I do not want to have to install a later version of the JDK because all my projects run on 1.8. But here's the thing.... On the command line
java -version
Returns this:
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-bre_2021_08_14_21_34-b00)
OpenJDK 64-Bit Server VM (build 25.302-b00, mixed mode)
but a slightly different command (version prefixed with 2 dashes instead of 1)
java --version
returns this error:
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
This is because Java 8 uses single dash version, all JDKs after use double dash.
So the machine, when looking for JAVA_HOME, is also using double dashes and getting the error.
just run this
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
I have Mojave 10.14.6 and the only thing that did work for me was:
setting JAVA_HOME to the following:
export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
source .bash_profile (or wherever you keep your vars, in my case .zshrc)
Hope it helps! You can now type java --version and it should work
It's worth noting that with my current version of SQLDeveloper (21.2.1), there's another way to specify the JDK location. In my case, I was able to open up ~/.sqldeveloper/21.2.1/product.conf and set the JavaHome directive to the appropriate directory. I use jabba for JDK version management, and this path was something like ~/.jabba/jdk/amazon-corretto#1.8.292-10.1/Contents/Home. Needless to say, just setting that config value and restarting SQLDeveloper left me with a running copy again. This should work with any version of SQLDeveloper given the product.conf file exists inside your user's .sqldeveloper directory appropriate for the version you are using.
install JDK it will work ,
here is the jdk link to download .
link: https://www.oracle.com/technetwork/java/javase/downloads/jdk13-downloads-
5672538.html

Java Virtual Machine Launcher error [duplicate]

This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 6 years ago.
Pictures:
Command Prompt showing versions
Picture of error
Hello.java
import java.applet.Applet;
import java.awt.*;
public class Hello extends Applet {
// Java applet to draw "Hello World"
public void paint (Graphics page) {
page.drawString ("Hello World!", 50, 50);
}
}
Hello.html
<HTML>
<HEAD>
<TITLE>HelloWorld Applet</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Hello.class" WIDTH=300 HEIGHT=150>
</APPLET>
</BODY>
</HTML>
Error
Hello : Unsupported major.minor version 52.0
What may the problem be?
The issue is because of Java version mismatch. Referring to the JVM specification the following are the major versions of classfiles for use with different versions of Java. (As of now, all versions support all previous versions.)
Java SE version
Major version
1.0.2
45
1.1
45 (Not a typo, same version)
1.2
46
1.3
47
1.4
48
5.0
49
6
50
7
51
8
52
9
53
10
54
11
55
12
56
13
57
14
58
15
59
16
60
These are the assigned major numbers. The error regarding the unsupported major.minor version is because during compile time you are using a higher JDK and a lower JDK during runtime.
Thus, the 'major.minor version 52.0' error is possibly because the jar was compiled in JDK 1.8, but you are trying to run it using a JDK 1.7 environment. The reported number is the required number, not the number you are using. To solve this, it's always better to have the JDK and JRE pointed to the same version.
In IntelliJ IDEA,
Go to Maven Settings → Maven → Importing. Set the JDK for importer to 1.8.
Go to Maven Settings → Maven → Runner. Set the JRE to 1.8.
Go to menu File* → Project Structure → SDKs. Make sure the JDK home path is set to 1.8.
Restart IntelliJ IDEA.
Another approach which might help is by instructing IntelliJ IDEA which JDK version to start up with.
Go to: /Applications/IntelliJ\ IDEA\ 15\ CE.app/Contents/Info.plist
and replace the JVM version with:
<key>JVMVersion</key>
<string>1.8*</string>
The smart way to fix that problem is to compile using the latest SDK and use the cross compilation options when compiling. To use the options completely correctly requires the rt.jar of a JRE (not JDK) of the target version.
Given the nature of that applet, it looks like it could be compiled for use with Java 1.1 meaning you'd use javac -target 1.1.
You will need to change your compiler compliance level back to 1.7 in your IDE.
This can be done in the preferences settings of your IDE. For example, in Eclipse go to menu Windows → Preferences, select Java, and expand it. Then select Compiler and change the compliance level to 1.7. I am sure this will work from there.
You must run and compile your application with the same version of Java.
If you're using Eclipse you should do 2 things:
In Eclipse, click on "Window > Preferences", and in the window that appears, on the left side, under "Java", click on "Installed JREs", click on "Add..." and navigate to the folder that contains the JDK.
Right-click on your project and click on "Properties", in the window that appears, on the left side, click on "Java Compiler" and uncheck "Use compliance from execution environment on the Java Build Path", this allows you to choose in the the list "Compiler compilance level" the same version that you set in the previous step.
You need to upgrade your Java version to Java 8.
Download latest Java archive
Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from the shell.
For 64 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.tar.gz"
# tar xzf jdk-8u51-linux-x64.tar.gz
For 32 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-i586.tar.gz"
# tar xzf jdk-8u51-linux-i586.tar.gz
Note: If the above wget command doesn’t not work for you, watch this example video to download the Java source archive using the terminal.
Install Java with alternatives
After extracting the archive file, use the alternatives command to install it. The alternatives command is available in the chkconfig package.
# cd /opt/jdk1.8.0_51/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_51/bin/java 2
# alternatives --config java
At this point Java 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives:
# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_51/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_51/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_51/bin/jar
# alternatives --set javac /opt/jdk1.8.0_51/bin/javac
Check installed Java version
Check the installed version of Java using the following command.
root#tecadmin ~# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Configuring Environment Variables
Most of Java-based applications use environment variables to work. Set the Java environment variables using the following commands:
Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.8.0_51
Setup JRE_HOME Variable
# export JRE_HOME=$JAVA_HOME/jre
Setup PATH Variable
# export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
Note that the change to the PATH variable put the new Java bin folders first so that they override any existing java/bins in the path. It is a bit sloppy to leave two java/bin folders in your path so you should be advised to clean those up as a separate task.
Also, put all above environment variables in the /etc/environment file for auto loading on system boot.
I had the same problem... a JDK and plug-in version conflict.
I compiled using 1.8 ... the latest one, and that message started to appear.
So I've searched for the JRE 7 (http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html)... and installed it... again...
Now 1.8 and 1.7 in the same computer.
Using NetBeans, and compiling, and targeting to version 1.7, fixed my problem.
If you have a problem in Android Studio and you have installed Android N, change the Android rendering version with an older one and the problem will disappear.
If you're using the NetBeans IDE, right click on the project and choose Properties and go to sources, and you can change the Source/Binary Format to a lower JDK version.
Unsupported major.minor version 52.0 comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program.
Read more: http://javarevisited.blogspot.com/2015/05/fixing-unsupported-majorminor-version.html#ixzz4AVD4Evgv
It happens when you compile your projects on higher version of java(say jdk 1.8) and then run it on a lower version (say jdk 1.7).
If you have JRE-1.7 library in your project path then ,
1.Right click on project
2.Go to Properties
3.Select Project Facets
4.Find Java in rows and then choose version (say 1.7) if using JRE-1.7
5.Click Apply and run your project.
I solved my problem by removing old versions of JRE and installing JRE 8.
I could solve the same problem using the below solution.
In my project, I added a JAR file which were created in Java 8. And my project was referring to JRE 7. When I changed project JRE to 8, my problem was solved.
Steps:
In Eclipse, right click on the project name in project explorer → Build path → Libraries → click on JRE version → click Edit → Installed JRE → Add → Standerd VM → select JRE home click-path (path should be localePath\java\jdk1.8.0_25\jre) → provide name → Save → select same JRE for project → Finish → OK. Refresh/build project once → try to run your Java file. It should work.
I had Java 1.7 & 1.8 installed (with SBT 2.4 that requires Java 1.8).
Even though my project was linked to Java 1.8, I had to change the JAVA_HOME environment variable to point 1.8.
Finally, problem solved.
If you are using Eclipse, make sure your menu Project → Properties → Java build path → libraries → JRE system library matches your project requirements (as shown in the image).
All you need to do to solve the problem is... to make sure your version of Java is the same for both compiling and running. No matter what tools or IDEs you are using.
If you are using Linux and you have different versions of Java installed, use the following command:
sudo update-alternatives --config java
This will give a quick way of switching between the Java versions installed on the system. By choosing Java 8 I will solve your problem.
This occurred to me when I installed a fresh Java 1.8, but left the old command line interpreter open.
It had an old path and kept on executing the application with Java 1.7 whereas project was already built with Java 1.8.
If your JDK version is right. Another reason that may cause this error is that your Android Studio is in a low version, but your Gradle version is too high. Upgrade your IDE to a newer version may help this.
Upgrade your Andorra version to JDK 1.8.
This is a version mismatch that your compiler is looking for Java version 8 and you have Java version 7.
You can run an app build in version 7 in version 8, but you can't do vice versa because when it comes to higher levels, versions are embedded with more features, enhancements rather than previous versions.
Download JDK version from this link
And set your JDK path for this
You need to use JDK 1.7.0 rather than JDK 1.8.0.
To make sure it, you need to delete JDK 1.8.0 on your computer.
If you use Mac, you need to delete:
/Library/Java/JavaVirtualMachines/jdk.jdk
/Library/PreferencePanes/JavaControlPanel.prefPane
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin
Then, you need to reinstall JDK 1.7.0, and you will succeed to generate the .jar file.
You may want to check your Run Configurations setting if you're using Eclipse v4.4 (Luna) and have already completed all steps mentioned above.
There could be several possibilities that cause this error. The root cause is a mismatch of the project require compilation in JDK1.8/JRE8 while the environment compiler is JDK1.7/JRE7.
You can check my blog post to go through all your settings are correct.
None of these answers helped me, but I found a solution.
I had a webproject used in Wildfly 8.2, built with Maven, source and target was set to 1.8 on maven-compiler-plugin, as well as all Eclipse and Maven settings were set to Java 1.8.
The problem was that Wildfly 8.2 cannot handle Java 1.8, so I had to set everything to 1.7 and it worked.
Just want to add this. I had this problem today. Adjusted the settings in my project, rebuilt, and same problem. I had (incorrectly) assumed that changing the settings in my project (Eclipse) would cause the projects on which my project depends to be recompiled also.
Adjusting the settings to all of the projects up the dependency tree solved the problem.
Just go to http://java.com/en/download/ and update your version of JRE
If you are using IntelliJ IDEA, go to Project Structure (Ctrl + Alt + Shift + S), and you can change your project's JDK.
I ran into this issue in Eclipse on Mac OS X v10.9 (Mavericks). I tried many answers on Stack Overflow ... finally, after a full day I *installed a fresh version of the Android SDK (and updated Eclipse, menu Project → Properties → Android to use the new path)*.
I had to get SDK updates, but only pulling down those updates I thought were necessary, avoiding APIs I were not working with (like Wear and TV) .. and that did the trick. Apparently, it seems I had corrupted my SDK somewhere along the way.
BTW .. I did see the error re-surface with one project in my workspace, but it seemed related to an import of appcompat-7, which I was not using. After rm-ing that project, so far haven't seen the issue resurface.

OS X Yosemite not finding Java 8 runtime

I installed Java 8 SDK (with update 25 for JRE) from the Oracle Java site using the instructions on this page
http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html
and put the following line in my ~/.bash_profile
export JAVA_HOME="/usr/libexec/java_home -v 1.8"
but when I try to compile or run a Java program in Bash I get the following message
No Java runtime present, requesting install.
and this window
I ran /usr/libexec/java_home to check:
$ /usr/libexec/java_home
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
But the JRE is in
/System/Library/Frameworks/JavaVM.framework/Versions/Current
and the JRE location in System Preferences is pointing to
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin
I don't know what the problem is here, but usr/bin/javac and /usr/bin/java are not able to find the correct JVM location in /System/Library/Frameworks/JavaVM.framework/Versions/Current.
I have encountered the same problem , i think you should install JDK but not JRE
You need to add some backticks:
export JAVA_HOME="`/usr/libexec/java_home -v 1.8`"
The /usr/libexec/java_home command outputs the right value for JAVA_HOME on its standard output, you need to use backticks to capture that value so you can store it in the variable.
But the JRE is in /System/Library/Frameworks/JavaVM.framework/Versions/Current
No, it isn't. The Oracle JRE installs itself under /Library/Internet Plug-Ins, the Oracle JDK installs under /Library/Java/JavaVirtualMachines. The binaries under /usr/bin and /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands are stubs that delegate to whichever JDK your JAVA_HOME variable points to.
Here's how I solved my problem on my mac
Check from RStudio if Java_HOME has been setup properly by running Sys.getenv("JAVA_HOME") in the console. If it returns blank, you need to set it up properly
Check whether you have Java SDK installed
Open terminal and check if you have Java SDK installed
Run the /usr/libexec/java_home -vcommand. This will show you the library where you Java SDK is installed.
If you don't have Java SDK installed yet, result from command above is blank, or the version is not up-to-date, download here and install the latest version.
Copy the library shown in step 2. On my mac, it shows:
/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home
Back on your RStudio console, set the JAVA_HOME
Sys.setenv(JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home")
After doing the steps above, h2o.init() ran without hitch.
Please carefully note #Ian Robert's point on JRE vs JDK distinction. We need JDK to make h2o run.
I've tried several solutions, downloading several sdk but Android Studio didn't recognize them as valid sdks.
Finally, the workaround that worked for me was:
Delete Android Studio.app and Android Studio preferences (~/Library/Preferences/AndroidStuido).
Rename /usr/libexec/java_home to java_home.bak.
Install again Android Stuido.
When Android Studio prompts for a valid Java SDK, follow link provided by Android Studio and download that java installation.
After installation, push detect button on Android Studio, and run.

Categories