'WSL-2 Ubuntu 20.04 JavaFX error while using Java 8

I am using WSL-2 Ubuntu 20.04 on windows10 and I want to run a java application on it but I get the following error:

Error: JavaFX runtime components are missing, and are required to run this application

It is strange because I have installed Java 8 which has JavaFX included. java -version gives me back the following:

java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~20.04-b07)OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

javac -version
javac 1.8.0_312

I am running the java program in the following way: java -jar myprogram.jar

What do I miss?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source