132

I'm trying to decide whether I could switch to JavaFX for the user interface of my Java application. Most of my users would be using the Oracle JRE, which has JavaFX integrated these days. However, some are using OpenJDK (on linux). This (old) question suggests that OpenJDK deals very badly with JavaFX. According to this question, the alternative OpenJFX will only be fully integrated into OpenJDK in version 9. So my question is twofold:

  • Is the JavaFX support in OpenJDK still so bad?
  • If so, are there any Linux distributions that already offer an OpenJFX package so users wouldn't have to build it themselves?
Community
  • 1
  • 1
mdriesen
  • 1,492
  • 2
  • 10
  • 11

8 Answers8

120

JavaFX is part of OpenJDK

The JavaFX project itself is open source and is part of the OpenJDK project.

However, the OpenJDK project includes many projects, including incubating projects and other projects, such as OpenJFX, whose source and implementation are not shipped as part of some JDK/JRE distributions (e.g. Oracle JDK 11+ implementations and many open-source JDK Linux package installations do not include JavaFX runtimes).

Modern JavaFX distributions are modules

JavaFX is not part of most JDK 11+ downloads, it is usually downloaded by developers as modules or a separate SDK.

Specifically for JavaFX 11+, as detailed on the https://openjfx.io site:

JavaFX runtime is available as a platform-specific SDK, or as a number of jmods, or as a set of artifacts in Maven Central.

This means that JavaFX can be used from any modern JDK running on a supported platform, by including the appropriate JavaFX modules (available from openjfx or Maven Central) on the runtime module path.

All JavaFX modules available from openjfx are open source implementations that contain no closed source code.

For distribution of JavaFX-based applications to end-users, it is advised to package a run-time image distribution based on the JDK and JavaFX modules + required dependent library code and application code. A full discussion of this packaging is out of scope for this answer, but one can create a distribution based purely on open-source JDK+JavaFX+library+application code if desired. See the openjfx.io documentation on run-time images for some more (though not comprehensive) information on this.

Update Sep 2021

Also, see the related question:

Which covers information regarding Java 8 and also some later versions.

Update Dec 2019

For current information on how to use Open Source JavaFX, visit https://openjfx.io. This includes instructions on using JavaFX as a modular library accessed from an existing JDK (such as an Open JDK installation).

The open source code repository for JavaFX is at https://github.com/openjdk/jfx.

At the source location linked, you can find license files for open JavaFX (currently this license matches the license for OpenJDK: GPL+classpath exception).

The wiki for the project is located at: https://wiki.openjdk.java.net/display/OpenJFX/Main

If you want a quick start to using open JavaFX, the Bellsoft's Liberica JDK distributions provide pre-built OpenJDK binaries that include OpenJFX for a variety of platforms.

For distribution as self-contained applications, Java 14 is scheduled to implement JEP 343: Packaging Tool, which "Supports native packaging formats to give end users a natural installation experience. These formats include msi and exe on Windows, pkg and dmg on macOS, and deb and rpm on Linux.", for deployment of OpenJFX based applications with native installers and no additional platform dependencies (such as a pre-installed JDK).


Older information that may become outdated over time

Building JavaFX from the OpenJDK repository

You can build an open version of OpenJDK (including JavaFX) completely from source which has no dependencies on the Oracle JDK or closed source code.

Update: Using a JavaFX distribution pre-built from OpenJDK sources

As noted in comments to this question and in another answer, the Debian Linux distributions offer a JavaFX binary distibution based upon OpenJDK:

(currently this only works for Java 8 as far as I know).

Differences between Open JDK and Oracle JDK with respect to JavaFX

The following information was provided for Java 8. As of Java 9, VP6 encoding is deprecated for JavaFX and the Oracle WebStart/Browser embedded application deployment technology is also deprecated. So future versions of JavaFX, even if they are distributed by Oracle, will likely not include any technology which is not open source.

Oracle JDK includes some software that is not usable from the OpenJDK. The components that relate to JavaFX:

  • The ON2 VP6 video codec, which is owned by Google and Google has not open sourced.
  • The Oracle WebStart/Browser Embedded application deployment technology.

This means that an open version of JavaFX cannot play VP6 FLV files. This is not a big loss as it is difficult to find VP6 encoders or media encoded in VP6.

Other more common video formats, such as H.264 will playback fine with an open version of JavaFX (as long as you have the appropriate codecs pre-installed on the target machine).

The lack of WebStart/Browser Embedded deployment technology is really something to do with OpenJDK itself rather than JavaFX specifically. This technology can be used to deploy non-JavaFX applications.

It would be great if the Open Source community developed a deployment technology for Java (and other software) which completely replaced WebStart and Browser Embedded deployment methods, allowing a nice light-weight, low impact user experience for application distribution. I believe there have been some projects started to serve such a goal, but they have not yet reached a high maturity and adoption level.

