由较新版本的Java Runtime编译(类文件版本57.0) [英] Has been compiled by a more recent version of the Java Runtime (class file version 57.0)

查看:1197
本文介绍了由较新版本的Java Runtime编译(类文件版本57.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IntelliJ遇到了这个问题.但我拥有系统上新安装的所有产品的最新版本.

I get this problem Using IntelliJ. But I have the newest version of everything newly installed on my system.

...已由Java Runtime的较新版本(类文件版本57.0)进行编译,此版本的Java Runtime仅可识别52.0以下的类文件版本.

我已经设置:

PATH作为C:\ Program Files \ Java \ jdk-13 JAVA_HOME为:C:\ Program Files \ Java \ jdk-13 JRE_HOME为:C:\ Program Files \ Java \ jre1.8.0_221

PATH as C:\Program Files\Java\jdk-13 JAVA_HOME as: C:\Program Files\Java\jdk-13 JRE_HOME as: C:\Program Files\Java\jre1.8.0_221

我已经设置了路径,试图在Project结构中找到更改

I've set the path, tried to find a change in the Project structure

完整的错误消息:

H:\087-JAVA\HelloWorld\src>java com.codewithmosh.Main
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/codewithmosh/Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

推荐答案

您需要仔细检查PATH环境设置.您当前所在的C:\Program Files\Java\jdk-13不正确.请确保在PATH列表的顶部,您具有bin子目录以获取最新的JDK版本.

You need to double check the PATH environment setting. C:\Program Files\Java\jdk-13 you currently have there is not correct. Please make sure you have the bin subdirectory for the latest JDK version at the top of the PATH list.

java.exe可执行文件位于C:\Program Files\Java\jdk-13\bin目录中,因此这就是PATH中需要的文件.

java.exe executable is in C:\Program Files\Java\jdk-13\bin directory, so that is what you need to have in PATH.

使用此工具可以在Windows上快速验证或编辑环境变量.它允许对PATH条目重新排序.它还将用红色突出显示无效路径.

Use this tool to quickly verify or edit the environment variables on Windows. It allows to reorder PATH entries. It will also highlight invalid paths in red.

如果您还希望代码在较低的JDK版本上运行,请在IDE中更改目标字节码版本.有关相关屏幕截图,请参见此答案.

If you want your code to run on lower JDK versions as well, change the target bytecode version in the IDE. See this answer for the relevant screenshots.

另请参阅此答案(针对Java)类文件版本.发生的情况是,您使用Java 13和13语言级别的字节码(目标)构建代码,并尝试使用Java 8(根据PATH变量配置,这是第一个(默认)Java版本)运行代码.

See also this answer for the Java class file versions. What happens is that you build the code with Java 13 and 13 language level bytecode (target) and try to run it with Java 8 which is the first (default) Java version according to the PATH variable configuration.

解决方案是将Java 13 bin目录放在上面的PATH中或代替Java8.在Windows上,您可能已将C:\Program Files (x86)\Common Files\Oracle\Java\javapath自动添加到PATH中,现在它指向Java 8:

The solution is to have Java 13 bin directory in PATH above or instead of Java 8. On Windows you may have C:\Program Files (x86)\Common Files\Oracle\Java\javapath added to PATH automatically which points to Java 8 now:

在这种情况下,请从PATH中删除突出显示的部分,然后注销/登录或重新引导以使更改生效.您需要先以管理员身份重新启动,才能编辑系统变量(请参见系统变量列右上角的按钮).

If it's the case, remove the highlighted part from PATH and then logout/login or reboot for the changes to have effect. You need to Restart as administrator first to be able to edit the System variables (see the button on the top right of the system variables column).

这篇关于由较新版本的Java Runtime编译(类文件版本57.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