19

When trying to compile an JavaFX application in the environment:

java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)

cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.2 LTS"

I get the error-message:

cannot access javafx.event.EventHandler
[ERROR]   class file for javafx.event.EventHandler not found

I tried to find a solution by following these links:

The most promising actions where to

  1. install openjfx with apt install openjfx
  2. set the JAVA_HOME environment variable to /usr/lib/jvm/java-8-openjdk-amd64

But the error persists.

What needs to be done to get OpenJDK 8 and JavaFX working on Ubuntu 18.04.2 LTS?

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186

3 Answers3

46

The hint from

https://github.com/JabRef/help.jabref.org/issues/204

helped. The commands:

apt purge openjfx
apt install openjfx=8u161-b12-1ubuntu2 libopenjfx-jni=8u161-b12-1ubuntu2 libopenjfx-java=8u161-b12-1ubuntu2
apt-mark hold openjfx libopenjfx-jni libopenjfx-java

fixed the problem. Many thanks to https://github.com/Druidefix for this. (If you'd like to answer this yourself I'll happily delete my own answer ...)

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
  • Is this all you had to do? Did you have to go through [this](https://wiki.openjdk.java.net/display/OpenJFX/Using+an+IDE#UsinganIDE-JDK-8Only:Deletejfxrt.jar(ormoveittoadifferentdirectory)) or similar? Have you been able to get it going without having to use gradle, maven, e(fx)clipse? There seems to be tons of guidance out there, it seems there are a lot of ways to get openjfx going, articles and forums talking about building, modules etc etc. Nothing seems to work for me and I'm getting a bit desperate. I was on xubuntu 19.10, but also installed 18.04 hoping your steps would help - no luck. – pateksan Feb 06 '20 at 00:12
  • I tried this in a clean virtual machine and it worked. May be trying it with docker / travis will give you some hint on what's missing – Wolfgang Fahl Feb 16 '20 at 12:42
  • 3
    In the current ubuntu version (20.04) these packages are no longer available. Nowadays openjfx defaults to v11. – Michiel May 12 '20 at 08:31
  • see http://wiki.bitplan.com/index.php/Java8 - the newer java defaults leave a big mess in quite a few environments due to the large number of incompatibilities – Wolfgang Fahl May 12 '20 at 18:04
  • @Michiel, if you find a current solution, would you share it here? I've been using the "pin to 8u161-b12-lubuntu2" solution for a while now for a docker definition in an automated pipeline and it just recently stopped working, presumably because ubuntu removed those packages. I'm not sure what to do now. – NateW May 13 '20 at 18:26
  • 2
    I've created the new question https://stackoverflow.com/questions/61783369/install-openjdkopenjfx-8-on-ubuntu-20 in hopes to find a more current fix since the fix in this answer recently stopped working. – NateW May 13 '20 at 19:34
  • @NateW I gave up and made the switch to java 11 :( – Michiel May 15 '20 at 09:02
3

What I did was build it from source. The instructions here on the OpenJDK wiki worked for me. Once I built it, I had to put the jars in the right place, like this other stackoverflow post talked about.

cd build/sdk/
sudo cp -R rt/lib /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/
sudo cp ./lib/ant-javafx.jar /usr/lib/jvm/java-8-openjdk-amd64/lib/
sudo cp ./lib/javafx-mx.jar /usr/lib/jvm/java-8-openjdk-amd64/lib/

After that I was able to compile my project!

Marthinwurer
  • 116
  • 1
  • 6
-4

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

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.

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

pateksan
  • 160
  • 1
  • 12
  • The question is specifically about OpenJDK and the need for it in light of Oracles new license politics. Pointing to the license-problematic Oracle JDK is not helpful in this context since it is the problem not the solution. – Wolfgang Fahl Jun 07 '20 at 07:26
  • @WolfgangFahl I can see what you're saying, but I'm pretty sure this question gets a lot of visits from people who can't get javafx going and are not that bothered about politics (at least in the short term). Feel free to downvote at your pleasure, but personally I regret not installing Oracle JDK earlier. I was refusing to do it because it was not "hardcore open source/free" and I think it was a mistake to get so hung up on principles. In hindsight, Oracle JDK would have been perfectly fine for first steps in javafx and I could be trying to run openjfx alongside learning javafx itself. – pateksan Jun 07 '20 at 13:52
  • 1
    - i can confirm that JavaFX with OracleJDK runs mostly out of the box. A notable exception is Raspberry PI see http://can4eve.bitplan.com/index.php/JavaFX – Wolfgang Fahl Jun 08 '20 at 14:06