I am getting this error when compiling a project: Unsupported major.minor version 51.0. I am using JDK 1.6:
$ java -version
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)
According to this page, the error is due to inconsistency between JRE and JDK. Does anyone know how to fix this? Thank you very much.
BTW, my platform is OSX 10.8.5.
Update
Here is my JAVA_HOME:
export JAVA_HOME=`/usr/libexec/java_home -v 1.6.0`
You are getting "Unsupported major.minor version 51.0" because you are trying to run the application in jre 6 which is compiled using jdk 7.
Either compile your application using jdk 6 or upgrade your default jre to 7.
Related
Everyone!
I have a java program with jar libraries that works on the following JDK version:
java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
I need to make it compile on a supercomputer that works on the following JDK version:
java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
As you can see they all have the same JDK which is JDK 8. However, when compiling using:
javac myFile.java
The following error appears:
class file has wrong version 51.0, should be 48.0
It seems that the compiling is done on another JDK (other than 8). Can anyone please help me solve this problem?
Kindest Regards!
java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.
J2SE 8=52,
J2SE 7=51,
J2SE 6.0=50,
J2SE 5.0=49,
JDK 1.4=48,
JDK 1.3=47,
JDK 1.2=46,
JDK 1.1=45
First Rule: Java version must be same on your local pc and server. Otherwise this kind of unwanted problem may arise.
For more checking, You can check
java --version
javac --version
It will make clarify of jdk and jre version mismatch. If it shows various version, then uninstall other versions and build your project and deploy on server.
Another answer is similar to your problem is here: Cannot compile Java code - "class file has wrong version 52.0, should be 48.0"
Resource Link:
Exception in thread “main” java.lang.UnsupportedClassVersionError: com/crunchify/Main : Unsupported major.minor version 51.0
I'm trying to run a java application, but when I start it on JBOSS, I get the error:
java.lang.UnsupportedClassVersionError: net/sourceforge/jtds/jdbc/Driver : Unsupported major.minor version 51.0
I searched around and found out that this is caused by compiling the code with java 7 and running it with java 6, so I started looking for my java configurations.
When I ran javac -version and it returns me:
U:\>javac -version
javac 1.6.0_27
When I run java -version it returns me:
U:\>java -version
java version "1.6.0_27"
Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
Java HotSpot(TM) Client VM (build 20.2-b06, mixed mode)
When I run mvn -v:
U:\>mvn -v
Apache Maven 3.0.4 (r1232337; 2012-01-17 06:44:56-0200)
Maven home: C:\dev\apache-maven-3.0.4\bin\..
Java version: 1.6.0_27, vendor: Sun Microsystems Inc.
Java home: C:\dev\Java\jdk1.6.0_27\jre
I'm not sure why this is happening, since everything is running on java 6 and version 51.0 is from java 7, according to this post:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
Anyone knows any other way to know how my code may be compiling on java 7, instead on java 6?
The problem is that the jTDS library itself is compiled in Java 7. You should use Java 7 to run it, not Java 6.
If you cannot change the Java version, you can try using an older version of the library that's compiled in Java 6. Or if you have access to the source code, you can try building it with the -target compiler flag set to 1.6.
Ok if i try run a java file from console i get unsupported major.minor 51.0. These class files were't compiled on my MAC osx. BUT... If I'm in finder and right click the class file and open with jar launcher it loads. Im trying to load it with terminal, java programName. My java version in console says
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
BUT in sys-pref-java it says Platform: 1.7 product: 1.7.0_51
Terminal using a different version? Not sure what to do.
You should set your JAVA_HOME environment variable to the results of the /usr/libexec/java_home command (which evaluates to your system configured Java version).
Try this:-
export JAVA_HOME="$(/usr/libexec/java_home -v 1.7)"
I'm trying to run PUMA benchmark set(Purdue Mapreduce Benchmarks Suite: for hadoop). I ran one application(wordcount) appropriately but couldn't run the other one(invertedindex). Error occures at runtime and it says
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/hadoop/examples/InvertedIndex : Unsupported major.minor version 51.0
I googled and found that it's because of the java version. I checked the java version and recompile the code and then run it. But still the same error occured at runtime for invertedindex application and wordcount application works well.
$ java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
$ javac -version
javac 1.7.0_51
How can I resolve this problem? Can this error be caused by source code?
the java version you obtain with java -version is not reflective of your hadoop's java version.
to check your hadoop's java version, use command hadoop classpath and check the directory of jdk it points to. or you could go to hadoop/config/hadoop-env.sh to find it.
your problem will most likely be solved by pointing hadoops's java home to jdk 1.7. you can edit this again in hadoop-env.sh.
I installed Java 7 on my Mac, compiled a web-app, and now I am trying to run it on Tomcat. However, I get the nasty Unsupported major.minor version 51.0 error. Googling showed that it is because Tomcat is using Java 6 to run the app, which is compiled for Java 7.
So I tried setting the path to the Java 7 jre in my "catalina.sh" script, but it didn't help. Moreover, "java -version" returns the correct java version.
dtv$ java -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
How can I fix this?
Try setting JAVA_HOME environment variable to point to your JDK 7. Catalina expects to find Java there. See if that tells it how to get JDK 7.