Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error after upgrading to JDK 8 on MAC

Tags:

java

macos

java-8

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
like image 313
Leo Farmer Avatar asked Dec 05 '25 21:12

Leo Farmer


2 Answers

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.

like image 168
Matt Clark Avatar answered Dec 08 '25 12:12

Matt Clark


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

like image 22
Epicblood Avatar answered Dec 08 '25 12:12

Epicblood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!