简体   繁体   中英

Java wrong major version

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?

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 (eg 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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM