felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neil Bartlett <njbartl...@gmail.com>
Subject Re: NoClassDefFoundError of classes that are in the JRE
Date Thu, 11 Aug 2016 13:31:20 GMT
I want to try to give you a more solid basis for these discoveries.

A bundle MUST import all of the packages that it both (a) uses (that is, refers to from contained
types) and (b) does not contain. There is a single exception to this rule: all package names
beginning with “java.” are loaded by delegation to the Boot ClassLoader and cannot be
imported.

See OSGi R6 Core Specification, section 3.9.3: "The Framework must always delegate any package
that starts with java. to the parent class loader”. The reason for this exception is a security
rule in the JVM… see the JavaDocs for ClassLoader.defineClass(): “SecurityException …
 if <tt>name</tt> begins with "<tt>java.</tt>”. Only the Boot Class
Loader is permitted to define classes in the “java.*” namespace. Everything else such
as “javax.*” can and must be imported.

The OSGi Framework normally exports the standard set of Java SE packages from the System Bundle,
so if you want javax.xml.parsers then you just import javax.xml.parsers and it gets wired
to the export from the system bundle. I note that javax.xml.parsers is a standard Java SE
package (since Java 1.4) and therefore should be exported already. Unfortunately the JCP specifications
don’t provide versions for Java SE packages therefore the Framework exports them all as
version 0.0.0.

However, the System, Bundle exports can be overridden with configuration. This is normally
done if you want to use a non-standard JRE package like “sun.misc” – you can make the
System Bundle export this package by specifying “org.osgi.framework.system.packages.extra=sun.misc”.
It’s also possible for somebody to override the default behaviour and remove some of the
Java SE packages. I have no idea whether WebLogic does this or not.

Finally, just because some other bundle imports a package doesn’t mean that your bundle
gets that import too. I refer you back to the rule above: a bundle MUST import all the packages
it uses except for those named java.*.

I hope this helps,

Neil



