Reputation: 616
I have a simple Java program that consists of two .java
files. It runs fine when executed from my IDE (IntelliJ). It also compiles (via the javac
utility) just fine. However, when I attempt to run it from the Windows command prompt (using java <<myClassName>>
) I get this error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=RunExport, offset=6
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:364)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:154)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:777)
at java.net.URLClassLoader.access$400(URLClassLoader.java:96)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1225)
at java.security.AccessController.doPrivileged(AccessController.java:366)
at java.net.URLClassLoader.findClass(URLClassLoader.java:660)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:942)
at java.lang.ClassLoader.loadClass(ClassLoader.java:851)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:827)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:494)
I have read various questions and proposed solutions for this error, but I have not been able to solve it. It appears that the version of Java used to compile the code is not recognized as being the same as that of the JRE in which I am running it. I am using jdk1.8.0_91
. The javac.exe
and java.exe
files I am using are both in C:\Program Files\Java\jdk1.8.0_91\bin
. This is also the path defined in my Windows PATH
environment variable.
Upvotes: 2
Views: 8024
Reputation: 9093
This error means you are compiling and running with different, incompatible versions of Java.
Do java -version
and javac -version
to find out what versions these commands are actually using.
Then, to fix the version, you have three options:
Change which version of Java is used through the Java control panel.
Change which version of Java is used by editing your PATH environment variable. The path to your desired Java version should come before the path to any other Java versions.
If neither of these seems to work, or if this is a one-time use, you can simply specify the full path when running/compiling your program:
C:\Program Files\Java\jdk1.8.0_91\bin\java.exe
This material taken from comments by Carlos Heuberger
Upvotes: 3
Reputation: 57
It is possible that your IntelliJ is referring to default JRE. Go through this link https://www.jetbrains.com/help/idea/2017.1/defining-a-jdk-and-a-mobile-sdk-in-intellij-idea.html to setup intelliJ. Ensure is points to the JRE configured as your path.
Upvotes: -1