Linux Mint java and JavaFX

user02814 :

I am running Linux Mint 19.1 and have installed the OpenJDK Runtime Environment. I do not have eclipse installed and this question, which does not provide sufficient detail to make it clear what OP's question actually is, doesn't seem particularly relevant despite the title.

> java --version
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed mode, sharing)

Since installing Java, I have also installed javafx using the information I found on Ask Ubuntu. apt reports the following:

> sudo apt install openjdk-11-jdk openjfx
...
  openjdk-11-jdk is already the newest version (11.0.3+7-1ubuntu2~18.04.1).
  openjfx is already the newest version (11.0.2+1-1~18.04.2).

The problem I am now having is that the line import javafx; results in the following error:

> java CheckJavaFX.java
CheckJavaFX.java:1: error: package javafx.application does not exist
import javafx.application.Application;
                     ^
1 error
error: compilation failed

How do I resolve the problem?

José Pereda :

Based on what you have done:

sudo apt install openjdk-11-jdk openjfx

You have installed two different things:

  • On one side, openjdk-11-jdk installs the latest JDK 11.0.3, based on this detail.

  • On the other, openjfx installs JavaFX 11.0.2 according to this.

If you check the latter, you are just downloading the JavaFX SDK (the JavaFX jars and native libraries) to a given location, but you are not bundling it with the JDK.

This explain the error you get, as the JDK doesn't have any JavaFX module included:

error: package javafx.application does not exist

Even if you try to do a "manual merge", by copying those files to the JDK location, that won't work either.

In order to use JavaFX 11+ directly from the SDK, you have to add the jars to the module-path, like explained in the documentation at https://openjfx.io/openjfx-docs/.

Alternatively you can use Maven or Gradle build tools and the JavaFX plugins, that won't require the SDK, and will use Maven Central to retrieve the JavaFX modules.

Finally, if you sill want to use JavaFX bundled with the JDK (without module-path), you can either download a different distribution that bundles it (there are a few out there), or you can "merge" the JDK and the JavaFX SDK yourself, to produce a custom image that combines both, as explained here: https://openjfx.io/openjfx-docs/#modular, section Custom JDK+JavaFX image.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=123860&siteId=1
Recommended