简体   繁体   English

尝试在 cmd 中运行可执行文件 Jar 时出错

[英]Error while trying to run executable Jar in cmd

I know there are a few other similar questions to this, but the solutions don't seem to work.我知道还有其他一些类似的问题,但解决方案似乎不起作用。 (I have read about a dozen stack-overflow forums) (我已经阅读了大约十几个堆栈溢出论坛)

Here is that I tried doing in CMD:这是我尝试在 CMD 中做的事情:

C:\Users\warre>java -jar C:\Users\warre\OneDrive\Desktop\MirrorUserInput.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: usefulTools/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)

C:\Users\warre>javac -version
javac 14

C:\Users\warre>java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) Client VM (build 25.251-b08, mixed mode, sharing)

Here is my source code. 这是我的源代码。

I understand that some of the issues may arise from the discrepancy between JDK and JRE but I got confused when I tried to understand that complexity (I know the general difference between the two, and have read a few articles, but get confused exactly why it is causing an issue in eclipse.)我知道有些问题可能是由于 JDK 和 JRE 之间的差异引起的,但是当我试图理解这种复杂性时我感到困惑(我知道两者之间的一般区别,并且已经阅读了几篇文章,但对它的确切原因感到困惑导致 eclipse 出现问题。)

I used eclipse to export this.我用 eclipse 来导出这个。 I used all the default settings.我使用了所有默认设置。 I can send screenshots of this information if requested.如果需要,我可以发送此信息的屏幕截图。

You are right.你说的对。 The discrepancy occurs when version of JDK is higher than the JRE version.当 JDK 版本高于 JRE 版本时,会出现差异。

The reported major numbers are:报告的主要数字是:

Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

Based on the error message I can say for sure that your eclipse JDK version is set as Java 13 and the JRE version of your machine is 8.根据错误消息,我可以肯定地说,您的 eclipse JDK 版本设置为 Java 13,而您机器的 JRE 版本是 8。

You have two solutions.你有两个解决方案。 One solution maybe to upgrade your JRE to 13 at least.一种解决方案可能是将您的 JRE 至少升级到 13。 Or go to the eclipse Java compiler option and decrease the JDK version to JDK 8.或 go 到 eclipse Java 编译器选项,并将 JDK 版本降低到 JDK 8。

In Eclipse, go to menu command Window -> Preferences -> Java -> Compiler and then set "Compiler compliance level" to 1.8. In Eclipse, go to menu command Window -> Preferences -> Java -> Compiler and then set "Compiler compliance level" to 1.8.

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

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