简体   繁体   English

Java错误的主要版本

[英]Java wrong major version

On our hadoop cluster my Pig UDF fails complaining 在我们的hadoop集群上,我的Pig UDF无法抱怨

 [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. 我读过用猪写的udf,就像教程一样 ,问题也很清楚,但是不幸的是我无法解决。 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. 我的清单不包含版本(是否有必要?),尽管我使用1.7进行了编译,但javap报告的主要版本为52,代表Java 1.8。 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, 并且Javap报告主要版本52,代表Java 1.8,

That is the relevant fact. 这是相关的事实。

although I compiled it with 1.7. 尽管我用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. 所有这些都归结为您如何编译代码,并且当您说使用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. 因为Java 1.7 Java编译器无法使用Java 1.8版本号创建“ .class”文件。 It simply doesn't understand the Java 8 syntax extensions, and the corresponding enhancements to the classfile format. 它根本不了解Java 8语法扩展以及对类文件格式的相应增强。

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. 解决此问题的方法是仔细查看您的构建过程,并弄清楚如何以及为什么使用Java 1.8编译器来编译有问题的类。 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. 如果您是手工构建(例如通过从命令行运行“ javac”和“ jar”,或通过单击IDE中的按钮),那么现在是学习诸如Maven,Ant和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. 我的设置证明了这一点,但是我想我发现了问题:.settings / org.eclipse.jdt.core.prefs包含几个1.8。 entries. 条目。 This may be due to the fact that at the time of the project creation I had 1.8. 这可能是由于在创建项目时我有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. 这说明我可能正在使用Eclipse Java编译器而不是JDK的Java编译器进行编译。

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. 实际上,您的Eclipse编译器正在(或正在)针对Java 1.8目标进行编译……因为您的Eclipse设置表明Eclipse Java编译器应该这样做。 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. 如果使用Eclipse编译器来编译代码,则JDK或JRE安装的版本不会确定类文件的版本号。

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. 再次,我强烈建议您学习使用Maven,Ant或Gradle,以便您的构建过程具有更高的可重复性和更少的错误发生率。

I guess Stephen C's is the most general answer. 我想斯蒂芬·C是最笼统的答案。

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. 在我的特殊情况下,问题是项目特定的编译器合规性设置错误,因为在创建项目时我在本地使用了JDK 1.8,后来在群集上收到错误时安装了1.7。

The option is quite hidden and can be found here: Window > Preferences > Java > Compiler > "Configure project specific settings" > [projectname] > "Compiler compliance level" 该选项非常隐蔽,可以在以下位置找到: Window > Preferences > Java > Compiler > "Configure project specific settings" > [projectname] > "Compiler compliance level"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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