23

I am trying to run the WordCount example on hadoop - 1.0.4 and I am getting the following error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: WordCount :
Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:149)

I use the following java version:

java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) Server VM (build 23.6-b04, mixed mode)

Also JAVA_HOME indicates to the java7 installation directory.

Thanks for your help.

georgiana_e
  • 1,809
  • 10
  • 35
  • 54

7 Answers7

19

Seems like you are using JDK8 for compiling and Lower version on Where you are using it.

So

Assuming using eclipse, Window > Preferences > Compiler > compiler level

and then set lower level(< current one ).

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • 1
    I am compiling from command line in ubuntu and I didn't manage to change the compiler level to a lower one, I used the fallowing syntax: javac -1.6 WordCount.java but it didn't work and I get an error "invalid flag -1.6". – georgiana_e Aug 10 '13 at 13:35
  • 2
    It worked after I've changed the compilation level. Thanks very much. – georgiana_e Aug 10 '13 at 14:18
4

I had the same problem which I solved. I found that the JAVA_HOME in my hadoop-env.sh is /usr/lib/jvm/java-6-openjdk but the JAVA_HOME in /etc/profile is /usr/local/java/jdk1.8.0_25.

After I change JAVA_HOME in /etc/profile to /usr/lib/jvm/java-6-openjdk which is the same as hadoop-env.sh and use $source /etc/profile # to make /etc/profile effects

My problem is solved! I hope this will help you.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Albert
  • 41
  • 1
0

Looks like someone managed to compile a class with a Java 8 compiler. Recompile the offending jar with a compliance level of Java 7 or lower.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
0

Well obviously that won't work! You are compiling on a newer JDK and deploying on an older JDK / JRE. You need to compile on the older JDK.

saurav
  • 3,424
  • 1
  • 22
  • 33
  • Thanks very much, this was the problem. I used the hadoop-core.jar file which was compile with java6 and I compiled my program with java 8. It worked after I changed the compilation level for my program to 1.6. – georgiana_e Aug 10 '13 at 14:21
  • Kool Happy to Help :) – saurav Aug 10 '13 at 15:03
  • Though, of course, you can use a newer JDK to target an older bytecode level using `-source` and `-target` options. – Lawrence Dol May 08 '14 at 17:37
0

The problem is due to .jsp files are getting compiled with higher compiler(8) than expected(7). Change all compilation levels to lower one(i.e. 7) also change the jdk path given in eclipse configuration settings file in the same folder where .exe is located.

0

I think you already got your answer ..just to add, in eclipse under project there is a JRE System Library [JavaSE-1.x] folder .. right click on it you will see JRE System Library screen..there you can set the execution environment.

ppant
  • 752
  • 9
  • 19
0

I also encountered the same problem.Should use same JAVA version for compile and same or greater on where you are executing it although vice-versa cause this error. If you checked:

  1. Window > Preferences > Compiler > compiler level
  2. java -version and both has same version then you are good to go. While creating New Project in Eclipse: File -> New -> Java Project under JRE check Use an execution environmententer image description here and set to same version which is on your system and system where you need to execute this project.
niks
  • 101
  • 3