Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Import-Package necessary for org.xml.sax?
Import-Package necessary for org.xml.sax? [message #874786] Mon, 21 May 2012 14:39 Go to next message
Rolf Hauck is currently offline Rolf HauckFriend
Messages: 2
Registered: May 2012
Junior Member
I'm trying to run a system consisting of two bundles A and B. A exports a package foo.bar containing a class ConfigWrapper, which is implemented by using org.apache.commons.configuration. commons-configuration.jar is contained in the lib folder of A and is part of the Bundle classpath.
Classes of bundle B use foo.bar.ConfigWrapper, and the manifest of B contains "Import-Package: foo.bar".
My problem is, that ConfigWrapper cannot be instantiated because of a NoClassDefFoundError: org/xml/sax/EntityResolver.

I have a solution for this, but I cannot believe that this is necessary: If I add org.xml.sax and several related packages to the list of imported packages of A, the NoClassDefFoundError disappears.
Do I really have to scan all externally provided libraries for their dependencies on javax.*, org.xml.*, org.w3c.* et cetera and name those in the Import-Packages section of the manifest file? Or do I miss an important point?

Thanks for your help
Rolf
Re: Import-Package necessary for org.xml.sax? [message #874864 is a reply to message #874786] Mon, 21 May 2012 17:40 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 486
Registered: July 2009
Location: San Francisco ✈ Germany
Senior Member

Hi Rolf,

Am 21.05.2012 16:39, schrieb Rolf Hauck:
> Do I really have to scan all externally provided libraries for their
> dependencies on javax.*, org.xml.*, org.w3c.* et cetera and name those
> in the Import-Packages section of the manifest file? Or do I miss an
> important point?

Those imports are really necessary for OSGi bundles. However, some
(most?) frameworks can be configured to run in a relaxed mode which
automatically makes packages from the system classpath available to all
OSGi bundles even if they don't declare a dependency.

I recommend against putting common libraries within your bundle. Instead
you can re-use one of the available sources which already converted
non-OSGi libraries into OSGi bundles (eg. Orbit,
http://download.eclipse.org/tools/orbit).

Another option is to use a tool like Bnd to convert an existing library
into an OSGi bundle. Those tools are able to analyze the dependencies
and add them automatically.

Are there specific class-loading issues which require to have the
library loaded by the same class loader as the bundle?

-Gunnar

--
Gunnar Wagenknecht
gunnar@xxxxxxxx
http://wagenknecht.org/
Re: Import-Package necessary for org.xml.sax? [message #875104 is a reply to message #874864] Tue, 22 May 2012 06:43 Go to previous messageGo to next message
Rolf Hauck is currently offline Rolf HauckFriend
Messages: 2
Registered: May 2012
Junior Member
Hi, Gunnar,

use of the common library is an implementation detail that we don't want to expose to other bundles. Therefore we would rather avoid making it publicly available as a regular bundle.
We are surprised that it is necessary to name standard packages from the VM in the imports.
The application comes up normally if we start it from within the Eclipse IDE. The problem arises when we start it from the command line, using a config.ini. How would we configure the "relaxed mode" you mentioned?

Rolf
Re: Import-Package necessary for org.xml.sax? [message #875124 is a reply to message #875104] Tue, 22 May 2012 07:34 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 486
Registered: July 2009
Location: San Francisco ✈ Germany
Senior Member

Am 22.05.2012 08:43, schrieb Rolf Hauck:
> We are surprised that it is necessary to name standard packages from the VM in the imports.

I agree that org.xml.sax is very common, though. But only java.* are
standard VM packages.

Did you try the PDE Organize Manifest wizard to find missing imports?

> The application comes up normally if we start it from within the
> Eclipse IDE. The problem arises when we start it from the command line,
> using a config.ini. How would we configure the "relaxed mode" you mentioned?

Are you using the binary launcher? As far as I remember the relaxed mode
should be enabled by default when Equinox/Eclipse is started using the
binary executable or the launcher jar. However, when Equinox OSGi jar is
started directly (java -jar org.eclipse.osgi...) then the strict mode is
the default.

http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html

I think the relevant property should be
osgi.compatibility.bootdelegation. It's only set to true by default when
Equinox is started through the launcher (eg., launch inside Eclipse,
org.eclipse.equinox.launcher.jar, eclipse executable).

-Gunnar

--
Gunnar Wagenknecht
gunnar@xxxxxxxx
http://wagenknecht.org/
Re: Import-Package necessary for org.xml.sax? [message #875711 is a reply to message #874786] Wed, 23 May 2012 08:05 Go to previous messageGo to next message
Libor Jelinek is currently offline Libor JelinekFriend
Messages: 143
Registered: January 2012
Location: Prague, Czech Rep.
Senior Member

Hi Rolf,
by default only exposed JRE packages are java.* and javax.*.

This is maintained by execution environment profiles. Profiles shipped
with standard Equinox are files with .profile extension in root of
org.eclipse.osgi_*.jar (* means version) archive.

Check what your profile contains because my Indigo
org.eclipse.osgi_3.7.2.v20120110-1415.jar's JavaSE-1.7.profile file
contains (among others):

org.osgi.framework.system.packages = \
...
org.xml.sax,\
org.xml.sax.ext,\
org.xml.sax.helpers

So org.xml.sax.EntityResolver should be available to any bundle
out-of-the-box....

Anyway, declaring these "not-so-common" packages as imported is not
weird but absolutely normal and always working approach.

Also, you may have been interested to read
*
http://blog.springsource.org/2009/01/19/exposing-the-boot-classpath-in-osgi/
* or http://wiki.eclipse.org/Equinox_Boot_Delegation

Cheers
Libor

On 05/21/2012 04:39 PM, Rolf Hauck wrote:
> I'm trying to run a system consisting of two bundles A and B. A exports
> a package foo.bar containing a class ConfigWrapper, which is implemented
> by using org.apache.commons.configuration. commons-configuration.jar is
> contained in the lib folder of A and is part of the Bundle classpath.
> Classes of bundle B use foo.bar.ConfigWrapper, and the manifest of B
> contains "Import-Package: foo.bar".
> My problem is, that ConfigWrapper cannot be instantiated because of a
> NoClassDefFoundError: org/xml/sax/EntityResolver.
> I have a solution for this, but I cannot believe that this is necessary:
> If I add org.xml.sax and several related packages to the list of
> imported packages of A, the NoClassDefFoundError disappears.
> Do I really have to scan all externally provided libraries for their
> dependencies on javax.*, org.xml.*, org.w3c.* et cetera and name those
> in the Import-Packages section of the manifest file? Or do I miss an
> important point?
>
> Thanks for your help Rolf
>
Re: Import-Package necessary for org.xml.sax? [message #875933 is a reply to message #875711] Wed, 23 May 2012 15:17 Go to previous message
Libor Jelinek is currently offline Libor JelinekFriend
Messages: 143
Registered: January 2012
Location: Prague, Czech Rep.
Senior Member

You can also try to make use of org.osgi.framework.bootdelegation
property in config.ini to list org.xml

org.osgi.framework.bootdelegation=org.xml

Libor

On 05/23/2012 10:05 AM, Libor Jelinek wrote:
> Hi Rolf,
> by default only exposed JRE packages are java.* and javax.*.
>
> This is maintained by execution environment profiles. Profiles shipped
> with standard Equinox are files with .profile extension in root of
> org.eclipse.osgi_*.jar (* means version) archive.
>
> Check what your profile contains because my Indigo
> org.eclipse.osgi_3.7.2.v20120110-1415.jar's JavaSE-1.7.profile file
> contains (among others):
>
> org.osgi.framework.system.packages = \
> ...
> org.xml.sax,\
> org.xml.sax.ext,\
> org.xml.sax.helpers
>
> So org.xml.sax.EntityResolver should be available to any bundle
> out-of-the-box....
>
> Anyway, declaring these "not-so-common" packages as imported is not
> weird but absolutely normal and always working approach.
>
> Also, you may have been interested to read
> *
> http://blog.springsource.org/2009/01/19/exposing-the-boot-classpath-in-osgi/
>
> * or http://wiki.eclipse.org/Equinox_Boot_Delegation
>
> Cheers
> Libor
>
> On 05/21/2012 04:39 PM, Rolf Hauck wrote:
>> I'm trying to run a system consisting of two bundles A and B. A exports
>> a package foo.bar containing a class ConfigWrapper, which is implemented
>> by using org.apache.commons.configuration. commons-configuration.jar is
>> contained in the lib folder of A and is part of the Bundle classpath.
>> Classes of bundle B use foo.bar.ConfigWrapper, and the manifest of B
>> contains "Import-Package: foo.bar".
>> My problem is, that ConfigWrapper cannot be instantiated because of a
>> NoClassDefFoundError: org/xml/sax/EntityResolver.
>> I have a solution for this, but I cannot believe that this is necessary:
>> If I add org.xml.sax and several related packages to the list of
>> imported packages of A, the NoClassDefFoundError disappears.
>> Do I really have to scan all externally provided libraries for their
>> dependencies on javax.*, org.xml.*, org.w3c.* et cetera and name those
>> in the Import-Packages section of the manifest file? Or do I miss an
>> important point?
>>
>> Thanks for your help Rolf
>>
Previous Topic:Difference Between Bind & Activate??
Next Topic:What are configurators and how to auto-discover bundles and start them?
Goto Forum:
  


Current Time: Fri Apr 19 21:29:21 GMT 2024

Powered by FUDForum. Page generated in 0.03282 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top