What else can I use in Java as an alternative to ServiceLoader?

I am looking for something like ServiceLoader, but which does not depend on the SPI file, where all implementations of the service must be listed, and then added to the path of some class loader so that they can be found.

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

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

Thanks for any suggestions!

+3
source share
3 answers

The easiest solution is to use JSPF .

More “enterprise” could be used with OSGi ... but in this case you need to take a look at iPOJO as an example. Sorry, I finally reread your message. I think that, contrary to what you say, OSGi is precisely copied for your needs, as it accurately allows you to download services and dynamic wiring.

And IoC containers can provide this function with some extensions (I think this is possible even with the Guice extension).

+7
source

It seems that you are looking for the Netbeans Search API - Link

+2
source

( ) sezpoz.

It is very similar to the JDK ServiceLoader in that it uses a resource search META-INF, except that resources are automatically created by the annotation processor. Thus, his most abstract is heavy and, as a rule, safer in price after processing. It was used by Hudson / Jenkins.

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

0
source

Source: https://habr.com/ru/post/1753509/


All Articles