1

On our hadoop cluster my Pig UDF fails complaining

 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1069: Problem resolving class version numbers for class <classname>

I read writing a udf in pig kind of like tutorial and the problem seams to be clear, but unfortunately I cant solve it. My manifest does not contain a version (is this necessary?) and javap reports major version 52, representing java 1.8, although I compiled it with 1.7. So how can I solve this?

Community
  • 1
  • 1
ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103
  • 1
    How is the jar getting created ? Ant/ Maven ? – Murali Rao Jun 26 '15 at 23:55
  • I guess the jar is not really the problem, since the unpacked classfile is already of a wrong version. The jar is created by click with a jardesc file. Sorry if that is not enough information, I am an eclipse noob, – ManuelSchneid3r Jun 27 '15 at 10:25

2 Answers2

4

My manifest does not contain a version (is this necessary?)

The version manifest entry is not relevant to this. The classloader pays no attention to the version manifest entry.

and javap reports major version 52, representing java 1.8,

That is the relevant fact.

although I compiled it with 1.7.

This all boils down to how you compiled your code, and I think you are incorrect when you say that you compiled with Java 1.7.

Why do I say that? Because the Java 1.7 java compiler is not capable of creating a ".class" file with the Java 1.8 version numbers. It simply doesn't understand the Java 8 syntax extensions, and the corresponding enhancements to the classfile format.

So how can I solve this?

The way to resolve this is to look carefully at your build process and figure out how and why the offending class got compiled using a Java 1.8 compiler. Because there can be no doubt that that is what has happened.

If you are building by hand (e.g. by running "javac" and "jar" from the command line, or by clicking buttons in your IDE) then now would be a good time to learn about build tools like Maven, Ant and Gradle.


FOLLOWUP

That not true. My setting proofs this, but I guess I found the issue: .settings/org.eclipse.jdt.core.prefs contain several 1.8. entries. This may be due to the fact that at the time of the project creation I had 1.8. installed.

Actually, it doesn't "prove" anything ...

What this is telling me is that you are probably compiling with the Eclipse Java compiler, not the Java compiler from your JDK.

In fact, your Eclipse compiler is (or was) compiling for a Java 1.8 target ... because that is what your Eclipse settings say that the Eclipse Java compiler should do. If you are using the Eclipse compiler to compile your code, the version of your JDK or JRE install doesn't determine the classfile version number.

Once again, I strongly recommend that you learn to use a Maven, Ant or Gradle so that you build process is more repeatable and less error prone.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • "Because the Java 1.7 java compiler is not capable of creating a ".class" file with the Java 1.8 version numbers." Thatt not true. My setting proofs this, but I guess I found the issue: .settings/org.eclipse.jdt.core.prefs contain several 1.8. entries. This may be due to the fact that at the time of the project creation I had 1.8. installed. – ManuelSchneid3r Jun 27 '15 at 10:30
  • Your setting proves nothing of the sort. Sorry, but your reasoning is flawed. Your setting If you want a evidence that it is impossible: 1) try compiling with a `javac -target 1.8 ...` using the compiler in a Java 1.7 JDK, and 2) read the source code for the Java 1.7 compiler. – Stephen C Jun 27 '15 at 11:30
  • Okay didn't know that eclipse has its own compiler. This makes things clearer. Thank you. – ManuelSchneid3r Jun 27 '15 at 13:07
0

I guess Stephen C's is the most general answer.

In my special case the problem was, that the project specific compiler compliance settings were wrong, because I used JDK 1.8 locally when I created the project and installed 1.7 later, when I got the error on the cluster.

The option is quite hidden and can be found here: Window > Preferences > Java > Compiler > "Configure project specific settings" > [projectname] > "Compiler compliance level"

ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103