• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OSGI class loading

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a non OSGI library file which has an API(method) which takes className as input & it tries to load the class using Class.forName.
This works fine in java. But i have created a bundle from the jar using maven plugin. i.e, I have added OSGI nature to it.

I have say 3 projects
1. My OSGI bundle - "BundleA".
2. NON osgi Library project "LibB". - converted to OSGI using BND tool or Maven
2. NON osgi Library project "LibC". - converted to OSGI using BND tool or Maven

LibsC - is the one explained above having the code class.forName. - 3rd party library
LibB - like intermediate library
BundleA - Exports a package say com.company.test

BudleA calls a service from LibB which inturn calls the method having loadClass(className) which takes class name from BundleA which is exported from bundle.
I have added <DynamicImport-Package>*</DynamicImport-Package> in manifest of LibC

I am getting classNotFoundException.
Please help
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Irrespective of whether or not it turns out to be possible, it's probably not a good idea to do your own dynamic class loading within a dynamic class loading environment like OSGi.

The thing is that OSGi has a highly restrictive idea of what a classpath is; for a given bundle it's essentially the classes within that bundle, and everything that gets imported - nothing else. So the class you're trying to load would need to be part of the bundle or part of one of its imports.

But there are likely better solutions to whatever the underlying problem is that you're trying to solve.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic