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?

3

3 Answers 3

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

7
  • Is this all you had to do? Did you have to go through this 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 6, 2020 at 0: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 Feb 16, 2020 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, 2020 at 8:31
  • see 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 May 12, 2020 at 18:04
  • 2
    I've created the new question stackoverflow.com/questions/61783369/… in hopes to find a more current fix since the fix in this answer recently stopped working.
    – NateW
    May 13, 2020 at 19:34
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!

-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.

3
  • 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. Jun 7, 2020 at 7: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 7, 2020 at 13:52
  • 1
    - i can confirm that JavaFX with OracleJDK runs mostly out of the box. A notable exception is Raspberry PI see can4eve.bitplan.com/index.php/JavaFX Jun 8, 2020 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.