-1

I have a recent Eclipse (2022-03) which relies on some JRE-17 according to eclipse.ini (-vm C:/Users/ericl/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.2.v20220201-1208/jre/bin), but I still want to use a JDK/JRE 1.8 which seems to be correctly installed everywhere (Eclipse preferences installed JRE, JDK compliance 1.8, etc...) because I want to build a standalone executable JAR for an older JavaFX lib because it relies on a single file (jfxrt.jar), so it is obviously easier to distribute.

I use "ant -v" to build my JAR to be sure I rely on the correct JRE 1.8: Apache Ant(TM) version 1.10.12 compiled on October 13 2021 Trying the default build file: build.xml Buildfile: C:\Development\java\eclipse\workspace\MCQ Factory JavaFX\build.xml Detected Java version: 1.8 in: C:\Development\java\jdk1.8.0_121\jre ...

Javac correct: javac -version javac 1.8.0_121

Java correct: java -version java version "1.8.0_121"

But when I try to execute my standalone JAR "MCQ-Test.jar" I get the UnsupportedClassVersionError although JDK 1.8 seems to have been used all along: java -jar .\MCQ-Test.jar Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: com/fdli/mcq/logic/McqPlayer has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

So how can I force the compilation of my standalone JAR to the correct version?

  • com/fdli/mcq/logic/McqPlayer will need to be recompiled with 1.8 or a 1.8 version of it found. If that's your own class with your own source, make sure you clean before recompiling with 1.8 – g00se May 21 '22 at 22:14
  • 1
    The Java with which Eclipse is running is independent from the Java version you use in your project. Make sure you have configure a Java 8 JDK in the preferences _Java > Installed JREs_, that you use Java 8 in your project (_Project > Properties: Java Compiler_) and in your Ant launch configuration that you use the Java 8 JDK in the _JRE_ tab. – howlger May 22 '22 at 06:26
  • In fact I am partially incorrect: when I go in console mode to the root of my Eclipse project to launch manually the build.xml ANT file (ant -v), it works, the correct JDK is used (V 8). It is when I use Eclipse GUI for the same (Right mouse, Run as Ant build) that the wrong JDK is used (V 17). – Eric Lemaitre May 23 '22 at 00:42

0 Answers0