What else can be used in Java as the ServiceLoader alternative?
Asked Answered
C

3

5

I'm looking for something like the ServiceLoader, but which does not depend on SPI file, where all the service implementations should be enumerated and then added to the path of some class loader, in order to be found.

Let's say there is an application, that has the interface and some implementations of a service. What framework can be used, that allows you to add a new JAR to the application, which contains some new implementations and they can be automatically added to the class path of all the class loaders inside that application? All the class loaders is very important here, because if this is a NetBeans module application, the NetBeans platform does weird magic and you never know which class loader is used by which thread, with which class path etc... It would be also great, if the application does not need to be restarted to find the new JAR, but that's not an important requirement.

I already heard about OSGi, but this seems too big and I only need 1% of its features.

Thanks for any suggestions!

Covariance answered 7/7, 2010 at 11:39 Comment(0)
W
7

Simplest solution is to use JSPF.

More "enterprise" one could be to use OSGi ... but in that case, you'll have to take a look at iPOJO, as an example. Sorry, I finally re-read your message. I think that, contrary to what you say, OSGi is exactly scopped for your need, as it precisely allows service loading and dynamic wiring.

And IoC containers may provide, with some extensions, that kind of feature (I think it's at least possible using a Guice extension).

Whichsoever answered 7/7, 2010 at 12:26 Comment(2)
JSPF looks very promising on its feature list and seems simple! I'm going to try it... Thanks!Covariance
It really works out of the box! And even works with NetBeans! Great! I prefer a ready solution for now. If I have the time later I'll try writing a Guice extension.Covariance
I
2

Seems that you are looking for Netbeans Lookup API - Link

Induce answered 7/7, 2010 at 13:2 Comment(1)
Sorry but I would like to avoid everything NetBeans related - I simply don't want to hear anymore anything about NetBeans! All my troubles comes from NetBeans related stuff!Covariance
P
0

A newer alternative (this is an old question) might be sezpoz.

Its very similar to the JDK ServiceLoader in that it uses a META-INF resource lookup except that the resources are automatically created by an annotation processor. Thus its very annotation heavy and generally more type safe at the cost of post processing. Its used by Hudson/Jenkins.

I believe Kohsuke was the first to come up with this annotation processing idea: http://metainf-services.kohsuke.org/

Pincer answered 25/2, 2015 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.