The import javafx cannot be resolved

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:

  1. Right-click on project
  2. 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.

  1. Right click on the Java project, select Properties
  2. 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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật