You are aware that you can manipulate and load classes from any bundle
using the Bundle object?

Manipulating bundles allows you to load a specific class from a
specific bundle with Bundle.loadClass(String) (there are also methods
for finding and getting resources).

The problem is mainly when you have code that just uses its own or the
context classloader, assuming that there is a single classpath for the
whole system. In those cases, the buddy loader can work.

Kind regards,

     Peter Kriens


JT> Thanks for the replies.

JT> I knew about spring-osgi. I really wanted to know how to let an
JT> existing class retrieve resources from another bundle, I was just
JT> using spring as an example (Sorry, should of been more clear about
JT> that).  There are other frameworks, depending on how things are
JT> setup, that would need access to another bundle's classpath.  For
JT> instance Hibernate, Eclipse-BuddyPolicy for Equinox works for
JT> Hibernate though.  But that was for loading classes, not resources.

JT> Is there a cross OSGi platform way to handle this?

JT> Thanks again


JT>  On 10/18/06, Kaegi, Simon <[EMAIL PROTECTED]> wrote:
JT>  Also see...
JT> http://opensource.atlassian.com/projects/spring/browse/SPR-1802

JT> This is a hot item right now -- lots of activity.

 >> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] ] On Behalf Of Benjamin Schmaus
>> Sent: Wednesday, October 18, 2006 5:27 PM
>> To: General OPS4J
>> Subject: Re: OSGi Classloading
>>
>> I believe that Spring 2.0 provides pretty solid support for 
>> using Spring in an OSGi runtime.
>>
>> More at http://www.springframework.org/osgi/specification
>>
>> On 10/18/06, Cameron Fieber < [EMAIL PROTECTED]> wrote:
>> > What I've done using Spring + OSGi is:
>> >
>> > 1) create a library bundle for Spring that just exports all
>> the spring 
>> > classes
>> >
>> > 2) created some hooks following the patterns of the Spring Remoting
>> > classes: OSGIExporter and OSGIImporter that publish spring beans as
>> > OSGI services or import OSGI services for use by spring beans 
>> >
>> > 3) each bundle that wants to export beans creates an application
>> > context in its activator (Abstract class that does that)
>> and uses the
>> > OSGI Exporter to publish those beans 
>> >
>> > The activator is set via a manifest entry as to which services are
>> > required before it can launch the application context, so
>> it waits to
>> > launch the application context until all required services are 
>> > available, and restarts the application context if those services
>> > change.
>> >
>> > Basically it uses the OSGI service mechanism to integrate
>> spring beans
>> > in different bundles.  As far as classloading stuff goes, all it 
>> > required was that any thing you are exposing for other application
>> > contexts to import has to be properly configured in your
>> manifest as
>> > an exported package and imported by the consuming bundle. 
>> >
>> > It's not pretty but it works.  Unfortunately I can't
>> publish the code
>> > for it, but it wasn't too hard to build.
>> >
>> > -Cameron
>> >
>> > On 10/18/06, Joe Toth < [EMAIL PROTECTED]> wrote:
>> > > I'm relatively new to OSGi, but I'm learning. I have a question
>> > > regarding classloading.
>> > >
>> > > I'm trying to have a Spring based plug-in/bundle serve up 
>> beans to
>> > > other bundles.  In one bundle I add all the spring stuff
>> and spring
>> > > works fine in that one bundle (its called
>> > > org.omegaframework.system).  Now I'm trying to initialize Spring 
>> > > with an applicationContext.xml from another bundle (called
>> > > org.omegaframework.example).  I know the 2 bundles have different
>> > > classloaders so I have to do something in the Spring 
>> bundle to let it know about the classpath from the other bundle.
>> > >
>> > > I tried 2 methods:
>> > > 1. Using Equinox's BuddyLoader by putting...
>> > > Eclipse-RegisterBuddy:  org.omegaframework.system   in the
>> example bundle.
>> > > And Eclipse-BuddyPolicy: registered in the system bundle.
>> > > This didn't work, plus I'm looking for a platform
>> independent way to 
>> > > do it anyway, if possible.
>> > >
>> > > 2. Passing the classloader...This method is in the system
>> bundle and
>> > > is called from the example bundle.  I tried passing 
>> > > ExampleActivator.class.getClassloader() and
>> > > this.getClassLoader()
>> > >
>> > >     public void init(String applicationContextXMLFile, ClassLoader
>> > > classLoader) { 
>> > >
>> > >         Thread current = Thread.currentThread();
>> > >         ClassLoader original = current.getContextClassLoader();
>> > >         current.setContextClassLoader (classLoader);
>> > >         try {
>> > >             context = new ClassPathXmlApplicationContext(
>> > >                     new String[] { applicationContextXMLFile },
>> > >  this.getClass());
>> > >         } catch (Exception e) {
>> > >             e.printStackTrace();
>> > >         } finally {
>> > >             current.setContextClassLoader(original); 
>> > >         }
>> > >
>> > >     }
>> > >
>> > >
>> > > I can't get either to work.  I've only tested on Equinox 3.3
>> > >
>> > > Is there a "standard" way to allow a bundle access to another 
>> > > bundles classpath?
>> > >
>> > > Thanks
>> > >
>> > > _______________________________________________
>> > > general mailing list
>> > > [email protected]
>> > > http://lists.ops4j.org/mailman/listinfo/general
>> > >
>> > > 
>> > >
>> >
>> > _______________________________________________
>> > general mailing list
>> > [email protected]
>> > http://lists.ops4j.org/mailman/listinfo/general
>> >
>>
>> _______________________________________________
>> general mailing list
>> [email protected]
>> http://lists.ops4j.org/mailman/listinfo/general
>>
>>

JT>      This message may contain privileged and/or confidential
JT> information.  If you have received this e-mail in error or are not
JT> the intended recipient, you may not use, copy, disseminate or
JT> distribute it; do not open any attachments, delete it immediately
JT> from your system and notify the sender promptly by e-mail that you have 
done so.  Thank you.

JT> _______________________________________________
JT> general mailing list
JT> [email protected]
JT> http://lists.ops4j.org/mailman/listinfo/general 


JT>   

-- 
Peter Kriens                              Tel +33467542167
9C, Avenue St. Drézéry                    AOL,Yahoo: pkriens
34160 Beaulieu, France                    ICQ 255570717
Skype pkriens                             Fax +1 8153772599


_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to