Reputation: 7900
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
Upvotes: 3
Views: 1062
Reputation: 28609
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.
Upvotes: 3
Reputation: 1177
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
Upvotes: 2