Error after upgrading to JDK 8 on MAC - java

After upgrading to JDK 8 on Mac, I get the following error when I try and check the java version. Can anyone help me sort it out?
MAC30880443:Versions t821714$ java -version
Error occurred during initialization of VM
java/lang/ClassNotFoundException: error in opening JAR file <Zip file open error> /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/endorsed/jaxb-api-2.2.12.jar

It would appear as if the new JDK got installed, however your JAVA_HOME environmental variable appears to be either unset, or still set to use JDK 7.
To check its current value, you can execute echo $JAVA_HOME
To update the value for your current terminal session, you can execute export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home.
If you want the above snippet to run every time you start a new terminal session, you can enter the following, which will append it to your .profile
echo "export /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home" >> ~/.profile
. ~/.profile
The second line will source that .profile line to load the variables set in it.
Cheers, and happy coding.

Looks like your java PATH is messed up, setting it varies based on OS version so take a look here and make sure it is set properly.
if you are running os 10+ all you have to do is
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
or if you think you know better than apple and are sure your java_home is in the default location, use:
echo "export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home" >> ~/.bash_profile
then do
source ~/.bash_profile
also make sure java 8 is set in the top of your preferences. (Utilities -> Java Preferences -> General). Click and drag it to the top of the list if it is not there, otherwise you might continue to use the older version of java

Related

ERROR: JAVA_HOME is set to an invalid directory: Please set the JAVA_HOME variable in your environment to match the location of your Java installation

When I was running "flutter doctor --android-licenses", I struggled to fix the error below,
ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-11-openjdk-amd64
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
I thought I should post this as a question and provide a response to it as other Answers to the this question could not help me.
Please see my solution below.
run the below command to choose the java version that you want to use.
sudo update-alternatives --config java
You will get something like this from the terminal.
Press the number corresponding to the version of java that you want to use.
Example,
Press to keep the current choice[*], or type selection number: 0
Copy the PATH corresponding to the java version that you chose. In my case since I
chose version in Number 0,
My PATH is /usr/lib/jvm/java-11-openjdk-amd64/bin/java.
But leave out the last part of the PATH,i.e "/bin/java".
So now your PATH is /usr/lib/jvm/java-11-openjdk-amd64
run the following command, where PATH value is the value copied from above.
export JAVA_HOME=PATH
In my case, I will run
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
run this command, copy it as it is. Don't change anything.
echo $JAVA_HOME
follow by this command, copy it as it is. Don't change anything.
export PATH=$PATH:$JAVA_HOME/bin
run this command,
echo $PATH
This will give out the full path to your $JAVA_HOME value.
In my case, this is what I got.
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
:/usr/lib/jvm/java-11-openjdk-amd64/bin
Now you are sorted.
"flutter doctor --android-licenses", ran successfully.

Setting Java Environment Variables for Talend

I'm loading Talend on my mac and I'm trying to set the Java environment variables.
Talend says to set the path based on this:
export JAVA_HOME=/usr/lib/jvm/jre1.8.0_65
export PATH=$JAVA_HOME/bin:$PATH
I have several issues:
It says I should base the 1st export on where my Java is installed which is
/usr/lib/JavaVirtualMachine/jdk1.8.0_144. I'm assuming path should be exact - so no "jvm"? Also assume my jdk is correct since that is what I have.
When i set the variable how do I know it takes? I've played with it and then I use printenv but I never see what I enter.
To set this perm (when I know the path) do I open terminal and enter it like this?
export JAVA_HOME=/usr/lib/jvm/jre1.8.0_65 ~/ .profile
Thanks - New to this and trying to do a little development
You don't need an exact path.
Let java tell you where is it running from
export JAVA_HOME=`/usr/libexec/java_home`
how do I know it takes?
You need to first source ~/.profile if you added it there, then you can echo $JAVA_HOME

How to set JAVA_HOME environment variable on Mac OS X 10.9?

