Guice pluggability without OSGi

88 views
Skip to first unread message

Jean-Francois Poilpret

unread,
Jul 31, 2008, 9:34:03 AM7/31/08
to google...@googlegroups.com

Hello,

 

I have just written a small prototype that enables an application to search dynamically for Guice Modules in plugins (external jars) and create an Injector from these Modules. I’ve put some details on my blog, if someone is interested by this topic:

 

http://jfpoilpret.blogspot.com/2008/07/dynamically-loading-guice-modules-as.html

 

Cheers, Jean-Francois

Anthony MULLER

unread,
Jul 31, 2008, 9:47:23 AM7/31/08
to google...@googlegroups.com
I was just working on the same idea too! :)  Great work !

Can I use your classes freely?

Question about your GUI project: i will be based on Swing?

Anthony MÜLLER


2008/7/31 Jean-Francois Poilpret <jfpoi...@yahoo.fr>

Robbie Vanbrabant

unread,
Jul 31, 2008, 9:51:04 AM7/31/08
to google...@googlegroups.com
Cool! Also note that JDK 6 offers similar functionality with its ServiceLoader: http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html

Robbie

Jean-Francois Poilpret

unread,
Jul 31, 2008, 10:23:22 AM7/31/08
to google...@googlegroups.com

Hi Anthony,

 

You can freely copy the code from my blog, it is under ASL 2.0 license (like all my Open Source projects).

About Guice-GUI project, yes it is Swing-based (more exactly Swing Application Framework-based).

 

Cheers

 

Jean-Francois

 


Jean-Francois Poilpret

unread,
Jul 31, 2008, 10:25:37 AM7/31/08
to google...@googlegroups.com

Damn! I should have googled that before starting my experiments! I am not using Java 6, but I should have known that anyway. OK, at least it shall be useful to Java 5 users;-)

 

Cheers, Jean-Francois

 


From: google...@googlegroups.com [mailto:google...@googlegroups.com] On Behalf Of Robbie Vanbrabant
Sent: Thursday, July 31, 2008 8:51 PM
To: google...@googlegroups.com
Subject: Re: Guice pluggability without OSGi

 

Cool! Also note that JDK 6 offers similar functionality with its ServiceLoader: http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html

Robbie

Anthony MULLER

unread,
Jul 31, 2008, 10:28:22 AM7/31/08
to google...@googlegroups.com
Sure :)

At least Sun provides ServiceLoader as an external library for Java 5 :)

About ASL, it stands for Apache Licence ?

Anthony


2008/7/31 Jean-Francois Poilpret <jfpoi...@yahoo.fr>

Anthony MULLER

unread,
Jul 31, 2008, 10:30:06 AM7/31/08
to google...@googlegroups.com

Jean-Francois Poilpret

unread,
Jul 31, 2008, 10:58:46 AM7/31/08
to google...@googlegroups.com

Yes,

 

ASL stands for Apache License.

Checking the link you provided, I actually wonder if this goes as far as my example: I don’t see any way to find out all Guice Modules placed in jars in a directory that is NOT in the classpath… So there may still be room for improvement in Java 6 ServiceLocator?

 

Cheers, Jean-Francois

 


Anthony MULLER

unread,
Jul 31, 2008, 11:03:28 AM7/31/08
to google...@googlegroups.com
Oui you're right...

However, if you look at this link (particulary the comments bellow) it seems that some members are not really convinced by use of the ServiceLoader and think that it will be depreciate later...

As for me, it is a simple and efficient way to make modular applications easily!

Anthony MULLER

unread,
Jul 31, 2008, 11:04:07 AM7/31/08
to google...@googlegroups.com

Brian Pontarelli

unread,
Jul 31, 2008, 11:08:46 AM7/31/08
to google...@googlegroups.com
JCatapult also does this. I use ASM and search the classpath for packages named "guice" and then load everything from that package that implements Module. The JCatapult code also handles overriding of classes by only loading the leaf nodes of the inheritance graph. 

When I was developing it I looked at ServiceLoader, but one of JCatapult's main principles is minimize configuration whenever possible. Therefore, I went with a pure discovery approach. 

Feel free to check out the code and grab whatever you need. It is also open source under the ASLv2 (Apahce Source License version 2 ). It is located here:


The actual classpath searching is performed by Java.net Commons library. That code is located here:


Let me know if you have questions.

-bp

Anthony MULLER

unread,
Jul 31, 2008, 11:15:16 AM7/31/08
to google...@googlegroups.com
Nice! Thanks!


2008/7/31 Brian Pontarelli <br...@pontarelli.com>
Reply all
Reply to author
Forward
0 new messages