如何更新我的Java运行时环境

时间:2020-05-27 19:21:55

标签: java jar

我最近为我使用JDK 14.0.1编写的程序创建了一个.jar,并且正在尝试运行它,但是我不断收到一条错误消息,指出该.jar是在文件版本55中编译的,并且我当前的Java运行时环境“只能识别52.0以下的类文件版本”

我尝试通过控制面板更新Java,并将JAVA_HOME和系统路径更新为14.0.1,但是即使重新启动计算机后,我的Java版本和Java SE Runtime Environment版本仍为1.8。 / p>

(请忽略用户名,我是在中学时期写的)

C:\Users\Dudenugget123>java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

C:\Users\Dudenugget123>javac -version
javac 14.0.1

C:\Users\Dudenugget123\Desktop\BlueJ Programs\ThreeCombos>java -jar ThreeCombos.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: ThreeCombos has been compiled by a more recent version of the Java Runtime (class file version 55.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)

1 个答案:

答案 0 :(得分:1)

检查您的%PATH%环境变量,它可能包含旧JRE的路径。删除它,然后插入新JRE的路径。

%PATH%定义了在尝试启动程序而不指定完整路径时操作系统的外观。 %JAVA_HOME%已被一堆Java专用工具(如ant)使用,但对您的操作系统或命令提示符没有任何意义。