24

I have Java 8 and Ubuntu 18.04. I'm using NetBeans and when tried to make some program, it couldn't be done because JavaFX is missing.

I installed Java JDK with NetBeans from Oracle's site and thought everything is included but obviously I didn't check it well.

What should I do, what should I install? I'm not so good at this and don't know if problem is with Ubuntu or Java. :(

maria
  • 915
  • see also https://stackoverflow.com/questions/56166267/how-do-i-get-java-fx-running-with-openjdk-8-on-ubuntu-18-04-2-lts – Wolfgang Fahl Jun 25 '19 at 13:24

5 Answers5

27

In the Ubuntu 16.04 and later default repositories JavaFX is packaged as a separate package named openjfx. To install it in Ubuntu 18.04, open the terminal and type:

sudo apt install openjdk-8-jdk openjfx

The openjfx package can also be installed from the default repositories in all currently supported versions of Ubuntu.

Check that JDK 8 is selected as the default Java version in Netbeans -> Tools -> Options -> Java -> Nashorn tab -> click the Manage Platforms button -> click the Add Platform button -> click the radio button marked Java Standard Edition -> click the Next button -> browse to /usr/lib/jvm/java-8-openjdk-amd64 and select it as the default Java version.

Optionally you can install openjdk-11-jdk instead of or alongside openjdk-8-jdk. openjfx works with both openjdk-8-jdk and openjdk-11-jdk in Netbeans in Ubuntu 18.04. I am using Netbeans 8.2 10.0 in Ubuntu 18.04.

karel
  • 114,770
  • Thanks, your commands work but still with my java.io library I get the error Exception in thread "main" java.lang.IllegalStateException: Toolkit not initialized ...I don't know why – maria Nov 14 '18 at 17:49
  • @Mara I'm sorry, I found the error you got was in my JavaFX code because I didn't copy all the code to the end in Pastebin the first time that I uploaded it. I left out the two curly braces at the end the first time I uploaded it. I uploaded the code again here. The name of my JavaFX project in Netbeans is HelloWorldFX. – karel Nov 15 '18 at 00:26
  • 1
    JavaFX works for me on 18.04 only after installing JDK 8 AND changing the project SDK to 8 (doesn't want to work on SDK 10) in IntelliJ. – Line Feb 06 '19 at 09:04
  • It must be a JDK paths issue in IntelliJ because JDK 8 and 11 both work alongside each other in Netbeans in Ubuntu 18.04 with the same JavaFX package for both of them. – karel Feb 06 '19 at 09:27
  • I checked my whole hard drive but I can't seem to find a javafx distribution after installing openjfx. it's not in /usr/lib/jvm//jre/lib/ext/ where I found it to be on other devices such as my laptop running manjaro. :/ – Niklas Vest Jun 18 '19 at 09:42
  • JAVAFX_HOME path on Ubuntu Open the terminal and run: cd /usr/share/java/ && ls | grep javafx – karel Jun 18 '19 at 09:58
  • In Ubuntu 18.04.2 you get both java 8 & 11 jdks and openjfx. You can use update-alternatives to pick between the 8 & 11 java and javac but that doesn't work for openjfx. The only way I know to use openjfx 8, is to downgrade openjfx 11 to 8 and hold the openjfx packages so they don't get upgraded to 11 next upgrade. – Chris Good Jul 30 '19 at 12:32
  • @karel, I'll give JAVAFX_HOME a try. It would be great if I can use both jfx 8 & 11 on the same setup. Thanks for the info. – Chris Good Jul 30 '19 at 12:43
  • @karel, I was wrong in my 2nd previous comment. You don't get both v8 & v11 openjfx. You only get 1 of them. – Chris Good Aug 01 '19 at 09:27
  • @ChrisGood That's the same as what I wrote about in this comment. – karel Aug 01 '19 at 09:32
  • Here's the rest of my comment before I hit enter by accident: I was misled by 'apt list --installed -a' which shows installed AND uninstalled packages. So by default you only get v11. So without going to a lot of trouble to manually install javafx 8 jars in some alternative place, I don't see how it is possible to use JAVAFX_HOME to be able to pick jfx 8 or 11 at runtime. I guess I'd have to do the same for the jdk also, as you can only have jdk 8 OR 11 selected by update-alternatives. – Chris Good Aug 01 '19 at 09:41
  • Now it makes more sense. I don't have a JAVAFX_HOME. Instead I switch back and forth between Java 8 and Java 11 in the NetBeans settings. – karel Aug 01 '19 at 09:43
4

I think the easiest way is to install sdkman. Once installed, check for all the available candidates:

$ sdk list java

which will show a wide variety of options. You may select one with the FX suffix. In my case I can see something like this:

 Azul ZuluFX   |     | 11.0.2       | zulufx  |            | 11.0.2-zulufx       
               |     | 8.0.202      | zulufx  |            | 8.0.202-zulufx      
 BellSoft      |     | 12.0.2       | librca  |            | 12.0.2-librca       
               |     | 11.0.4       | librca  |            | 11.0.4-librca       

So, you can install it using this command:

$ sdk install java 11.0.2-zulufx   

Or,

$ sdk install java 8.0.202-zulufx # if you want java 8

And you are good to go! I hope this helps! :)

1

This issue can be fixed by adding the openjfx path and modules as arguments when running the javafx application, I already posted the solution on this link.
Good luck
Lotfi

0

I had the same problem. I installed openjdk, but it wasn't compatible with openjfx, since the only version available is openjfx 11.

So i searched for a while and stumbled across ZuluFX. I installed it with sdkman, which you can download from their website. After installing sdkman, just install zulufx.

$ sdk install java 8.0.202-zulufx

Your $JAVA_HOME should be the path where sdk man is installed -> /home/valentin/.sdkman/candidates/java/current

Now you can switch you JDK to that path in Netbeans and it should just work fine!

0

Liberica JDK "full" contains JavaFX. There are 8, 11 and latest versions as .tar.gz ans as .deb packages:

https://bell-sw.com/java.html

It is also available in sdkman as mentioned above (with updates).

For regular apt updates there is an official apt repository:

https://www.bell-sw.com/pages/repositories/#apt

To install version 11 containing FX use

sudo apt install bellsoft-java11-full

https://bell-sw.com/pages/repositories/#packages-versioning

Dmitry
  • 1