1

I wanted to run my app.jar via terminal with java -jar command, and I have gotten the following error:

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

which surprised me, because when I was setting everything up, I have downloaded and installed jdk-12.0.1 from java.sun.com. Also, JAVA_HOME path in /etc/environment is set to the /usr/lib/jvm/openjdk-12.0.1 directory. But when I run java --version, it shows me:

openjdk 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)

Can anyone explain why is that so and what should I do to configure everything properly?

Eliah Kagan
  • 117,780
Sergiy
  • 65
  • Have you set your default javac, javaws and java version? This may be answered before, see https://askubuntu.com/questions/121654/how-to-set-default-java-version – Bernard Wei Jul 11 '19 at 23:17

1 Answers1

2

Your system-level Java is still configured as OpenJDK 11. To manage multiple Java installations properly, you should register the Oracle/Open JDK 12 that you have manually downloaded so that Ubuntu can recognize it. After that, you can configure the specific Java version that you want using update-alternatives. The commands below will register the new Java installation and set it as the first priority:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/openjdk-12.0.1/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/openjdk-12.0.1/bin/javac" 1

If you only need a single Java installation, it would be easier to install the latest Java as a system package via the official repositories or ppa:

OpenJDK 12:

sudo apt install openjdk-12-jdk

Oracle JDK 12:

sudo add-apt-repository ppa:linuxuprising/java
sudo apt install oracle-java12-installer
prusswan
  • 709
  • Thank you! Whoever face this problem,another nice solution also is here https://askubuntu.com/questions/162159/how-do-i-make-the-official-jdk-version-the-default-java. – Sergiy Jul 12 '19 at 17:48