I am using Pair data structure in my code with java 8, it runs fine in local. But in jenkins build, I get this issue:
error: package javafx.util does not exist
import javafx.util.Pair;
I am using Pair data structure in my code with java 8, it runs fine in local. But in jenkins build, I get this issue:
error: package javafx.util does not exist
import javafx.util.Pair;
Your code uses the Pair
class that comes with JavaFX. Unlike Swing, JavaFX has never been a standard part of Java SE. You must make an implementation of JavaFX available to your app.
It would seem that your local machine has an implementation of JavaFX, but your Jenkins machine does not. You need to get an implementation of JavaFX onto that Jenkins machine.
The OpenJFX subproject on the OpenJDK project is an open-source implementation of JavaFX. The Gluon company leads OpenJFX, in cooperation with Oracle.
One solution is for you to bundle OpenJFX as part of your app. The common way to do this is to configure a dependency management tool such as Apache Maven or Gradle.
An alternative solution is to use a JDK that comes bundled with an implementation of JavaFX.
Vendors of JDK products are free to bundle an implementation of JavaFX.
Oracle chose to do so with early releases of their commercial Java 8 product. The company ceased bundling in later releases of Java 8. I guess that your local machine has an earlier release of Java 8 while your Jenkins machine has a later release of Java 8, with and without JavaFX bundled respectively.
At least two JDK vendors currently bundle OpenJFX with some editions of their JDK products:
Of course, going this route means you must also get OpenJFX onto your app’s deployment machines.
As commented, if you are not really making a JavaFX app, then bundling OpenJFX just for that Pair
class is overkill.
Some folks use the map entry interface and implementations as a pairing class. See the Map.Entry
interface with links to the mutable and immutable concrete classes.
I suggest you roll your own.
The easiest DIY implementation in Java 16+ is as a record.
record PairOfInts ( int x , int y ) {}
Tip: You can declare a record
locally within a method, in addition to nested in a class or standing alone as its own class.