19

I'm trying to install OpenJDK 8 and OpenJFX 8 on Ubuntu 20.10.

Installing openJFX 8 has always been a little tricky on Ubuntu, but I used to be able to do it using the tip from this SO answer: https://stackoverflow.com/a/56166582/2423283 That used to work fine (I think I was using Ubuntu 19.something), however it appears that recently 8u161-b12-1ubuntu2 was removed.

For some more background information, I'm installing this via a docker file in an automated pipeline. Here are the relevant parts of the Dockerfile:

FROM my.company.internal.registry:443/ubuntu:latest

RUN apt -y update && \
    apt -y install \
    openjdk-8-jdk \
    openjfx=8u161-b12-1ubuntu2 \
    libopenjfx-java=8u161-b12-1ubuntu2 \
    libopenjfx-jni=8u161-b12-1ubuntu2

This used to run just fine, but now I get:

E: Version '8u161-b12-1ubuntu2' for 'openjfx' was not found
E: Version '8u161-b12-1ubuntu2' for 'libopenjfx-java' was not found
E: Version '8u161-b12-1ubuntu2' for 'libopenjfx-jni' was not found

What I've tried so far

I've tried changing my ubuntu:latest to ubuntu:19:10 in my FROM line in the Dockerfile, but I still got the missing packages errors.

I tried just removing those version restrictions (the =8u161-b12-1ubuntu2) and I didn't see any errors during the installation, but then when I compiled my code, none of the JavaFX classes could be found.

NateW
  • 908
  • 1
  • 8
  • 28
  • It looks like [libopenjfx-java](https://packages.ubuntu.com/search?keywords=openjfx&searchon=names&suite=all&section=all) 8 is not in any recent repo. – David Conrad May 13 '20 at 19:58
  • Looks like https://bugs.launchpad.net/ubuntu/+source/openjfx/+bug/1799946 still applies – Wolfgang Fahl May 13 '20 at 20:49

4 Answers4

22

If you are set on using JDK 8 and JavaFX, I've found it's best to install an OpenJDK that includes JavaFX.

For version 8, not all OpenJDKs include JavaFX (e.g. AdoptOpenJDK). The best ones I have found are

  • Zulu : You must select "JDK FX" in the Java Package drop down
  • Liberica: You must select "Full JDK"

Liberica provides builds for raspberry pi and a wide variety of other architectures. If you need that, Liberica is the way to go.

maroc
  • 466
  • 2
  • 5
  • Thanks, this looks great. I'll accept this as the answer once I get a chance to try it out (which might be a while). – NateW Jun 04 '20 at 21:53
8

I stumbled upon the same problem and found that the easiest solution is to use sdkman: https://sdkman.io/install

With these three commands I was able to have openjdk 8 with JavaFX installed on Ubuntu 20.04:

curl -s "https://get.sdkman.io" | bash

source "$HOME/.sdkman/bin/sdkman-init.sh"

sdk install java 8.0.252.fx-zulu

user1822128
  • 107
  • 2
  • 1
    Looks like that installs the Azul zulu build of OpenJDK 8, which I think should be just fine (need to check if that adds any sort of legal/licensing changes). Sounds like sdkman is a good way to go and probably the most convenient way to install it, but really the answer to the problem is to use zulu, or some other community build of OpenJDK. – NateW Jun 09 '20 at 18:38
5

Install Liberica JDK / JRE via Aptitude

Liberica JDK is quite easy to install on Ubuntu / Debian based operating systems which support the aptitude package manager.

All you have to do is to add the official BellSoft repository:

wget -q -O - "https://download.bell-sw.com/pki/GPG-KEY-bellsoft" | sudo apt-key add -
echo "deb [arch=amd64] https://apt.bell-sw.com/ stable main" | sudo tee /etc/apt/sources.list.d/bellsoft.list

And after that update your packages and install the full bellsoft java version. It is important that you use the full version, as it is the only one coming with JFX. Also bear in mind that you should uninstall all previously installed java versions via apt purge before installing this java version.

sudo apt-get update
sudo apt-get install bellsoft-java8-full

You can use bellsoft-java8-runtime-full to safe some space if you only need the JRE. After the installation is completed applications using JavaFX work just fine.

In case you are not using the Ubuntu repository because you are using Debian for example you need to enter the following command to make sure there is no verification error on apt update for the Bellsoft repository.

#Use this only in case there is a verification error on update
apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv-keys 32E9750179FCEA62

If you are not using an operating system with the aptitude package manager there are also some other package managers like yum and yast supported. Click here

JustRandom
  • 487
  • 1
  • 9
  • 19
  • Can you please clarify (in an edit or comment) why it is necessary to *uninstall all previously installed java versions via apt purge before installing this java version*? I'm reluctant to do it because it took some effort to set up and I don't want to have to redo it if Liberica doesn't work out. – pateksan Jan 02 '21 at 02:29
  • 1
    It is just recommended by me. If you need multiple java versions installed then don't do this of course. Having only one java version installed makes running applications easier, because you can be sure that the java command in the operating system really points to the liberica java version and so the right version is used for executing. – JustRandom Jan 02 '21 at 14:46
-1

Use Oracle JDK (even if only as a temporary workaround)

I already said this just now in an answer to this question for 18.04

For any learners looking for a bit of basic practice with javafx, installing Oracle's Java 8 (which has javafx built-in) might be a better solution then messing about with open packages. There are great instructions here

You can continue efforts getting openjfx installed, but this will keep your learning going.

I don't know anything about docker files and automated pipelines, but I suspect a lot of people who come to this question are just early learners doing a manual installation.

NB this workaround has already been suggested by aran in a comment to the OP, please consider upvoting that comment.

pateksan
  • 160
  • 1
  • 12
  • 3
    I agree that just going with the Oracle JDK is a good way for people to go if they just want to learn. In my case, it's not an option because this is for production use and my company has some issues with Oracle's licensing. – NateW Jun 09 '20 at 18:39