Supporting Your Unsupported Class Version Error [Code Snippet]
Here's a quick fix if you're running into the UnsupportedClassVersionError. It could be as simple as making sure your PATH variable is playing nicely with JAVA_Home.
Join the DZone community and get the full member experience.
Join For FreeThis article covers how to fix Java errors akin to UnsupportedClassVersionError. Please feel free to comment/suggest if I missed something.
How to Reproduce the Error
- Set JAVA_HOME with one version of Java. Include a “bin” of different Java versions in the PATH variable.
- Compile the class, for example HelloWorld.java, with “javac”.
- Start the JVM with following class: “java HelloWorld”.
With the steps above, you might see an error like:
java.lang.UnsupportedClassVersionError: HelloWorld : Unsupported major.minor ver
sion 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
I set the JAVA_HOME for jdk 8.* and set the jdk7.* in PATH.
Basically, you want to make sure that same version is set as JAVA_HOME as it's included in the PATH variable (%JAVA_HOME%/bin). That should fix your problem!
Published at DZone with permission of Ajitesh Kumar, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments