0

I made a java program in Eclipse IDE (Version: 2019-09 R (4.13.0)) with multiple classes that is supposed to run in a terminal (cmd for example).

For this, I first tried to export my project: Export... > Runnable JAR file

I chose my Main class as my launch configuration and I clicked the radio button "Extract required libraries into generated JAR". I finished and the export seemed to work fine.

I know tried to run this program in cmd by using this attempt: https://stackoverflow.com/a/5774976/11583484 (java -jar fdm.jar)

Now an error occurs:

Exception in thread "main" java.lang.UnsupportedClassVersionError: general/Main has been compiled by a more recent version of the Java Runtime (class file version 54.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(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

At some point there seem to be trouble with Java versions, what may have been happened and what can I try to avoid it? I want to send the .jar file to another person that need to be able to run it properly later on.

ItsPete
  • 2,363
  • 3
  • 27
  • 35
TiMauzi
  • 190
  • 1
  • 3
  • 16

2 Answers2

0

general/Main has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0

You have compiled your project with Java 10 ("class file version 54") and you run it with Java 8 ("recognizes class file versions up to 52.0").

See these articles for more information:

haba713
  • 2,465
  • 1
  • 24
  • 45
0

I actually managed to solve the problem now. A similar problem has been described here: https://coderanch.com/t/701603/java/JRE-JDK

My problem: I had different versions of JDK installed. I needed to add the my JDK 11 path (in my case: C:\Program Files\Java\jdk-11\bin) to the "Path" environment variable and move it to the top.

Now, everything works just fine with java -jar fdm.jar.

Thank you for your help!

TiMauzi
  • 190
  • 1
  • 3
  • 16