java 運行報錯has been compiled by a more recent version of the Java Runtime
javaweb運行報錯:has been compiled by a more recent version of the Java Runtime (class file version 55.0)
報錯信息:
Exception in thread "main" java.lang.UnsupportedClassVersionError: pers/cyz/BookManage has been compiled by a more recent version of the Java Runtime (class file version 54.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)
解決辦法:
在項目的屬性里設置jdk版本,方法是右擊項目-->properties-->java compiler --> Enable project specific settings -->將compiler compliance level設置為1.8,也就是與jvm一致的版本

一般這樣的錯誤都是因為當前的jre不能對程序進行編譯,Tomcat的版本高于JDK的版本導致的,當前運行的jdk是1.8而我用的Tomcat版本是Tomcat 9所以就會出現這個問題。
解決方法:
要么降低Tomcat的版本號,要么用更高的版本的JRE。
這里我選擇使用高版本的JRE:

重啟服務器再次運行項目,問題解決。
eclipse運行Java代碼出現原因很多,具體問題具體分析。
解決方案:
如果是web項目,不要在打開的文件上右擊,要到項目路徑上去右擊”run as“,之后選擇“server”。
如果是mian方法項目,需要找到帶有main方法的類,之后打開這個類,之后“run as”,之后選擇“java applet”即可。
到此這篇關于java 運行報錯has been compiled by a more recent version of the Java Runtime的文章就介紹到這了,更多相關java has been compiled by a more recent version內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Java中new關鍵字和newInstance方法的區(qū)別分享
在初始化一個類,生成一個實例的時候,newInstance()方法和new關鍵字除了一個是方法一個是關鍵字外,最主要的區(qū)別是創(chuàng)建對象的方式不同2013-07-07
Java異常 Factory method''sqlSessionFactory''rew exception;este
這篇文章主要介紹了Java異常 Factory method ‘sqlSessionFactory‘ threw exception; nested exception is java.lang.NoSuchMethodError:,本文介紹了springboot 引入mybatis-plus后報錯的解決方案,以下就是詳細內容,需要的朋友可以參考下2021-07-07
Spring Boot整合Mybatis并完成CRUD操作的實現示例
這篇文章主要介紹了Spring Boot整合Mybatis并完成CRUD操作的實現示例,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12

