I have downloaded Java on mac mavericks system. But when I type on terminal to see the Java version using command:
java version
I get the following error
Could not find or load main class version
I went to oracle website and tried a check to see if Java is installed on my system,which confirmed the Java7 is installed on the system. But why can I not see version in terminal?
Try
java -version
Without the minus sign it is trying to load a program called version.
java –version
will cause the same error (copied from webpage) as "–" is an em dash
java -version is the command to check java version
Download latest Java SE from Oracle site and install it. Then reopen cmd and check java version using java -version.
Set the Java path to bin and check it's version also. Both java and javac should be on same version.
In my case:
C:\Users\darshan>java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
C:\Users\darshan>javac -version
javac 1.8.0_121
Related
I have recently been writing some Java programs on my Windows computer. I have been trying to use java -jar to run compiled jars in order to see errors more clearly, but when I try to do this, I get the following error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/company/app/GUI has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0
This obviously means that my java version is outdated. However, when I took a look at the Java Updater, it shows that I am running the latest version.
Running java -version shows this:
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) Client VM (build 25.261-b12, mixed mode)
So why is Command Prompt using an older version, and how do I change it?
Thank you for your help.
This error clearly indicates that you try to run a .jar file built with JDK 13 (major version 57) on a JRE/JDK 8 (major version 52) which is provided in PATH setting and thus invoked when running java -jar / java -version commands.
If you have JDK 13 installed on your machine, you need to check environment variable PATH and/or JAVA_HOME:
C:\Users\hp1>echo %JAVA_HOME%
C:\Java\jdk-13.0.2
C:\Users\hp1>echo %PATH%
C:\Windows\system32;C:\Java\jdk-13.0.2\bin
C:\Users\hp1>java -version
openjdk version "13.0.2" 2020-01-14
OpenJDK Runtime Environment (build 13.0.2+8)
OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
If PATH refers JRE/JDK 8, you may create another variable and update PATH (copy non-java paths):
>set JAVA_13=**path_to_your_jdk_13**
>set PATH=C:\Windows\system32;%JAVA_13%\bin
If you do not have JDK 13 on your machine, to resolve this issue you should rebuild the .jar file to make it compatible with JDK 8 providing that the code is not using any features from the newer versions.
I installed the latest version of Java and when I try to run eclipse it says:
Version 1.6.0_65 of the JVM is not suitable for this product. Version: 1.8 or greater is required.
I searched many forums and found the java -version command. When I run from the terminal I get:
java version "1.6.0_65" Java(TM) SE Runtime Environment (build
1.6.0_65-b14-466.1-11M4716) Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
But when I open Java on my system preferences it says I have 1.8.
Why? What do I do?
It says 1.6 because it is the pre-installed version in your system. But in order to install different version of Java, you need to install the latest development kit from Oracle's website i.e. http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
I downloaded Eclipse Luna and ran from the terminal in Mac OS X:
> /Applications/Eclipse.app/Contents/MacOS/eclipse
JavaVM: requested Java version (1.8.0) not available. Using Java at "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home" instead.
However, I have:
> java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
What am I doing wrong?
Luna seems currently having a bug: it installs the wrong Java version as its own dependency and then fails claiming that version is wrong.
You need to install Java separately (download official SDK from Oracle website) and make that one default. Be sure you install SDK and not the web plugin. Type java -version to verify the version and then which java to tell the exact path. Edit eclipse.ini as usual and set there the correct path to Java executable.
I upgraded java on my osx 10.9.4 machine using the suggested method from the java web site
It successfully updated, but when trying to run Eclipse I get an error:
Version 1.6.0_65 of the JVM is not suitable for this product.
Version 1.7 or greater is required.
When I access java settings through the applet in the control panel, it shows Java 7 Update 65, but when I type java -version in the console, it shows 1.6.0_65 (response shown below):
| => java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
As far as I know, there is only one java on the box. "which java" returns /usr/bin/java and type -a java returns only /usr/bin/java also. /usr/bin/java is obviously the older version, but I'd like to use the updated one. Can someone please tell me how to update the /usr/bin/java version and/or how to link the applet version so that Eclipse will use the updated one?
Take a look at oracle documentation here:
http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html
It says:
To run a different version of Java, either specify the full path, or
use the java_home tool:
/usr/libexec/java_home -v 1.7.0_06 --exec javac -version
The /usr/libexec/java_home is a link to your jdk directory that should be located under:
/Library/Java/JavaVirtualMachines/jdk<major>.<minor>.<macro[_update]>.jdk
I think your java_home link is pointing to your jdk6. You can check it doing a ls -l /usr/libexec/
I've recently installed netbeans 7.3 on my Mac (Lion 10.7.5, up-to-date).
At the command line, I would get:
[129]$java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06-451-11M4406)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01-451, mixed mode)
Today I went to the netbeans plugin window and found 18 updates to install. When I attempted to do this, I received a message that some of them require > Java 1.7, and I only have 1.6 (as indicated above). So I dutifully ran out to java.com and downloaded Java 1.7 Update 21 successfully.
When I run a Java version checker in various browsers I see a report that Java 1.7.0_21 is the installed version. In addition, the Mac's Java Control Panel also indicates that 1.7.0_21-b12 is the current version.
However, upon restarting netbeans, it still has the same complaint that Java 1.6 is in use. I've rebooted the machine and get the same result. And, the result of 'java -version' at the command line also still shows the same result as above (1.6.0_45).
And, finally, even if I try something like:
/usr/libexec/java_home -v 1.7.0_21 --exec java -version
I get:
Unable to find any JVMs matching version "1.7.0_21"
I'm baffled. Does anybody have any advice on this?
Thanks.
Doug
netbeans will be using it's own version of the the JDK try this
where-can-i-set-the-jre-jdk-which-is-used-to-run-netbeans-besides-the-command-line