Unresolved JavaFX packages in OSGi Felix Application

apache-felix, eclipse, javafx, maven, osgi

Solution

The OSGi spec requires that bundles must import all packages that don't start with "java.". So you do need to import packages that start with "javax.". So now you need an exporter and a source for the packages. `-Dorg.osgi.framework.bundle.parent=ext` gives you a source for the packages since the ext classloader loader is includes in the bundle parent. But the framework resolver still needs to have an exporter for the package to know that the bundle's imports are properly resolved. This is why you need `-Dorg.osgi.framework.system.packages.extra=javafx.stage`.

Problem

I develop a rich application based on JavaFX and the OSGi Felix container. When my JavaFX is started, an org.osgi.framework.BundleException is thrown indicating that the framwork could not wire my JavaFX packages : ``` ERROR: Bundle app-impl-bundle [3] Error starting eclipse-project:T:\workspace\fast-osgi\app-impl-bundle\ (org.osgi.framework.BundleException: Unresolved constraint in bundle app-impl-bundle [3]: Unable to resolve 3.0: missing requirement [3.0] osgi.wiring.package; (&(osgi.wiring.package=javafx.stage)(version>=2.2.0))) ``` Here my MANIFEST.MF file : ``` Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: app-impl-bundle Bundle-SymbolicName: app-impl-bundle Bundle-Version: 1.0.0.qualifier Require-Bundle: app-bundle;bundle-version="0.0.1" Bundle-Activator: com.mycompany.app.impl.Activator Import-Package: javafx.stage;version="2.2.0", javax.xml.parsers, org.osgi.framework;version="1.8.0", org.w3c.dom, org.xml.sax Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ClassPath: ., target/lib/log4j-1.2.17.jar ``` And here the VM Arguments used to start the OSGi Framework (I run my project under Eclipse Luna, using this plugin) : ``` -Dosgi.requiredJavaVersion=1.8 -Dorg.osgi.framework.bundle.parent=ext ``` The last argument has no effect. In spite of this this article which tell that it works on Equinox... I found a solution adding this option to the VM arguments : ``` -Dorg.osgi.framework.system.packages.extra=javafx.stage ``` But this is not very flexible. Do you think Felix OSGi implementation is the problem ? Should it works only with Equinox ? Anyone can help me ? Is it the right way to do it ?

Original source