0

I have been trying to build my java program into a .jar file with IntelliJ IDEA (JDK 20.0.2). The building process went fine, the .jar was built but when I tried to run it using java -jar filename.jar it only threw an exception:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of the Java Runtime (class file version 64.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)

I thought the problem was my JRE not being up-to-date. I updated it. Same error. Desperately I reinstalled it over and over again but it did not fix my issue. I am not sure I have the latest JRE, in fact this is the only one I could find on https://www.java.com/en/download/

java version "1.8.0_381"
Java(TM) SE Runtime Environment (build 1.8.0_381-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.381-b09, mixed mode)

All the paths to JRE are set in my system enviroment path, the only JRE I have installed right now is the one I am talking about. I built the .jar using IntelliJ IDEA artifacts, my code does not contain any errors and runs properly through IntelliJ IDEA.

  • If the answers in the duplicates used to close this question don't help you, then likely some of [these might](https://www.google.com/search?q=site%3Astackoverflow.com+java+UnsupportedClassVersionError). Good luck! – Hovercraft Full Of Eels Aug 15 '23 at 20:07
  • 1
    Java 1.8 is quite old. Consult https://jdk.java.net/. – Louis Wasserman Aug 15 '23 at 20:20
  • The java.com channel was created (by Sun) for a JRE as opposed to a JDK, decades ago when the licensing was different. For 'modular' Java beginning with Java 9 in 2017, Oracle distributes _only_ the JDK (from which a tailored JRE can be extracted); there is no separate JRE distribution. Since you have Java 20 JDK for IDEA just use that. – dave_thompson_085 Aug 15 '23 at 21:05

0 Answers0