Search code examples
mavenosgieclipse-rcpopenjfxjavafx-11

Using Openjfx 11 classes in an OSGi application



Does anyone know if there is a way to use JavaFX modules in eclipse workspace? I have an OSGi-maven multi-modular application.

Up until now, I have tried a couple of things.

  1. To download JavaFX SDK and to add jars in eclipse as a user-defined library.
  2. To bundle JavaFX jars and to use them as regular OSGi bundles after that (added as dependency and after that in target-platform).

Both of these things work. But, in the first case, every developer would have to manually add those jars as a library on the classpath. And in the second for every platform, we would have to have a different bundle for each module.

If I do neither of those things I have compile errors that JavaFX classes cannot be found (as expected).

Is there some third way to do this? By using some OSGi functionality or something like that? I haven't found any way to add a module in MANIFEST.MF. Is that even possible?

I have added JavaFX modules as VM arguments in the OSGi framework launcher, and everything works fine. But I have to do one of those things mentioned before so that I don't have compile errors. VM arguments: --module-path /path/to/javafx/sdk/11/lib --add-modules javafx.controls,javafx.graphics,javafx.base


Solution

  • I tried to convert an E4/OSGI/GEF/JavaFx project that uses JRE 8 to JRE 11 and OpenJFX 11, and found a way to do so.

    In my case, I use SWT and javafx.embed.swt.FxCanvas. Including the user defined JavaFX library in the modulepath didn't work, generating class not found errors during compile-time; but including the library in classpath worked.

    I also couldn't run the application using --module-path arguments; it gave NoClassDefFoundError exception for org.eclipse.swt.widgets.Canvas

    My solution uses E(fx)clipse, which could also be the third option for you. After including the javafx libraries in the classpath, and including org.eclipse.fx.osgi in the project configuration, I used the following VM parameters to load JavaFX classes using E(fx)clipse.

    -Dosgi.framework.extensions=org.eclipse.fx.osgi -Defxclipse.java-modules.dir=[openjfx-lib-directory]

    You can also add -Defxclipse.osgi.hook.debug=true" to see debug messages from E(fx)clipse while loading the classes.