Enviroment :
i. OS: Windows
ii. IDE: Eclipse Luna
Exception Message:
Exception in thread "main" java.lang.UnsupportedClassVersionError: xxxxx/Main : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
The root cause of this problem is due to the creation of the java project is in IDE with Java 8 (jre8 or jdk1.8). But the project maybe later imported into another IDE with Java 7 (jre7 or jdk1.7). This cause the mismatch of the java compiler version.
In order to solve this. Several things need to be in place.
- Ensure you have Eclipse support Java 8. I know Eclipse Luna and above support Java 8. I'm not sure about the other Eclipse. You to find out.
- Ensure you have install jdk1.8 or jre8 in your PC. You can download from Oracle.
- If you're not sure about whether you have installed before, you can run the javac command in your console.
- You can also check the Environment variable of your Java_Home by right click on [Computer]->[Advanced system settings]->[Advanced] [Environment Variables]. Check the JAVA_HOME
- Make sure you path your JAVA_HOME.
- Now switch back to your Eclipse IDE.
- Goto [Windows]->[Preferences]->[Java]->[Compiler]. Ensure you select the JDK1.8 and also checked on the [Installed JREs]
- If you're running Maven project. Ensure you configure your Maven to built for JDK1.8/JRE8.
- NOTE: If you're running standalone application, ensure your [RUN CONFIGURATIONS]->[JRE] is using the correct Runtime JRE. I realized that the it won't changed automatically eventhough we have insalled the JRE8.
- Hope either one of the steps help you solving your Unsupported major.minor version 52.0 exception.
No comments:
Post a Comment