我制作了一个非常适合我的可执行jar文件,但当我将其发送给我的朋友时,他们会收到错误A JNI error has occurred, please check your installation and try again
。当他们在控制台中运行它时,扩展的错误消息是
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/pathto/project
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
当jar文件是用比运行jar的人更新的java版本编译时会导致此问题(例如,您用java 11编译了jar,但您的朋友只安装了java 8(https://www.oracle.com/java/technologies/downloads/#jdk17-windows和下载x64 Installer
。然后,让你的朋友通过运行下载的exe来安装java。接下来转到exe安装JDK的位置,默认为C:Program FilesJava
,并将文件路径复制到新下载的JDK(C:Program FilesJavajdk-17.0.1
(。最后,转到控制面板中的edit the system environtment variables
,转到Environment Variables...
单击System Variables
下的Path
,单击"编辑"按钮,单击"新建"按钮,粘贴到您复制的文件路径中,单击"确定",然后将新创建的变量移到顶部。