-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support OSGi classloading in Guice #94
Comments
From kevinb9n on April 20, 2007 07:48:25 (No comment was entered for this change.) Owner: crazyboblee |
From mcculls on April 25, 2007 09:44:18 Hi, I've taken this a bit further and extended the patch to also update the build process. It now adds OSGi metadata to the Guice jar using the Bnd bundle tool from http://www.aqute.biz/Code/Bnd . With this patch and the bnd-0.0.130.jar (which needs to be copied to lib/build) the Guice Jar can be dropped Attachment: gist |
From mcculls on May 15, 2007 22:45:17 Refactored patch wrt. latest trunk changes, and updated BND library to 0.0.134 Attachment: gist |
From dev2null on May 16, 2007 09:14:45 You might want to use bnd 0.0.135 or later if running on Windows or else the ant |
From mcculls on June 23, 2007 01:21:49 FYI, see http://wiki.ops4j.org/confluence/display/ops4j/Guice-OSGi for further work |
From dev2null on July 04, 2007 01:02:16 I'd like to include Guice in an Eclipse RCP application where OSGi support is needed. |
From mario.scalas on July 20, 2007 05:21:16 I'm interested too in using Guice along OSGi bundles. |
From alex.horn on July 20, 2007 06:17:10 I agree. OSGi is practically speaking an Inversion of Control framework. There are Guice, however, does a fine job of leveraging annotation (as opposed to XML) to meet |
From bslesinsky on July 21, 2007 11:26:34 It's not my decision and I know very little about OSGi, but I'm guessing that we It looks like the intent of the patch to Guice is to allow it to be configured to |
From alex.horn on July 21, 2007 12:49:17 Looking at the path, I think your observations are accurate. An extension would serve |
From bslesinsky on July 21, 2007 15:22:57 The main thing is to clarify the contract for the hook, so that we can write unit |
From mcculls on July 22, 2007 06:37:57 FYI, the latest form of the patch (currently done as a m2 project - see above link) I'd like to keep OSGi service injection as separate annotations, as this provides a I'll have a go at refactoring it this week - using a factory approach to provide |
From alex.horn on July 22, 2007 15:29:35 As you put time and effort into this patch, I am interested as far as how you |
From bslesinsky on July 22, 2007 22:49:06 I did some reading about OSGi and much of the above makes more sense to me now. It seems like Guice itself should be considered a library rather than as a service. There's also an impedance mismatch between Guice injection and OSGi services, in that |
From dev2null on July 23, 2007 00:51:18 Are there other class loader strategies that you think may be needed or would the |
From mcculls on July 23, 2007 01:35:23 I think making it a generic classloader hook (using a factory pattern) is best, as while the GuiceClassLoader from Providing a hook would also allow other containers to use their custom classloaders with Guice. |
From mcculls on July 23, 2007 01:58:02 alex.horn: the Guice-OSGi lab work is complementary to declarative services, in that both inject service dependencies, what's more interesting is the new OSGi component model RFP (inspired by Spring-OSGi) which is still being btw, I was running an OSGi tutorial a few months ago and demo'd some of the Guice-OSGi work, and people |
From mcculls on July 23, 2007 02:08:54 bslesinsky: OSGi already supports multiple versions of a library running in the same process, and dynamic updating of Interesting thought about scopes: bundles have a well-defined lifecycle, so a bundle scope may be possible... BTW, wrt. impedance mismatch, you see the same issue with Spring-OSGi where proxies help bridge the gap |
From bslesinsky on July 23, 2007 09:58:16 Well, I still have basic questions about OSGi: One is whether it's good practice in OSGi to make every Java library its own bundle. It seems like both approaches have been taken for Jetty; I found a page for the Also, I haven't figured out yet how you keep a reference to an OSGi service in a way |
From mcculls on July 24, 2007 02:19:33 > whether it's good practice in OSGi to make every Java library its own bundle. no set practice: having a bundle for every library is good in that you can however, making every library a bundle can sometimes be overkill in that you luckily these days there are lots of tools that help you create and manage (one of the more popular is the BND tool, see http://aqute.biz/Code/Bnd ) at the minimum, all that is required to turn a library into an OSGi bundle > Do Guice's dependencies need to be bundles as well? Or on the other hand, suppose at the moment the Guice-OSGi bundle includes the Guice library, plus dependencies > It seems like both approaches have been taken for Jetty; I found a page for the yes, the old oscar implementation of the HttpService embedded a version of Jetty > On the other hand, Jetty seems to be its own bundle now. also true, but only for recent versions (they've added OSGi metadata to the jar) > Also, I haven't figured out yet how you keep a reference to an OSGi service in the low-level way to access services is via a ServiceReference (indirect handle) a ServiceTracker can tell you when services come and go (via subclassing or giving Guice-OSGi uses ServiceTrackers to provide service instances via an injected proxy. DS will do the tracking for you and call methods when services come and go, passing for a good tutorial on OSGi, take a look at Neil Bartlett's series of articles: http://neilbartlett.name/blog/osgi-articles HTH |
From colin.mailinglist on July 24, 2007 10:00:35 This looks interesting, I'm going to give it a spin and see how it works. One comment about the comparison between DS and Guice-OSGi - one of the principal Cheers, |
From bslesinsky on July 25, 2007 11:25:38 > at the moment the Guice-OSGi bundle includes the Guice library, plus dependencies Okay, I think we should stick to this, so there is no reason for Guice > the low-level way to access services is via a ServiceReference (indirect handle) I see that OSGi uses reference-counting using getService() and A Guice Provider has get() but no unget(). It's recommended that an How do services usually handle this? |
From dev2null on July 25, 2007 13:13:30 A class loader hook mechanism may still be useful. It would be great it I could Currently plain Guice cannot work in an OSGi container and Guice-OSGi introduces a The other reason for adding hooks to the standard Guice distribution is of course Finally, packaging Guice with a bundle manifest would allow hiding non-api classes as |
From mcculls on July 26, 2007 03:39:47 here's a prototype patch against guice trunk that adds a generic classloader hook two basic implementations are provided - DefaultClassLoaderFactory which provides it also adds basic OSGi metadata to the manifest (non-generated) but this isn't if you'd like to use this with OSGi, apply the patch to trunk and rebuild the jar. -Dcom.google.inject.ClassLoaderFactory= if anyone spots any typos / bugs / possible improvements just give me a shout :) Attachment: gist |
From bslesinsky on July 26, 2007 10:05:38 It seems like there is still a fair amount of OSGi magic going on. Can you explain Why use a system property? How about: Guice.createInjector(classLoaderFactory, modules); Then each injector can be configured to do class loading its own way, and this should |
From mcculls on July 27, 2007 09:47:00 Actually the only OSGi magic in the last patch was the manifest entries. The system property and META-INF/services lookup code is a common Java Anyway, I agree about making it easier to test, so have refactored it to The attached patch only adds the hook and a default implementation - it Let me know if I'm on the wrong track :) PS. http://www.eclipsezone.com/articles/eclipse-vms has a good discussion Attachment: gist |
From geoff.hill.au on September 04, 2007 04:31:45 What do I apply this latest patch to? I don't have any GuiceCodeGen.java in my guice sources - fresh from svn BTW - this looks cool. |
From mcculls on September 05, 2007 21:28:45 Hi Geoff, GuiceCodeGen.java was based on GuiceFastClass.java (refactored and extended) - I'm attaching an updated patch which is based on today's trunk, applies cleanly and Attachment: gist |
From mario.scalas on September 10, 2007 02:20:50 How does the patch relate with http://wiki.ops4j.org/confluence/display/ops4j/Guice-OSGi ? The latter supports OSGi |
From mcculls on September 10, 2007 02:34:33 this patch is an evolution of the work I started with "Guice-OSGi" and incorporates I haven't updated Guice-OSGi to use this patch, but it shouldn't take too long - just |
From mcculls on October 02, 2007 09:14:16 FYI, I'm now maintaining the classloader hook patch at: https://peaberry.googlecode.com/svn/trunk/patches/ClassLoaderHook.txt and regularly update it so it applies cleanly to trunk. |
From mcculls on November 28, 2007 23:34:13 Note: patch has been refactored to: http://peaberry.googlecode.com/svn/trunk/patch/ClassLoaderHook.txt |
From mcculls on March 31, 2008 00:49:39 some design doc: https://code.google.com/p/peaberry/wiki/Patch_ClassLoaderHook |
From limpbizkit on June 04, 2008 22:55:47 (No comment was entered for this change.) Labels: Milestone-Release2.0 |
From limpbizkit on June 25, 2008 08:44:06 I'm working on applying mcculls' latest patch. It should fix the OSGi issue and the memory leak issue. http://peaberry.googlecode.com/svn/trunk/patch/ClassLoaderHook.txt Owner: limpbizkit |
From limpbizkit on June 29, 2008 16:06:16 Stuart's done a great job on this and what we've got is fantastic. Guice now will play-nice in an OSGi container Stuart's patch is applied but I've temporarily turned it off. To activate it, use -Dguice.custom.loader=true. I'm Status: Started |
From limpbizkit on July 03, 2008 14:27:18 Fixed. Stuart's latest changes address the package-private problem. Status: Fixed |
From annemartens1 on February 16, 2009 07:33:27 Dear OSGi-Guice team, I'm confused what the current requirements to use Guice with OSGi are. On the I want to use a third-party framework that uses Guice in my application. The I still experience class loading problems Thanks a lot in advance for you help! Kind regards, |
From mcculls on February 22, 2009 07:39:17 Hi Anne, I've just written up a wiki page about Guice and OSGi: https://code.google.com/p/google-guice/wiki/OSGi Guice trunk produces an OSGi bundle: you can drop it directly into an OSGi container If you're still having trouble feel free to post a message on the Guice-OSGi group |
From a.shewring on May 22, 2009 05:26:45 I'm having the same issue as Anne is, namely java.lang.NoClassDefFoundError: com/google/inject/internal/cglib/reflect/FastClass I am using the Guice 2.0 release jar. Modifying the manifest by adding Incidentally I also needed to add com.google.inject.internal;version="1.2" to the guice-2.0.jar's manifest in order for the org.google.assistedinject bundle to Lastly, the shipped aopalliance.jar is not an OSGi bundle. For Guice 1.0 I used the Please reopen this issue as there are clearly outstanding problems when running Guice Binary attachments: com.springsource.org.aopalliance-1.0.0.jar |
From mcculls on May 22, 2009 06:05:24 Be aware there are a couple of OSGi patches that are not in Guice 2.0: https://code.google.com/p/google-guice/issues/detail?id=311 https://code.google.com/p/google-guice/issues/detail?id=337 https://code.google.com/p/google-guice/issues/detail?id=343 These are all scheduled for release 2.1 Only issue 343 relates to the core Guice jar (the others are related to extensions, In particular, if you try to proxy a package-private type then it is impossible for If you want a copy of Guice 2.0 with the patch for issue 343 applied then you can get To use extensions like AssistedInject in OSGi you will either have to wait for the As for the AOP Alliance jar, the version distributed with Guice does not have OSGi But if you want OSGi metadata added to Guice's AOP Alliance jar feel free to open a In summary: check the bindings for private types, try out the Guice binary from the |
From mcculls on May 22, 2009 06:12:12 Also a quick comment about: > That bundle's manifest also required modification as it was importing This is recommended best-practice in OSGi, bundles should import their own exports to |
From a.shewring on May 22, 2009 14:47:01
Thank you very much for your detailed explanations and for pointing out the OSGi best Binary attachments: guice-2.0.jar, guice-assistedinject-2.0.jar |
From mcculls on April 20, 2007 05:33:19
Here's a simple patch that lets you use Guice on OSGi (including method interception)
For a more detailed example see my local sandpit project: https://scm.ops4j.org/repos/ops4j/laboratory/users/stuart/peaberry it doesn't do a lot at the moment but it does successfully use several Guice features.
Attachment: gist
GUICE_OSGI.patch
Original issue: http://code.google.com/p/google-guice/issues/detail?id=94
The text was updated successfully, but these errors were encountered: