Adding JavaFX dependency for OSGi/RCP application with Java 11 / JDK11

Ajay Lamba
2 min readSep 21, 2022

--

As you must have known by now that JavaFx is no longer part of JDK11. So how to migrate an OSGi application using JavaFx from JDK1.8 to JDK11? Keep reading to know the step by step process..

JavaFx is not part of JDK in Java 11 and is maintained separately as OpenJFX. You can download the SDK from https://gluonhq.com/products/javafx/ which is free to use.

There are multiple ways to add dependency of OpenJFX in your OSGi/RCP app. Couple of them are explained in this article and this article. These are very good articles and provide good explanation to add the dependencies in tycho build and eclipse. But with this approach there is a lot of manual work required each time someone in the team sets up the environment and also if you are not careful, the dependencies won’t be packaged in the final tycho build.

Is there a better way? Yes there is a better and cleaner way to add the OpenJFX dependencies in your RCP application. I assume you are using active target based dependencies in your application. If not, I would highly recommend to migrate your app to use the active target based dependency mechanism. This is an article explaining how to setup the active target.

As you would know there are public p2 repositories to add plugin dependencies in a RCP application and one of them is this. You can add the dependencies in the ‘active target’ from such repositories. But sometimes the required dependencies (e.g. OpenJFX) are not present in the public repositories. So you need to convert the jars available on maven repo or the downloaded jars to a plugin so that you can host it and use in the active target.

How to add OpenJFX dependency?

  1. Download the OpenJFX SDK from https://gluonhq.com/products/javafx/ and get the jars from the lib folder.
  2. Convert the jars to plugins manually using eclipse project. You can follow this article to create plugins from the jars.
  3. Make the plugins deployable on p2 repo. Follow this article for the same.
  4. Host the plugins on cloud (e.g. Amazon S3 location) which would act as p2 repo for us.
  5. Add the dependency in the active target and use in the application. You can follow this article to add the dependency in the active target.

--

--

Ajay Lamba

Decade of development experience. Passionate for best coding practices.