> On 11 Aug 2016, at 14:05, Remo Liechti <remo.liechti@swisslog.com> wrote:
> 
> Found it. You need to pass that imports along all bundles in between.
> 
> Let's say, you have bundle A, B and C. And Bundle C uses some javax.xml.* stuff, while
the bundles hierarchy sis like:
> A=Com.foo
> B=com.foo.bar
> C=com.foo.bar.util
> 
> Now you first need to add the javax.xml.parsers to the the extra property as you said,
then you need to add it to all of those 3 bundles as import property.
> Afterwards, its loading.
> 
> Thanks mate!
> 
> 
> -----Original Message-----
> From: Robert Onslow [mailto:robert.onslow@gmail.com]
> Sent: Donnerstag, 11. August 2016 14:32
> To: users@felix.apache.org
> Subject: Re: NoClassDefFoundError of classes that are in the JRE
> 
> Nothing that occurs to me, unfortunately Remo Robert
> 
> On Thu, Aug 11, 2016 at 11:36 AM, Remo Liechti <remo.liechti@swisslog.com> wrote:
>> Robert
>> 
>> Thanks for pointing this out. I found the config location and in Weblogic you can
actually set this property, but it seems to have no effect. I'll open a tracker with Oracle
on this.
>> Anything else I can try?
>> 
>> Thanks
>> 
>> 
>> -----Original Message-----
>> From: Robert Onslow [mailto:robert.onslow@gmail.com]
>> Sent: Donnerstag, 11. August 2016 11:09
>> To: users@felix.apache.org
>> Subject: Re: NoClassDefFoundError of classes that are in the JRE
>> 
>> Remo
>> 
>> The other thing you may need to do is find the configuration file for
>> the felix installation, something like config.properties, and set
>> 
>> org.osgi.framework.system.packages.extra=javax.xml.parser, ....
>> 
>> There's no need for a version number
>> 
>> Robert
>> 
>> On Thu, Aug 11, 2016 at 9:34 AM, Remo Liechti <remo.liechti@swisslog.com> wrote:
>>> Hi Robert
>>> 
>>> Good to hear that. Anything else to put in, like version number or the like?
When I put it in like this, it didn't work:
>>> 
>>> Import-Package: javax.xml.parsers,
>>> ...,
>>> ...,
>>> 
>>> Thanks
>>> 
>>> 
>>> -----Original Message-----
>>> From: Robert Onslow [mailto:robert.onslow@gmail.com]
>>> Sent: Donnerstag, 11. August 2016 10:15
>>> To: users@felix.apache.org
>>> Subject: Re: NoClassDefFoundError of classes that are in the JRE
>>> 
>>> Remo
>>> 
>>> When I moved from eclipse to felix I found that everything apart from
>>> java.* has to be imported as in
>>> 
>>> Import-Package: javax.xml.parsers
>>> 
>>> Robert
>>> 
>>> On Thu, Aug 11, 2016 at 9:02 AM, Remo Liechti <remo.liechti@swisslog.com>
wrote:
>>>> Hi guys
>>>> 
>>>> Another issue I came across while bundling the osgi application into a webapplication
for WebLogic.
>>>> It seems like some of the bundles I like to start fail during activation,
because they cannot find the class description of classes that actually are in the regular
JRE:
>>>> 
>>>> <Aug 11, 2016 9:47:19 AM CEST> <Error> <OSGiForApps> <BEA-000000>
>>>> <com.kuka.configuration.manager:15:[com.kuka.configuration.manager]
>>>> The activate method has thrown an exception
>>>> org.apache.felix.log.LogException: java.lang.NoClassDefFoundError: javax/xml/parsers/DocumentBuilderFactory
>>>>       at com.kuka.configuration.project.ConfigurationProjectSerializer.<clinit>(ConfigurationProjectSerializer.java:39)
>>>>       at
>>>> com.kuka.configuration.project.ConfigurationProject.loadInternal(Con
>>>> f
>>>> i
>>>> gurationProject.java:281)
>>>> 
>>>> When searching for that class in eclipse, I find it within the JRE of Weblogic.
Does Felix use another JRE, or does Felix inherit all classes into each classloader of each
bundle only if the package is something within java.*, and stuff like javax.* and so on are
not inherited within the classloaders? I ask this because stuff like java.io.File and so on
are found.
>>>> 
>>>> I tried to add the xerces into my application, however, it cannot be found
still.
>>>> The application I'm migrating was using equinox before, does it maybe import
the javax by default while felix isn't? Is there a way to add a dependency in the manifest
file to xerces? I failed with this approach:
>>>> 
>>>> Import-Package: xerces;version="2.11.0", [...]
>>>> 
>>>> Thanks,
>>>> Remo
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> This message may contain legally privileged or confidential information and
is therefore addressed to the named persons only. The recipient should inform the sender and
delete this message, if he/she is not named as addressee. The sender disclaims any and all
liability for the integrity and punctuality of this message. The sender has activated an automatic
virus scanning, but does not guarantee the virus free transmission of this message.
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>> 
>>> This message may contain legally privileged or confidential information and is
therefore addressed to the named persons only. The recipient should inform the sender and
delete this message, if he/she is not named as addressee. The sender disclaims any and all
liability for the integrity and punctuality of this message. The sender has activated an automatic
virus scanning, but does not guarantee the virus free transmission of this message.
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>> 
>> This message may contain legally privileged or confidential information and is therefore
addressed to the named persons only. The recipient should inform the sender and delete this
message, if he/she is not named as addressee. The sender disclaims any and all liability for
the integrity and punctuality of this message. The sender has activated an automatic virus
scanning, but does not guarantee the virus free transmission of this message.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
> This message may contain legally privileged or confidential information and is therefore
addressed to the named persons only. The recipient should inform the sender and delete this
message, if he/she is not named as addressee. The sender disclaims any and all liability for
the integrity and punctuality of this message. The sender has activated an automatic virus
scanning, but does not guarantee the virus free transmission of this message.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Mime
View raw message