4

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 ?

thibault
  • 379
  • 1
  • 3
  • 13
  • 1
    Though I have no knowledge on OSGi, I am curious to know why `javafx.stage;version="2.2.0"` ? – ItachiUchiha Feb 26 '15 at 09:19
  • Perhaps there is something in [e(fx)clipse](http://www.eclipse.org/efxclipse/index.html#about-tooling): "Unfortunately, JavaFX was not written with OSGi in mind so there are various sources of error when running inside OSGi. These problems include the location of the JavaFX binaries in your Java installation and class loading issues because of OSGi's visibility rules. e(fx)clipse provides helper libraries for dealing with all of those problems and makes writing JavaFX applications on top of Eclipse Equinox feel as easy as it is with SWT and Swing." I know nothing of OSGi; just quoting doc. – jewelsea Feb 26 '15 at 09:39
  • @jewelsea Ok, but since JDK8 JavaFX is load in the ExtClassloader so it should theoretically works :( – thibault Feb 26 '15 at 09:46
  • As you already found out the problem is that javafx.* are not part of an EE so felix needs help to know that they are there. You are in a slightly better position with Felix than e(fx)clipse who uses Equinox because Felix by default delegates class look ups to the extension classloader – tomsontom Feb 26 '15 at 10:26

3 Answers3

6

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.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27
  • But I don't have to do that for packages that start with _org.* (org.w3c.com, org.xml.sax)_. This comes only with javafx.* packages – thibault Feb 26 '15 at 13:40
  • 1
    _You_ don't have too because the framework impl has set `org.osgi.framework.system.packages` to the set of packages normally found in the JRE. JavaFX is not in the normal set of package found in the JRE (which is why you need to use the ext classloader.) See https://svn.apache.org/repos/asf/felix/trunk/framework/src/main/resources/default.properties. – BJ Hargrave Feb 26 '15 at 17:36
0

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).

Puce
  • 37,247
  • 13
  • 80
  • 152
0

Adding these two VM arguments fixed it for me:

-Dorg.osgi.framework.bundle.parent=ext  
-Dorg.osgi.framework.system.packages.extra=javafx.* 
Chin
  • 19,717
  • 37
  • 107
  • 164