I installed Eclipse IDE today on my Ubuntu Linux and then installed JavaFX using ‘Install New Software’ and when I created a javafx project, I got the following error in Main.java:
The import javafx cannot be resolved.
So, I listed the following directory to search for “jfxrt.jar”:
ls -l /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext
But I didn’t find “jfxrt.jar”.
java -version
The output:
openjdk version “1.8.0_45-internal”
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
2
According to the packages list in Ubuntu Vivid there is a package named openjfx. This should be a candidate for what you’re looking for:
JavaFX/OpenJFX 8 – Rich client application platform for Java
You can install it via:
sudo apt-get install openjfx
It provides the following JAR files to the OpenJDK installation on Ubuntu systems:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jfxswt.jar
/usr/lib/jvm/java-8-openjdk-amd64/lib/ant-javafx.jar
/usr/lib/jvm/java-8-openjdk-amd64/lib/javafx-mx.jar
Hope this helps.
4
Here’s how to set it up on Ubuntu Linux with Maven:
1) Install OpenJFX package, check where did it put the files.
sudo apt install openjfx
dpkg-query -L openjfx
You might end up with version for JDK 11. In which case, either follow with installing a new OpenJDK, or set a version of OpenJFX for JDK 8.
2) Put it to your Maven project as a system
-scoped dependency.
Note this is the lazy and not-so-nice way. Properly, you should install the jars like this:
dpkg-query -L openjfx | grep -E '.jar$' | xargs -l -I{} mvn install:install-file -Dfile="{}" -DgroupId=javafx -DartifactId=$(echo $JAR | tr '.' '-') -Dversion=1.0 -Dpackaging=jar
And then use it as a normal
compile-scoped
dependency.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.source.level>1.8</project.source.level>
<project.target.level>1.8</project.target.level>
<javafx.dir>/usr/share/openjfx/lib</javafx.dir>
</properties>
<dependencies>
<!-- JavaFx :
sudo apt install openjfx
dpkg-query -L openjfx
-->
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx-base</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${javafx.dir}/javafx.base.jar</systemPath>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx-controls</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${javafx.dir}/javafx.controls.jar</systemPath>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${javafx.dir}/javafx.fxml.jar</systemPath>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${javafx.dir}/javafx.graphics.jar</systemPath>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx-media</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${javafx.dir}/javafx.media.jar</systemPath>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx-swing</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${javafx.dir}/javafx.swing.jar</systemPath>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx-web</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${javafx.dir}/javafx.web.jar</systemPath>
</dependency>
</dependencies>
For Java Compiler 8 or above, do the following:
- Right-click on project
- Choose Build Path —-> Add Libraries
You will then be presented with the following screenshot below:
Make sure you have downloaded and installed a JDK 8 or above
When you press the finish button, all Java FX errors in your code should disappear.
Note Prerequisites:
JDK 9 installed and tested on NetBeans 8.0.1
0
A) Make sure that you are using a compatible JDK, like 1.8, AND
B) configure a compatible version of Java in the Eclipse Project Facets.
- Right click on the Java project, select Properties
- Select Project Facets, find Java, set version 1.8
For Java 11, this error also appears, as JavaFX has been removed from Java 11 and comes as standalone
More info:
https://blogs.oracle.com/java-platform-group/the-future-of-javafx-and-other-java-client-roadmap-updates
1