Question
Why is JavaFX not included in OpenJDK 8 on Ubuntu Wily (15.10)?
java -version
openjdk version "1.8.0_66-internal"
OpenJDK Runtime Environment (build 1.8.0_66-internal-b17)
OpenJDK Server VM (build 25.66-b17, mixed mode)
Answer
JavaFX is a powerful framework used for building rich internet applications in Java, but it is not bundled with OpenJDK 8 on some Linux distributions, including Ubuntu Wily (15.10). This separation is due to several factors such as licensing, package maintenance, and the focus of certain distributions.
// Sample code to include JavaFX in your project in Eclipse
// Make sure to add the required JavaFX library to your project build path.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class HelloFX extends Application {
@Override
public void start(Stage stage) {
Button btn = new Button("Say 'Hello World'");
btn.setOnAction(e -> System.out.println("Hello World!"));
Scene scene = new Scene(btn, 200, 100);
stage.setScene(scene);
stage.setTitle("Hello FX");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Causes
- JavaFX was separated from the JDK to allow for independent development and distribution.
- The JavaFX libraries are not part of the default OpenJDK package for Ubuntu, which focuses on providing the core Java functionality.
- Licensing and redistribution concerns delayed the inclusion of JavaFX in OpenJDK distributions.
Solutions
- Download and install OpenJFX separately using the package manager: `sudo apt-get install openjfx`.
- Add the JavaFX library to your Eclipse project build path to resolve 'javafx couldn't be resolved' errors.
- Ensure that your Java version is compatible with JavaFX, especially if using features specific to later Java versions.
Common Mistakes
Mistake: Not installing the OpenJFX package separately after installing OpenJDK.
Solution: Ensure you run `sudo apt-get install openjfx` to install JavaFX alongside OpenJDK.
Mistake: Failing to configure the JavaFX library in the Eclipse build path.
Solution: Right-click your project, go to Properties -> Java Build Path -> Libraries, and add the JavaFX library.
Helpers
- JavaFX
- OpenJDK 8
- Ubuntu Wily 15.10
- install JavaFX
- Eclipse JavaFX error