Unsupported major.minor version 51.0 while executing JSP - java

I am trying to deploy my JSP and java files on the server. But when I try to access the jsp I get the error msg
javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: com/usct/db/DBConnect : Unsupported major.minor version 51.0
I read a few posts and found out that this is due to difference in Java version on the two different platforms but I am using JAVA 1.7 on my server and my client when I do
java -version
in my jdk/bin it shows that the java version is 1.7.0_10 and
Java SE Runtime Environment (build 1.7.0_10-b18)
Can someone please help me with this issue?
Thank you

... but I am using JAVA 1.7 on my server and my client when I do ...
The most likely explanation is that you are actually using Java 1.6 or earlier ... despite what you think. In other words, when you run java -version from the command-line, you are getting a different Java installation to the one that is being used to run your web container.
(If you are on a Linux system, you should be able to tell which JVM is being used by running ps -efl and greping for "java" or similar. Alternatively, use the approach suggested by #dbf.)
It is worth noting that the version of Java on the client is not relevant. The exception is occurring on the server side.
Reference: How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
- explains the general problem and solution.

java.lang.UnsupportedClassVersionError error occurs due to higher JDK during compile time and lower JDK during runtime.
Java Version Major Version
Java 4 48.0
Java 5 49.0
Java 6 50.0
Java 7 51.0
So if you compile your Java source file with javac of JDK 1.7 it will
create class files with major version 51.0 and if you run those class
files with Java 1.6 it will throw
java.lang.unsupportedclassversionerror unsupported major.minor version
51.0 error
Try Compiling with older JDK or Upgrade the JRE.
More more information visit.

I believe com/usct/db/DBConnect is not a class provided by Java. And hence the reason of your error is not the version of jdk and jre on both your coding and execution environment. It seems the jar you used for the class DBConnect on your client and environment are of different java versions.

Try to print System.getProperty("java.version") from your JSP to check what version is actually used by your server.

Related

Unsupported major.minor version 52.0 (unable to load class) [duplicate]

This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 5 years ago.
When i run my project i am getting the following exception:
javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: apache/commons/codec/UtilityUtil : Unsupported major.minor version 52.0 (unable to load class apache.commons.codec.UtilityUtil)
I have researched and found out that it happens if the version of java is different from runtime and compilation time.
I have followed these two posts and tried to figure out that i am using java 8 and runtime has 1.7.:
Unsupported major.minor version 52.0 captive portal
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
I have changed the compilation version to 1.7. But still the same problem exists. I dont know why.
Runtime version: 1.7.0_45
Compilation Version: 1.7.0_80.
This is a duplicate. The classes you are using are probably compiled with Java 1.8 and your jvm is 1.7. That also includes 3rd party jars
52 = J2SE 8. You are still compiling with Java 1.8 (or some libs you are using are compiled with 1.8 as pointed out by #efekctive).
Please post what command are you using to build.
As #efekctive stated my build is using java 8 for building the class. Changed the version back to 7 and worked as expected. Thanks everyone.
Please do the following steps to find out yourJRE version and JDK version.
JRE check
java -version
java version "1.7.0_111"
OpenJDK Runtime Environment (IcedTea 2.6.7) (7u111-2.6.7-2~deb7u1)
OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode)
JDK check
javac -version
javac 1.6.0_38
And you can find that both the versions are different. So, make them into common version. That will solve your issue.

JBoss Unsupported major.minor version 52.0

I have an application that needs to be deployed in JBoss 6.0.0 and I am using Eclipse Mars. My system variable points to Java 1.6, from build path I've selected Java 1.6 and also, JBoss is using Java 1.6. My problem is that when trying to deploy the app to JBoss the following error
[org.jboss.detailed.classloader.ClassLoaderManager] Unexpected error during load of:com.xservice.java.velocity.VelocityLoader: java.lang.UnsupportedClassVersionError: com/xservice/java/velocity/VelocityLoader : Unsupported major.minor version 52.0.
I don't have any idea how to handle this considering the given settings.
The problem was fixed by changing the Java version from Project Facets(it was 1.8 instead of 1.6). Thanks go to Sanjeev Saha.
Project facets screen
Please locate the Jar which contains the class com.xservice.java.velocity.VelocityLoader.
This class is compiled with JDK 8. The class file version for Java SE 8 is 52.0 as per http://www.oracle.com/technetwork/java/javase/8-compatibility-guide-2156366.html Your JVM is Java 6. You may not be able to run a Java class compiled with JDK 8.0 by JVM 6.0. This is the reason you are getting 'Unsupported major.minor version 52.0'
My suggestion is using a Jar which contains classes compiled by JDK 6.0.

"A Java Exception has occured" what might be the cause?

When my jar is run on another computer there occurs a java exception but on my setup it runs ok. They are using Java 1.8? atleast one of them is. and my JDK is also 1.8.
Could the cause of this be in META-INF? I also tried sending .class files and running the main class using cmd (it maybe gave some other error i think)
Also I've exported it as a jar from eclipse, not executable jar. Could this be the cause?
EDIT
One of the stacktraces says: "Unsupported major.minor version 52.0‏"
Java version mismatch. The other computer not really running with JRE 8.
See this answer for detail Unsupported major.minor version 52.0
Your code was compiled with Java Version 1.8 while it is being executed with Java Version 1.7 or below.

JAVA runtime error:Unsupported major.minor version 51.0

i have java version "1.6.0_45" and javac 1.7.0_51 when i run my file as javac -source 1.6 Mouse.java then it show error this warning: [options] bootstrap class path not set in conjunction with -source 1.6 1 warning and when i run simple java Mouse then it show error
Exception in thread "main" java.lang.UnsupportedClassVersionError: Mouse : Unsupported major.minor version 51.0.
java.lang.UnsupportedClassVersionError: Mouse : Unsupported major.minor version 51.0
That error is caused by incompatible Java versions. You're most likely trying to run something compiled by a newer Java version with an older Java version. You should check your Java versions. 51.0 is the newer class file format which is supported by JDK7
You are compiling with 1.7 resulting in 1.7 code. You are trying to use Java 1.6 to execute said code. Doesn't work.
Edit: Either compile with 1.6 (if possible) or use > 1.7 compatible JRE to execute your code.
You told javac that your source code should be compatible with Java 6 (i.e. it should not use Java 7 specific features like try-with-resources or the diamond operator).
But you didn't tell it to compile class files compatible with Java 6. That is done using the -target 1.6 option.
Quite frankly, I would use the JDK 1.6 to compile your classes if you want the sourcecode and the target class files to be compatible with 1.6. That would guarantee (as the warning message you get tells you) that your code is also not using JDK classes and methods that have been introduced in Java 7.

Google App Engine Java Error

I just started off with Google App Engine 1.6.4 in Eclipse Indigo a couple of days ago and I face a problem with the back end.
Whenever I try to use a servlet or a JSP, I get this annoying
java.lang.UnsupportedClassVersionError: org/msamogh/MyServlet : Unsupported major.minor version 51.0
I tried changing my JRE to Java 6, but the error still remains. Does anyone know how to fix this.
The major.minor version 51.0 seems to indicate that your classes are compiled using Java 7. Please make sure that the following are done:
Start Eclipse using a Java 6 JDK.
Set the default JVM in Eclipse to a Java 6 JDK.
Set the default and/or project compiler settings to use 1.6 target.
In general, you need to make sure that your runtime JRE is able to understand your compiled code. If you try to run code compiled for 1.7 on a 1.6 JRE, you will get the above error.
What is your output when you do java -version? This will tell you what version the running JVM is.
The Unsupported major.minor version 51.0 error could mean:
app is running on a lower Java version then the one used to compile it
Try adding a SYSTEM VARIABLE that looks like this: JRE_HOME = C:\PROGRAM FILES\JAVA\JRE7 or JRE6 shipped with the JDK 1.7 or later package with which you compiled it.

Categories

Resources