aGer
aGer

Reputation: 486

What is the JavaFX runtime?

In the documentation it is often said that 'the JavaFX runtime' is doing XY in the background - but what is "the runtime"? If I understand correct (please edit) the runtime is made of the following parts:

My question is: What is the runtime?

Upvotes: 3

Views: 5853

Answers (3)

mike rodent
mike rodent

Reputation: 15642

jewelsea's update for Java 9+ changes again with Java 11.

Java 11 does not come bundled with JavaFX: you have to get it and link it yourself.

You can in fact do this without knowing all the gory details if you use Gradle. A build.gradle file will typically contain these lines:

plugins {
    ...
    id 'org.openjfx.javafxplugin' version '0.0.8'
}
...
javafx {
    version = "13"
    modules = [ 'javafx.controls', 'javafx.fxml' ... ]
}
...

The gory details for configuring a non-Gradle JavaFX project in an IDE like IntelliJ can be found here. You have to download and extract a (recent) JavaFX JDK and then include this as a library, and then as a module.

If ever you need to run at the CLI (or just to see what's happening) do this sort of thing. Assuming you have extracted a JavaFX JDK 11 from here to a directory (created by you) such as ~/.java/JavaFX. And assuming you have a class in package sample, called Main, which extends javafx.application.Application:

java -cp .:~/.java/JavaFX/javafx-sdk-11.0.2/lib/*.jar --module-path ~/.java/JavaFX/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml sample.Main

... looks complicated but in fact it's quite simple: you configure the classpath with the current directory and all the .jars in the library ... but you also have to specify that this is a module path, and then say which modules you need. NB Windows will need the other slash, and elements in the classpath separated by ";" rather than ":", of course.

Upvotes: 0

jewelsea
jewelsea

Reputation: 159386

J Woodchucks answer addresses Java 7 and 8. This answer just addresses Java 9+.

For JRE 9+, jfxrt.jar does not exist and is replaced by .jmods in the <JRE_HOME>/jmods directory. This was done as part of JDK modularization. Additional required native libraries for JavaFX are included in the <JRE_HOME>/lib directory. JavaFX will not work without the required native libraries.

You can use the full JRE runtime provided by a vendor such as Oracle (and probably a third party OpenJDK provider such as an Ubuntu or Redhat JRE package). This will include all required modules and libraries to run JavaFX as well as some that form part of the JRE but are not necessarily required to run a JavaFX application.

Note, for Java 8, some OpenJDK vendors chose not to include the JavaFX runtime as part of their Java distributions, requiring either an install of an additional package a custom build of the OpenJDK or a switch to a java runtime which does include JavaFX (such as the Oracle JRE). Hopefully, for Java 9, all OpenJDK vendors will provide full JRE runtimes that include JavaFX but you might need to wait until the OpenJDK vendors release generally available Java 9 runtimes to find out.

It is possible to create a custom modular runtime for JavaFX with Java 9 which eliminates some JRE modules that your application may not need. A custom modular runtime for JavaFX requires the javafx.* modules that you wish to use, any dependent modules of those modules and any necessary native libraries. You can package your JavaFX application with a custom runtime using the JavaFX packager. The packaging technique of the JDK 9 javafxpackager is based upon the Java 9 module system; the internal implementation of which uses the java linker.

The java packager can further package the custom runtime as part of a self-contained application install package (if desired). A self-contained application contains your Java or JavaFX application and the JRE needed to run the application.

Once Java 9 undergoes its general availability release, I am sure that Oracle will provide some further official documentation and samples that demonstrates how to create a custom modular runtime for a JavaFX application and use it as part of a self-contained application.

Additionally, third party vendors such as gluon provide tools to package applications with custom JavaFX runtimes on various devices such as iPads and Android phones.

Upvotes: 4

Woodchuck
Woodchuck

Reputation: 4414

The JavaFX Runtime being referred to is the jfxrt.jar jar you mention. It contains the libraries required for JavaFX, including the JavaFX launcher thread (LauncherImpl in package com.sun.javafx.application) and Application class. The location of jfxrt.jar (whether you have the JDK or JRE) is:

I don't see LauncherImpl documented in Oracle's javadoc, so linked to OpenJDK version above.

Upvotes: 2

Related Questions