Unresolved JavaFX packages in OSGi Felix Applicati

2019-04-11 09:53发布

问题:

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 ?

回答1:

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.



回答2:

I've released some Early Access versions of Drombler FX, a new Rich Client Platform for JavaFX based on OSGi (Apache Felix) and Maven.

As an application framework it makes sure JavaFX and OSGi will get started properly and it provides the main window.

You can read more about Drombler FX here: http://puces-blog.blogspot.ch/search/label/Drombler

There's a Getting Started page which explains how to create, build and run a Drombler FX sample application with a few simple steps.

Please note that there is currently a critical bug in the Docking Framework because of a bug in JavaFX. That bug should be fixed in the Java SE/ JavaFX 8u40 release however (expected release date: March 2015).