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

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 .

This question is related to java tomcat war

The answer is


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.


java_home environment variable should point to the location of the proper version of java installation directory, so that tomcat starts with the right version. for example it you built the project with java 1.7 , then make sure that JAVA_HOME environment variable points to the jdk 1.7 installation directory in your machine.

I had same problem , when i deploy the war in tomcat and run, the link throws the error. But pointing the variable - JAVA_HOME to jdk 1.7 resolved the issue, as my war file was built in java 1.7 environment.


Try adding the following to your eclipse.ini file:

-vm
C:\Program Files\Java\jdk1.7.0_01\bin\java.exe

You might also have to change the Dosgi.requiredJavaVersion to 1.7 in the same file.


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.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to tomcat

Jersey stopped working with InjectionManagerFactory not found The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat Spring boot: Unable to start embedded Tomcat servlet container Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists Spring Boot application in eclipse, the Tomcat connector configured to listen on port XXXX failed to start Kill tomcat service running on any port, Windows Tomcat 8 is not able to handle get request with '|' in query parameters? 8080 port already taken issue when trying to redeploy project from Spring Tool Suite IDE 403 Access Denied on Tomcat 8 Manager App without prompting for user/password Difference between Xms and Xmx and XX:MaxPermSize

Examples related to war

Deploying Java webapp to Tomcat 8 running in Docker container What is WEB-INF used for in a Java EE web application? How to unpackage and repackage a WAR file How to start jenkins on different port rather than 8080 using command prompt in Windows? Update Jenkins from a war file Oracle JDBC ojdbc6 Jar as a Maven Dependency UnsupportedClassVersionError unsupported major.minor version 51.0 unable to load class How to extract .war files in java? ZIP vs JAR How do I update a Tomcat webapp without restarting the entire service? Difference between jar and war in Java