Skip to content
Advertisement

OpenJdK 8 – Can’t compile package javafx.util does not exist

Linux Mint 20.3
   os.name = Linux
   os.arch = amd64
   os.version = 5.13.0-25-generic



 Java : 
    openjdk version "1.8.0_322"
    OpenJDK Runtime Environment (build 1.8.0_322-b06)
    OpenJDK 64-Bit Server VM (build 25.322-b06, mixed mode)

Maven 3.8.3

I build my java project by Maven.

When I try to compile my java project by OpenJdk 1.8.0_322:

  package com.myproject;
    
    import java.util.Collection;
    import java.util.List;
    import java.util.Map;
    
    
    import javafx.util.Pair; //  here error
    
    @SuppressWarnings("rawtypes")
    public interface SomeMyInterface {
      // some code here
      Map<Integer, List<Pair<Integer,Integer>>> findAllMgIdsAssociatedNsPairs();
    }

I get error:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /SomeMyInterface.java:[10,19] package javafx.util does not exist

P.S. If I use jdk1.8.0_202 from Oracle the project success compile!

P.P.S. The project must be compile by java 8. It’s client requirements.

Advertisement

Answer

tl;dr

Either:

  • Develop/deploy on a JDK that includes the OpenJFX libraries.
  • Add the OpenJFX libraries to your Java project.

Details

JavaFX has never been an official part of Java SE.

For a while Oracle included their JavaFX library along with their JDK. They later ceased bundling.

You need to add an implementation of JavaFX to your project. You’ll find such an implementation in OpenJFX. This open-source project is housed as a subproject on the OpenJDK project, co-led by Gluon and Oracle.

Use your dependency manager of choice, such as Apache Maven or Gradle, to add the OpenJFX library to your project. Below I put Maven repo links for OpenJFX 11 through 17, but those require Java 11+. I have not found any Maven repo links for JavaFX/OpenJFX for Java 8.

Alternatively, you can develop on, and deploy to, a JDK that bundles the OpenJFX libraries. At least two vendors offer an edition of their JDK product with such a bundle:

  • ZuluFX by Azul Systems
    • See this downloads list for Java 8 on macOS, Linux, & Windows. Notice the Java Package filter field at top of downloads list.
  • LibericaFX by BellSoft
    • On the Downloads page, choose the Full option for an edition bundling OpenJFX. Available for Java 8 on macOS, Linux, & Windows.

If at all possible, consider moving on from Java 8. I suggest moving to the later LTS versions of Java, 11 and 17, as well as the latest LTS version of OpenJFX, 17, which requires Java 11 or later. Both Java and JavaFX have evolved greatly in recent years. This evolution includes the jlink and jpackage tooling to package your JavaFX app as single “double-clickable” app that includes the minimal parts of a JDK/JVM needed to run on a specific platform.

Versions

For OpenJFX versions 11 through 17, Java 11 or later is required/recommended. See Release Notes.

Maven links for OpenJFX 11 through 18 can be found here, and on other Maven repositories.

Source code for OpenJFX versions 14 through 18 can be found on GitHub site for OpenJDK. Source code for older versions 2, 8, 9, and 10 can be found on the read-only Mercurial repository of OpenJDK.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement