Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » JDK/JRE packages not exported by OSGi system bundle
JDK/JRE packages not exported by OSGi system bundle [message #734253] Fri, 07 October 2011 05:11 Go to next message
Piotr   is currently offline Piotr
Messages: 6
Registered: July 2009
Junior Member
Hello,
I guess the topic might appear from time to time, although I've spent two days searching for answer on Google and found some articles, which explain the problem, but I can't find working solution. Maybe you guys will be able to give me good answer.

Recently I introduced org.apache.servicemix.bundles.dom4j-1.6.1_4.jar bundle in order to have access to dom4j implementation. This bundle contains package org.dom4j.io, which defines usage of javax.xml.stream, javax.xml.stream.event and javax.xml.stream.util - unfortunately it imports those packages using version range - which is [1.0, 2).

As we know JRE 1.6 contains those packages, and according to "JavaSE-1.6.profile" file in org.eclipse.osgi bundle, this package should be exported by system bundle. Even though I defined everywhere "Bundle-RequiredExecutionEnvironment: JavaSE-1.6" in my MANIFEST.MF files, when on the launcher page I do "validate dependencies" I still get information, that dom4j bundle can't be resolved because javax.xml.stream* packages can't be found. I guess this is because system bundle exports them as version 0.0.0.

What can be my solution to this problem? Temporarily I edited manifest of dom4j bundle and I removed version constrains, so that every version is accepted. Unfortunately this is not desirable fix, because this isn't our bundle, and we would prefer to use it out of the box, without the need to change it's manifest.

There's additional problem like this. One of our other bundles (also provided by 3rd party) is woodstox-core-asl-4.1.1.jar, which in turn declares Import-package: javax.xml.stream;version="0.0.0" - this also isn't resolved against the JRE's package exported by system bundle - the difference is that it doesn't resolve in the launcher validation, but if I ignore the message, it will be wired to correct package in the running OSGi application.

Please note that the application we build is based on Eclipse RCP 3.6.2 - this is a desktop application. My IDE is Eclipse 3.7.1, we use JDK 1.6_20.

Can you please provide any ideas how to resolve my issues? Thank you in advance.
Re: JDK/JRE packages not exported by OSGi system bundle [message #734311 is a reply to message #734253] Fri, 07 October 2011 08:35 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas Watson
Messages: 418
Registered: July 2009
Senior Member
Hi,

This is related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=348630

We need to go through each package and figure out what the correct version should be as exported by each VM version. Unfortunately there is no real good document that tells us what the versions should be. Any help there would be great.

At runtime you can specify additional versions of the packages you need exported by specifying the org.osgi.framework.system.packages.extra property. Something like this in the config.ini

org.osgi.framework.system.packages.extra= \
javax.xml.stream; version=1.0, \
javax.xml.stream.event; version=1.0, \
javax.xml.stream.util; version=1.0

This will configure the system bundle to export these packages at the 1.0 version.

HTH

Tom
Re: JDK/JRE packages not exported by OSGi system bundle [message #734313 is a reply to message #734311] Fri, 07 October 2011 08:43 Go to previous messageGo to next message
Piotr   is currently offline Piotr
Messages: 6
Registered: July 2009
Junior Member
Hi,
thank you for your answer. I tried the "org.osgi.framework.system.packages.extra" VM argument yesterday. It is not perfect solution but it works. Still, the launcher validator won't pick it, so you'll always have dependency validation errors in the dialog.
When you start the application using e.g. "org.osgi.framework.system.packages.extra=javax.xml.stream; version=1.0.0" option the problem in the running application disappears, but if you type in OSGi console "packages javax.xml.stream" you'll see, that there are now two providers of this package:
1) javax.xml.stream (0.0.0) <org.eclipse.osgi>
2) javax.xml.stream (1.0.0) <org.eclipse.osgi>

Normally that would be a problem - having two "providers" of the package, I guess, but since the provider is the same bundle (the system bundle) I hope that the classloader is also the same, that's why it works.

From the bug you pointed me to, I see that for the time being there's no hope to resolve the problem with the launcher dialog...

[Updated on: Fri, 07 October 2011 08:43]

Report message to a moderator

Re: JDK/JRE packages not exported by OSGi system bundle [message #734346 is a reply to message #734313] Fri, 07 October 2011 10:05 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas Watson
Messages: 418
Registered: July 2009
Senior Member
Yes, they are the same class loader. From the framework's perspective the package source is identical, it simply has different meta-data associated with it.

Another, perhaps nicer way to get this to work is to create a system bundle fragment with a Bundle-RequiredExecutionEnvironment header that requires JavaSE-1.6 and exports the packages at the version you expect from JavaSE-1.6. This system bundle fragment jar would be empty except having a manifest that looks something like this:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: the.jre.packages
Bundle-Version: 1.6
Fragment-Host: system.bundle
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: javax.xml.stream; version=1.0,
javax.xml.stream.event; version=1.0,
javax.xml.stream.util; version=1.0

If you include such a fragment in your target then I think PDE should find it and allow your bundles to resolve. At runtime this fragment will attach to the system bundle and cause it to export the additional packages just like if you set the extra configuration property.

HTH

Tom.
Re: JDK/JRE packages not exported by OSGi system bundle [message #734358 is a reply to message #734346] Fri, 07 October 2011 10:30 Go to previous messageGo to next message
Piotr   is currently offline Piotr
Messages: 6
Registered: July 2009
Junior Member
Thank you again.
I also tried the fragment approach yesterday, but since the fragment doesn't provide any implementation PDE doesn't allow me to export any packages from it. It puts error on the exported packages.
Re: JDK/JRE packages not exported by OSGi system bundle [message #941387 is a reply to message #734358] Fri, 12 October 2012 09:26 Go to previous message
Martin Skorsky is currently offline Martin Skorsky
Messages: 112
Registered: July 2009
Senior Member
An alternative approach to add version numbers to the Java packages exported by the system bundle:
use the property osgi.java.profile.
Example:
eclipse.exe -vmargs -Dosgi.java.profile=<URL of file with profile>

A template for the profile can be found in the org.eclipse.osgi bundle. Extract the profile suitable for your JVM and add the versions you need to a copy of the profile (use the URL to this file above).
Example for Java 7:
javax.xml.bind;version="2.2.3",
(originally: javax.xml.bind,)
Previous Topic:Provisioning exception
Next Topic:OSGI-Console for org.eclipse.osgi 3.8.1
Goto Forum:
  


Current Time: Fri Apr 18 14:11:36 EDT 2014

Powered by FUDForum. Page generated in 0.01682 seconds