java.lang.UnsupportedClassVersionError: com/dicoding/javafundamental/basic/Main has been compiled by a more recent version of the Java Runtime

java.lang.UnsupportedClassVersionError: com/dicoding/javafundamental/basic/Main has been compiled by a more recent version of the Java Runtime

enter image description here

我试图制作一个 JAR 格式的包。但是当我尝试时,它失败了。如何解决这个问题

java -jar out/artifacts/StrukturDasar_jar/StrukturDasar.jar

结果是这样的:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/dicoding/javafundamental/basic/Main has been compiled by a more recent version of the Java Runtime (class file vers
ion 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

我的 IDE 和 JDK:

IntelliJ IDEA 2019.1.3 (Community Edition)
Build #IC-191.7479.19, built on May 28, 2019
JRE: 1.8.0_202-release-1483-b58 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

这是由于 JDK/JRE 版本不匹配 - 可能 class 使用较高版本 JDK 编译,试图在低版本 JDK 中执行。

Java Runtime (class file vers ion 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

要么你必须对版本不匹配进行排序,要么在编译命令中指定目标版本。

这有助于您实现交叉编译。

https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#crosscomp-example