I just purchased a brand new MacBook Pro.
This is my first MAC ever and I'm still trying to get the hang of navigating my way around.
Anyway, I'm also new to Java and I've been practicing on my Windows PC before it permanently died.
Now that I'm on this MAC, I installed my JDK and now I need to set the JAVA_HOME environment variable.
I have no idea what to do.
I tried following some of these guides and didn't get very far.
Mkyong.com : How to set JAVA_HOME variable in Mac OSX
YouTube : How to set environment variables on mac, linux, solaris, rhel
YouTube : How to Set Environment Variables in Mac
I was able to locate the terminal and I think I created some multiple files. I'm getting messages like this:
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /Users/Erwin/.bash_profile"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/Users/Erwin/.bash_profile.sw p"
to avoid this message.
Can somebody tell how to set Java in Mac OSX environment step by step?
If you're using bash, all you have to do is:
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
If you're using zsh (which probably means you're running macOS Catalina or newer), then it should instead be:
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.zshrc
In either case, restart your shell.
If you have multiple JDK versions installed and you want it to be a specific one, you can use the -v flag to java_home like so:
echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" >> ~/.bash_profile
I just spent 2 hours setting this variable. The other answers did not work properly for me. I'm using macOS Catalina 10.15.4.
First, find your actual Java SDK Home directory:
/usr/libexec/java_home
Manually navigate there to make sure you don't have any mistakes due to incorrect versions, etc. For me, this was:
/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
Next, edit your terminal's profile. If you're using zsh, this will be:
vim ~/.zshrc
If you're not using zsh, this will be:
vim ~/.bash_profile
Inside, add the following new line anywhere in the file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
Restart your terminal app (or source ~/.bash_profile), and it should work properly.
I did it by putting
export JAVA_HOME=`/usr/libexec/java_home`
(backtics) in my .bashrc. See my comment on Adrian's answer.
Set $JAVA_HOME environment variable on latest or older Mac OSX.
Download & Install install JDK
First, install JDK
Open terminal check java version
$ java -version
Set JAVA_HOME environment variable
Open .zprofile file
$ open -t .zprofile
Or create . zprofile file
$ open -t .zprofile
write in .zprofile
export JAVA_HOME=$(/usr/libexec/java_home)
Save .zprofile and close the bash file & then write in the terminal for work perfectly.
$ source .zprofile
Setup test in terminal
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/. bash_profile or ~/.profile.
Open the terminal and run the below command.
$ vim .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
save and exit from vim editor, then run the source command on .bash_profile
$ source .bash_profile
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
It is recommended to check default terminal shell before set JAVA_HOME environment variable, via following commands:
$ echo $SHELL
/bin/bash
If your default terminal is /bin/bash (Bash), then you should use #Adrian Petrescu method.
If your default terminal is /bin/zsh (Z Shell), then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
If you are using Zsh, then try to add this line in ~/.zshrc file & restart terminal.
export JAVA_HOME=$(/usr/libexec/java_home)
I got it working by adding to ~/.profile. Somehow after updating to El Capitan beta, it didnt work even though JAVA_HOME was defined in .bash_profile.
If there are any El Capitan beta users, try adding to .profile
Since I'm using openjdk managed with sdkman, I added
sudo ln -sfn /path/to/my/installed/jdk/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Adding this to your system lets java_home recognize your installed version of Java even when its not installed via standard packages
I checked my /Library/Java/JavaVirtualMachines/
directory and found the version to be jdk1.8.0_321.jdk/Contents/Home
and added this directly to my .bash_profile:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home
but it's still complaining after sourcing the .bash_profile:The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt.
In the latest Mac, you have to add the Set $JAVA_HOME environment variable in .zprofile. Here, we simple way to open it. Press ⌘ + Shift + . from keyboard. Just open it and add the $JAVA_HOME environment variable as explained here:
JAVA 11 via Homebrew - tested on macos Ventura 2022
.zshrc
export JAVA_HOME=/opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk/Contents/Home
For Mac M1
Download & Install install JDK
Open terminal check java version
java -version
Now create a file
touch .zprofile
Open the file
open -t .zprofile
Add the below line
export JAVA_HOME=$(/usr/libexec/java_home)
I resolved it on macOS Monterey by using the option provided by Google
Under Gradle JDK, choose the Embedded JDK option.
https://developer.android.com/studio/intro/studio-config#:~:text=A%20copy%20of%20the%20latest,use%20for%20your%20Android%20projects.
I'm able to solve this issue by setting JAVA_HOME in .bash_profile file
export JAVA_HOME=/usr/local/opt/openjdk#17
Note:
I installed openjdk version 17 using 'brew'. I got this location from brew console. I'm using 'bash' instead of 'zsh' in my mac.
Open Terminal.
Confirm you have JDK by typing “which java”. ...
Check you have the needed version of Java, by typing
“java -version”.
Set JAVA_HOME using this command in Terminal: export
JAVA_HOME=/Library/Java/Home.
echo $JAVA_HOME on Terminal to confirm
the path.
More simply on a mac terminal with a modern OSX
$ vim ~/.zshrc
Type "a" to being editing, and then paste (ctrl + v):
$ JAVA_HOME=/usr/libexec/java_home
then hit "escape" and type exactly ":wq" in order to write to the file and quit vim mode.
Finally, when out of vim mode and back in your terminal, type
$ source ~/.zshrc
This will refresh so that your terminal is aware of the changes.
IMPORTANT * If you don't "source" the file, you won't see the changes in this terminal session.
Check the changes by typing
$ echo $JAVA_HOME
and you should see /usr/libexec/java_home
Quick Guide for M1
Add java sdk into your m1
check version
java --version
Get all java versions installed in ur mac
/usr/libexec/java_home -V
Execute for Java path from library
/usr/libexec/java_home
(specify java version if you have multiple version, In my case -v17.0.5
/usr/libexec/java_home -v17.0.5
Mac>User>'YourUserName/Home'>.zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.5.jdk/Contents/Home

JAVA_HOME error in Titanium Studio on Linux Mint

I will try and keep this as concise as possible since I need to get this figured out quickly. Back when I setup Titanium Studio 2.1.1.201207271312 on Linux Mint 13 64-bit system, I had all kinds of problems installing a version of Java Titanium liked. In the end I Think I used the instructions here to get it working.
Now all these months later when I try to compile an app for Google Play I get this dreaded error:
[ERROR] Program launch failed. Unable to locate Java VM. Please set JAVA_HOMenvironment variable.
[ERROR] Unabled to prepare JavaScript for packaging. Error code 4.
Checking the java alteranatives on my system I get this:
'update-alternatives --query java
Link: java
Status: auto
Best: /usr/lib/jvm/java-6-sun/jre/bin/java
Value: /usr/lib/jvm/java-6-sun/jre/bin/java
Alternative: /usr/lib/jvm/java-6-sun/jre/bin/java
Priority: 63
Slaves:
java.1.gz /usr/lib/jvm/java-6-sun/jre/man/man1/java.1.gz
Alternative: /usr/lib/jvm/java-7-oracle/bin/java
Priority: 1
Slaves:
java.1.gz /usr/lib/jvm/java-7-oracle/man/man1/java.1.gz
I have the following set in my .profile
export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre/bin/java
export PATH=$PATH:/usr/lib/jvm/java-6-sun/jre/bin/java
But still I get the error in Titanium. I have tried numerous different variations of my .profile file, but with no luck.
I really need to work this out quickly. Does anyone have any ideas?
EDIT: Solved
I seem to have worked the proper paths, here is how my .profile now reads:
JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export JAVA_HOME
PATH=$PATH:/usr/lib/jvm/java-6-sun
export PATH
.profile is usually processed by sh, while .bash_profile is processed by bash (and instead of .profile when present). Try following sh compatible format (which has bitten me before when mucking with .profile files):
JAVA_HOME=/usr/lib/jvm/java-6-sun
export JAVA_HOME
PATH=$PATH:/usr/lib/jvm/java-6-sun/bin:/usr/lib/jvm/java-6-sun/jre/bin
export PATH
I Corrected to what I usually use, I was just echoing your values, but I should have been more careful. I usually have JDK and JAVA_HOME is supposed to be the base for it and then I add bin for both JDK and JRE. If you compiling then you may need the JDK and not just the JRE.
I seem to have worked out the proper paths, here is how my .profile now reads:
JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export JAVA_HOME
PATH=$PATH:/usr/lib/jvm/java-6-sun
export PATH

Permanently removing a JAVA_TOOL_OPTIONS environment variable

I am trying to run jake on OS X 10.6.4 but get the message Narwhal on Rhino requires Java 1.5 or higher. You have JAVA_TOOL_OPTIONS:.-Xmx512m. This is left over from a previous project where someone told me to set it to get Flash to export without dying.
I have java 1.6 installed. The JAVA_TOOL_OPTIONS seems to be the issue. I removed it using unset JAVA_TOOL_OPTIONS. This worked until I reopened Terminal. The JAVA_TOOL_OPTIONS environment variable comes back.
Any ideas on how I can permanently get rid of this?
You probably set it in the .bashrc or .profile file in your homedirectory, remove it from there and you should be fine when you start a new terminal.
It seems like you have that variable in your environment. All you need to do is to remove it from env:
Just write unset JAVA_TOOL_OPTIONS in your terminal.
Set that line in the ~/.bashrc file to be sure that it will not abuse you next time you run console.

Categories

Resources