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

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.

Related

Unable to execute the program in hadoop

When I created a Jar and compiled in windows and tried to run in Hadoop. It's throwing an error while running this script
admin1#admin1:/usr/local/hadoop/conf$ hadoop jar wordcount.jar com.shailu.wordcount.WordCount input/wordcount output/wordcount
Error is:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/shailu/wordcount/WordCount : Unsupported major.minor version 52.0
Nothing wrong with ur execution,
Looks like there is a mismatch in the compile and the execute environment.
type "java -version" in both the environments , i.e. windows and hadoop(linux/unix)
My doubt is you have compiled the code in a higher version like 1.8, change it to 1.7 or so, you should be ok.
or while compiling choose the same java version as the hadoop environment have.
I have encountered such problem. You need keep the compiler consistently between windows and hadoop or hadoop compiler higher than windows'. See picture I screenshot from Internet(contain a little Chinese, you also can refence this website if you can open it: JDK compiler version mapping minor.major). I guess JDK1.8.x is mapping major.minor version 52.0.
JDK编译器版本-------------JDK compiler version
target参数----------------target parameter
十六进制 minor.major------hexadecimal minor.major
十进制 minor.major--------decimal minor.major
不能带 target 参数--------can't add target parameter
默认为--------------------default

Running a JAR I compiled: "Unsupported major.minor version 52.0"

I just recently recovered some programs from my old hard drive, so I tried compiling one and running it, and I get this error in command prompt:
Unsupported major.minor version 52.0
I compiled the program with Java 8, and I ran it with Java 8. The only thing I can think of is the fact that I used Java 7 with the program on my old computer. Also, I'm using Windows XP on this new computer, while I used Windows 7 on the old computer.
I am using two libraries, but I don't think that is the issue since the program ran fine in NetBeans.
Any ideas of what the problem is?
Based on your comment to archetype's answer, my guess is that java 7 is in one of your windows directories, like C:\Windows\System32 and that directory is before your JAVA_HOME directory in your path. Try typing 'where java' on the CMD. If it's in more than one directory, see which one comes first in your PATH variable and look at the version of java in that directory.
The root cause of the problem is that, the code was compiled in later version but your default runtime is running on the lower version. you can do this by simply checking your current version. java -version and javac -version. You may need to check the Java from the Control Panel. To verify the actual version of your JAR file, you may need to extract the actual version and look for the version information
javap -verbose <Java_Class_Name> | findstr "major"

Unsupported major.minor version 51.0 while executing JSP

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.

Errors when running executable jar file

I get the error below when trying to run an executable jar file. The file only contains a main with one line "System.out.println("Woo!");" and runs fine in eclipse.
I'm not sure how to read these error messages.
(too new to post images correctly)
The error means that you have compiled the code with a higher version of java and trying to run it on a older version of jvm.
Since it says major.minor version 51.0 it means that your compiler is java6. So you should run your program on java6 or higher.
Your compiled class is in jre 1.5 and your system default jre is different(might be 1.6).
compile your code in same version of jre.

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