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?


1 Answer 1


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .