Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnsupportedClassVersionError unsupported major.minor version 51.0 unable to load class [duplicate]

Tags:

java

tomcat

war

Possible Duplicate:
Exception in thread “main” java.lang.UnsupportedClassVersionError: a (Unsupporte d major.minor version 51.0)

i have developed an web application in java using jdk 1.7.0 ,Eclipse IDE (Indigo) and is running that application on the tomcat(apache-tomcat-7.0.23) configured in eclipse ide.

When i tried to run my application through IDE it runs fine but when i created its war and placed it in apache deployment folder(webapps) and run it from outside the IDE the start page gets successfully loaded but when i tried to do any operation over it it gives me an error

UnsupportedClassVersionError unsupported major.minor version 51.0 unable to load class bean.myclassname 

i have checked the java version outside ide its jdk 1.7.0 and also the JAVA_HOME environment variable is set to C:\Program Files\Java\jdk1.7.0_01 .

like image 333
Nishit Jain Avatar asked Jan 24 '12 06:01

Nishit Jain


People also ask

How do I fix Java Lang UnsupportedClassVersionError unsupported major minor version?

UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime. How can i make above change? Project -> Properties -> Java Compiler Enable project specific settings. Then select Compiler Compliance Level to 1.7, 1.6 or 1.5, build and test your app.

When my class encounters unsupported class version error which options could resolve this issue?

1) If you encounter UnSupportedClassVersionError, check the JRE version you are using to run program and switch to higher version for quick solution.

What is unsupported class version error?

Class UnsupportedClassVersionErrorThrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported. Since: 1.2 See Also: Serialized Form.


2 Answers

Well presumably it's not using the same version of Java when running it externally. Look through the startup scripts carefully to find where it picks up the version of Java to run. You should also check the startup logs to see whether they indicate which version is running.

Alternatively, unless you need the Java 7 features, you could always change your compiler preferences in Eclipse to target 1.6 instead.

like image 142
Jon Skeet Avatar answered Sep 25 '22 23:09

Jon Skeet


Even though your JDK in eclipse is 1.7, you need to make sure eclipse compilance level also set to 1.7. You can check compilance level--> Window-->Preferences--> Java--Compiler--compilance level.

Unsupported major minor error happens in cases where compilance level doesn't match with runtime.

like image 32
kosa Avatar answered Sep 21 '22 23:09

kosa