0

In my university we are learning about writing RMI applications. When I first tried running the example application in Eclipse 2019-03 I ran into the error: java.lang.UnsupportedClassVersionError I successfully ran other projects (non RMI) without any problems.

When I run

java -version

I get:

openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed       mode, sharing)

and

javac -version

I get:

javac 11.0.3

I have Java 8 and 11 installed on my system running Ubuntu 18.04. When looking for a solution to the problem, I found this question: How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

Changing the settings of the compiler compliace level in Eclipse to 1.8 did AND changing the project specific Settings helped me and I was able to finally run the Application without any errors. This solution does not satisfy me though.

When I run

update-alternatives --config java

and

update-alternatives --config javac

in both cases openjdk11 is selected. I do not understand, why I get the error if i dont change the compiler settings.

One of the answers suggested it is a wrongly set $JAVA_HOME varable. When I run:

jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));'

It indeed gives me the answer

/usr/lib/jvm/java-8-openjdk-amd64/jre

I tried following this guide to change it to openjdk11: https://askubuntu.com/questions/175514/how-to-set-java-home-for-java When I now run

echo $JAVA_HOME

I get:

/usr/lib/jvm/java-11-openjdk-amd64

but when I run

jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));'

again the answer is still the same.

I want to be able to use my openjdk 11 to compile and run the code without changing the compiler settings in Eclipse. Anybody had the same problem and a tip for me? Thank you in advance!

The full error is the following:

java.lang.UnsupportedClassVersionError: chapter6/Counter 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
Tom Smith
  • 153
  • 1
  • 8

1 Answers1

1

The /etc/alternatives is ignored when running inside Eclipse. Instead, you have a separate definition of which JDK/JRE to use. This can be set globally in the Eclipse Preferences, one-by-one in the Project Properties, or even at the Debug/Run configuration (in order to test your application in multiple java versions).

Shloim
  • 5,281
  • 21
  • 36