Personally, I feel that WebStart/Browser Embedded deployments are legacy technology and there are currently better ways to deploy many JavaFX applications (such as self-contained applications).

Update Dec, 2019:

An open source version of WebStart for JDK 11+ has been developed and is available at https://openwebstart.com.

Who needs to create Linux OpenJDK Distributions which include JavaFX

It is up to the people which create packages for Linux distributions based upon OpenJDK (e.g. Redhat, Ubuntu etc) to create RPMs for the JDK and JRE that include JavaFX. Those software distributors, then need to place the generated packages in their standard distribution code repositories (e.g. fedora/red hat network yum repositories). Currently this is not being done, but I would be quite surprised if Java 8 Linux packages did not include JavaFX when Java 8 is released in March 2014.

Update, Dec 2019:

Now that JavaFX has been separated from most binary JDK and JRE distributions (including Oracle's distribution) and is, instead, available as either a stand-alone SDK, set of jmods or as a library dependencies available from the central Maven repository (as outlined as https://openjfx.io), there is less of a need for standard Linux OpenJDK distributions to include JavaFX.

If you want a pre-built JDK which includes JavaFX, consider the Liberica JDK distributions, which are provided for a variety of platforms.

Advice on Deployment for Substantial Applications

I advise using Java's self-contained application deployment mode.

A description of this deployment mode is:

Application is installed on the local drive and runs as a standalone program using a private copy of Java and JavaFX runtimes. The application can be launched in the same way as other native applications for that operating system, for example using a desktop shortcut or menu entry.

You can build a self-contained application either from the Oracle JDK distribution or from an OpenJDK build which includes JavaFX. It currently easier to do so with an Oracle JDK.

As a version of Java is bundled with your application, you don't have to care about what version of Java may have been pre-installed on the machine, what capabilities it has and whether or not it is compatible with your program. Instead, you can test your application against an exact Java runtime version, and distribute that with your application. The user experience for deploying your application will be the same as installing a native application on their machine (e.g. a windows .exe or .msi installed, an OS X .dmg, a linux .rpm or .deb).

Note: The self-contained application feature was only available for Java 8 and 9, and not for Java 10-13. Java 14, via JEP 343: Packaging Tool, is scheduled to again provide support for this feature from OpenJDK distributions.

Update, April 2018: Information on Oracle's current policy towards future developments

jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • @Emmanuel, Thanks for your work on this. JavaFX is part of the JDK, so (at least until the JDK becomes modularized) I'm not sure why there would be a separate OpenJFX package instead of including all of the necessary runtime files in the standard OpenJDK package (as is done with the Oracle JDK distributions). The [open-jfx mailing list](http://mail.openjdk.java.net/mailman/listinfo/openjfx-dev) would be a good place if further discussion is required. – jewelsea Sep 18 '14 at 23:31
  • A separate package gives a degree of flexibility if someone is interested in the JDK but not in JavaFX. Isn't modularization an objective for Java 9 after all? :) – Emmanuel Bourg Sep 19 '14 at 07:26
  • @Emmanuel, Ubuntu 14.10 has one too now. Installed it, seems to work fine. – mdriesen Nov 18 '14 at 19:31
  • @mdriesen Yes this is the same package shared with Debian, thank you for the feedback. – Emmanuel Bourg Nov 19 '14 at 09:09
  • 11
    "Currently this is not being done, but I would be quite surprised if Java 8 Linux packages did not include JavaFX when Java 8 is released in March 2014". You must be surprised as OpenJDK 8 doesn't include OpenJFX. –  Nov 22 '14 at 07:45
  • @PashaTurok Debian/Ubuntu has OpenJFX packages, see comments. – jewelsea Nov 22 '14 at 17:48
  • I must be missing something as I search for "JFX" in Synaptic and find nothing, in Ubuntu 14.04. – NoBugs Feb 01 '16 at 05:18
  • @NoBugs you can find OpenJFX packages for Debian (which I presume work in Ubuntu because, as far as I know, Ubuntu is derived from Debian), at the link provided by Emmanuel Borg: http://packages.qa.debian.org/o/openjfx.html – jewelsea Feb 01 '16 at 17:51
  • 2
    Arch Linux also has packages for openjfx: https://www.archlinux.org/packages/?name=java-openjfx – Maciej Łoziński Aug 20 '16 at 14:15
  • 2
    @NoBugs This may be a little too late a response to be useful, but Ubuntu 14.04 doesn't include OpenJDK 8, which is why you can't find the corresponding JFX package. I can't recall which Ubuntu release introduced it, but it is definitely available in Ubuntu 16.04 - together with the "openjfx" package. – Mike Allen Dec 02 '16 at 02:02
  • I tried installing the open JDK 8 for windows from here: https://jdk.java.net/java-se-ri/8-MR3 and It doesn't seem to have JavaFX bundled with it. I tried using it with NetBeans. – Edward Eddy67716 Dec 28 '20 at 07:50
  • @EdwardEddy67716 The build of OpenJDK 8 you tried does not include JavaFX. I don't recommend using JavaFX 8 as it is obsolete. I recommend using up-to-date software as detailed at [openjdk.io](https://openjfx.io/). If you must use the outdated OpenJDK 8 ,then you can build OpenJFX 8 for it following the instructions at [Building OpenJFX 8u](https://wiki.openjdk.java.net/display/OpenJFX/Building+OpenJFX+8u). If you must use JavaFX 8 but can use Oracle JavaFX 8, you can [download it from Oracle](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html). – jewelsea Jan 01 '21 at 03:41
52

For me this worked.

$ sudo apt-get install openjfx
Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103
Vineel
  • 1,430
  • 14
  • 18
  • 3
    Probably the easiest way to add JavaFX to your Linux JDK – Reimeus Aug 01 '16 at 16:18
  • Although this is the right answer for many, some OSs don't provide this package. For those that don't `webupd8 PPA` for Ubuntu and `fedy` desktop installer for Fedora are two quick ways to setup the latest Oracle JDK/JRE which includes JavaFX. – tresf Sep 16 '16 at 19:45
  • 3
    For Ubuntu 18.04, it still depends on Java 8, but the default one is java 10. If you install it, you'll end up with 2 javas. – jgomo3 Jun 15 '18 at 00:49
  • According to [How to install openjfx along with openjdk-11?](https://askubuntu.com/questions/1036098/how-to-install-openjfx-along-with-openjdk-11), for Java versions 11+, to use JavaFX, rather than `apt-get install openjfx` (which currently works only for Java 8), you can use instructions from the https://openjfx.io web site, where JavaFX is "available as a platform-specific SDK, as a number of jmods, and as a set of artifacts in maven central.". – jewelsea Dec 26 '19 at 23:05
  • A Debian openjfx package has been released for OpenJDK-11 at https://tracker.debian.org/pkg/openjfx, so perhaps this method. `sudo apt-get install openjfx`, will continue to be supported and work for later JavaFX and ubuntu releases. Note that the Debian openjfx packages don't appear to be updated as frequently as the libraries distributed by openjfx.io, so if you wish to use the most up to date version, you are probably best off using an openjfx.io distribution. – jewelsea Jan 24 '20 at 19:24
12

As a quick solution you can copy the JavaFX runtime JAR file and those referenced from Oracle JRE(JDK) or any self-contained application that uses JavaFX(e.g. JavaFX Scene Builder 2.0):

cp <JRE_WITH_JAVAFX_HOME>/lib/ext/jfxrt.jar     <JRE_HOME>/lib/ext/
cp <JRE_WITH_JAVAFX_HOME>/lib/javafx.properties <JRE_HOME>/lib/
cp <JRE_WITH_JAVAFX_HOME>/lib/amd64/libprism_*  <JRE_HOME>/lib/amd64/
cp <JRE_WITH_JAVAFX_HOME>/lib/amd64/libglass.so <JRE_HOME>/lib/amd64/
cp <JRE_WITH_JAVAFX_HOME>/lib/amd64/libjavafx_* <JRE_HOME>/lib/amd64/

just make sure you have the gtk 2.18 or higher

Community
  • 1
  • 1
  • I can't find where openjfx is installed in Ubuntu 18.04, but I stole these jars and other files from another program installed in my hard disk (you can check something like phpstorm or clion :) ) and it worked like a charm. Thank you – Heichou Aug 11 '19 at 23:53
  • I copied over the files from JDK1.8.0_251 (Oracle Java 1.8) to java-8-openjdk-amd64 (ubuntu repository OpenJDK 8). Was still unable to run jar files with JavaFX. But when I simply linked to the jfxrt.jar as an external library jar in my Eclipse build path, programs did run within Eclipse context. Running "apt-cache policy libgtk2.0-0" gave "Installed: 2.24.32-1ubuntu1" – Phil Freihofner Apr 26 '20 at 19:51
7

Also answering this question:

Where can I get pre-built JavaFX libraries for OpenJDK (Windows)

On Linux its not really a problem, but on Windows its not that easy, especially if you want to distribute the JRE.

You can actually use OpenJFX with OpenJDK 8 on windows, you just have to assemble it yourself:

Download the OpenJDK from here: https://github.com/AdoptOpenJDK/openjdk8-releases/releases/tag/jdk8u172-b11

Download OpenJFX from here: https://github.com/SkyLandTW/OpenJFX-binary-windows/releases/tag/v8u172-b11

copy all the files from the OpenFX zip on top of the JDK, voila, you have an OpenJDK with JavaFX.

Update:

Fortunately from Azul there is now a OpenJDK+OpenJFX build which can be downloaded at their community page: https://www.azul.com/downloads/zulu-community/?&version=java-8-lts&os=windows&package=jdk-fx

Mauli
  • 16,863
  • 27
  • 87
  • 114
  • thanks. I checked the AdoptOpenJDK github-site but it says "legacy repository". Do you know where a newer matching OpenJFX-binary is available matching the builds of the new repo https://github.com/AdoptOpenJDK/openjdk8-binaries/releases ? – Houtman Dec 05 '18 at 12:48
  • do you mean with this "copy all the files from the OpenFX zip on top of the JDK" simply copy the unzipped files at the diverse JDK?But that doesn't sound the best because the library has many folder called same as all the JDK. So sure I am missing something – Carmine Tambascia Aug 20 '21 at 12:26
3

Try obuildfactory.

There is need to modify these scripts (contains error and don't exactly do the "thing" required), i will upload mine scripts forked from obuildfactory in next few days. and so i will also update my answer accordingly.

Until then enjoy, sir :)

DeepSidhu1313
  • 805
  • 15
  • 31
1

I needed to run a .jar in Windows which required Java FX. I also didn't need the JDK part.

Note: I didn't bother changing the PATH/JAVA_HOME variables because it wasn't needed in my case, for a more complete walkthrough see: How to install OpenJDK 11 on Windows?

  1. Download OpenJDK and Java FX (jmods) (version 17.0.2 for this example)

https://jdk.java.net/17/

https://gluonhq.com/products/javafx/

  1. Unzip the downloaded files. Copy/move the .jmod files from the Java FX directory to the OpenJDK dir (jmods subdirectory).

  2. Create a JRE with jlink, use this web app to get the exact command line options: https://justinmahar.github.io/easyjre/

PowerShell snippet:

$Version = '17.0.2'
$DownDir = 'path\to\dir\with\.zip'
$JdkDir = "jdk-${Version}"
$JavaFxDir = "javafx-jmods-${Version}"
$NewDir = "jre-${Version}+javafx"
$ProgramFilesDir = "$env:ProgramFiles\OpenJDK\${NewDir}"
Set-Location -Path $DownDir

# Unzip archives
Expand-Archive -Path "openjfx-${Version}_windows-x64_bin-jmods.zip" -Destination .
Expand-Archive -Path "openjdk-${Version}_windows-x64_bin.zip" -Destination .

# Create a custom runtime image using jlink, excluding all modules that start with 'jdk.'
Copy-Item -Path "${JavaFxDir}\*.jmod" -Destination "${JdkDir}\jmods"
$Mods = Get-Item -Path "$JdkDir\jmods\*.jmod" | ? { !($_.Name -like 'jdk.*') }
$Mods = $Mods.Name -replace '.jmod$' -join ','
& "${JdkDir}\bin\jlink.exe" --output $NewDir --compress=2 --no-header-files --no-man-pages --module-path "${JdkDir}\jmods" --add-modules $Mods

# (Optional) Delete unzipped directories
Remove-Item -Path $JdkDir,$JavaFxDir -Recurse

# Test if the .jar works
$jar = Get-Item "\path\to\.jar"
& "${NewDir}\bin\javaw.exe" -jar $jar

# (Optional) Copy the new directory to Program Files (requires admin privileges), zip it to distribute to other computers and delete it
Copy-Item -Path $NewDir -Destination $ProgramFilesDir -Recurse
Compress-Archive -Path $NewDir -DestinationPath "openjdk-${Version}_jre+javafx_windows-x64_bin.zip"
Remove-Item -Path $NewDir -Recurse

# (Optional) Create shortcut in Desktop
$Lnk = "$env:USERPROFILE\Desktop\Shortcut.lnk"
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($Lnk)
$Shortcut.TargetPath = "${ProgramFilesDir}\bin\javaw.exe"
$Shortcut.WorkingDirectory = $jar.DirectoryName
$Shortcut.Arguments = '-jar "' + $jar.FullName + '"'
$Shortcut.Save()
Bangaio
  • 95
  • 6
0

According to Oracle integration of OpenJDK & javaFX will be on Q1-2014 ( see roadmap : http://www.oracle.com/technetwork/java/javafx/overview/roadmap-1446331.html ). So, for the 1st question the answer is that you have to wait until then. For the 2nd question there is no other way. So, for now go with java swing or start javaFX and wait

Stathis Andronikos
  • 1,259
  • 2
  • 25
  • 44
0

I used Amazon Coretto JDK. This had all FX Components I needed.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32235716) – cabad Jul 16 '22 at 14:13