What is the JavaFX runtime?

Viewed 5190

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:

  • all classes etc. of the JavaFX framework, located in package javafx and stored in the jxfrt.jar file
  • the 'JavaFX-Launcher' thread
  • the 'JavaFX Appliaction Thread': all Objects and threads running your JavaFX application. They are created by the JavaFX-Launcher thread when the Appplication.launch() method was called.

My question is: What is the runtime?

3 Answers

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.

Related