Questions tagged [serviceloader]

ServiceLoader is a Java SDK way to load different providers for a class from the classpath. It uses special configuration files in META-INF/services.

The full documentation is provided by Oracle at http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html

163 questions
3
votes
3 answers

ServiceLoader.load is not finding the META-INF/services

So I want to build an extensible android application where developers can add 'CustomDevice' classes and the main program will run them automatically without editing existing code. I've read about Service Provider interface and thought that would be…
user1378063
  • 263
  • 1
  • 6
  • 9
3
votes
1 answer

Is there an analogue of ServiceLoader in Spring and how to use it?

I am trying to find out if there is a Spring analogue of the ServiceLoader class which is part of the standard SDK's API. If there is such a class how is it used? Please advise!
carlspring
  • 31,231
  • 29
  • 115
  • 197
3
votes
1 answer

does java.util.ServiceLoader load only a single instance of a service

I want to ask whether the ServiceLoader.load() can help me create multiple instances of the loaded service? I have been doing some testing and its seems it can only load one instance of the service at a time. If it is possible to have multiple…
MykelXIII
  • 1,085
  • 1
  • 8
  • 16
2
votes
2 answers

Searching for an elegant way in PHP for loading dependencies/services/configuration?

I'm building a MVC PHP framework and I wonder which are the best practices to load what I need in my classes, be it other classes or plain configuration. Till today I've used singletons, registry and lately a dependency injection container. While…
2
votes
1 answer

Why should an application module not require a module that provides a service?

The ServiceLoader.java docs notes: It is strongly recommended that the application module does not require modules which contain providers of the service. Why is this strongly recommended, what could happen if the recommendation isn't…
Toast
  • 93
  • 1
  • 6
2
votes
0 answers

ServiceLoader fails when starting from jar

While trying to implement classpath locations for URL a URLStreamHandlerProvider implementation was developed and added to META-INF/services/java.net.spi.URLStreamHandlerProvider as per…
2
votes
0 answers

Cannot load custom File System on Flink's shadow jar

I needed some metadata on my S3 objects, so I had to override the S3 file system provided by flink. I followed this guide to the letter and now I have a custom file system which works on my local machine, when I run my application in the IDE. Now I…
Jack
  • 57
  • 6
2
votes
1 answer

Java ServiceLoader not finding downloaded module in jar

I am building a client/server application. The client runs a small loader that downloads the client in the form of a module jar, but only if the client.jar has changed. The loader then attempts to run the client through ServiceLoader. Here is the…
Steve Brandli
  • 556
  • 4
  • 14
2
votes
1 answer

Creating Extensible Applications using service-loaders according to a singleton design pattern

I'm working on project on IntelliJ IDEA and I want to add support to Extensible Applications in my java application. The way to do it is, creating a jar file in this jar file there should be a META-INF/services directory, inside this directory, I…
2
votes
1 answer

Potential problems when using a modular jar on the classpath

What are the potential problems when using a valid modular jar (which contains a module-info.class) on the class-path of a non-modular application instead of on the module-path? There are only two possible problems that come to my mind at the…
mipa
  • 10,369
  • 2
  • 16
  • 35
2
votes
1 answer

Enum-aware ServiceLoader implementation?

I would like to be able to indicate an enum type as an interface implementation and then load all enums as separate instances/implementations of the interface via the ServiceLoader API. An example of this use case would be to allow downstream users…
J. Dimeo
  • 262
  • 2
  • 10
2
votes
0 answers

Is it possible to generate service provider with annotation processor in java9 modules based project

Before java9 modules there was an option to generate both service provider implementation classes and META-INF/services files. With this option service provider classes generated during annotation processing were accessible via ServiceLoader in…
2
votes
1 answer

How to register a custom AppHistoryServerPlugin?

How can I create my own implementation of AppHistoryServerPlugin trait and provide it as a service through ServiceLoader to Apache Spark? Note: This plugin class is inside a JAR which is in the class path of Apache Spark. Source Directory…
nomadSK25
  • 2,350
  • 3
  • 25
  • 36
2
votes
2 answers

Is the Iterable Object from the ServiceLoader oredered?

I have a pretty simple question, but i can't manage to find the correct answer. So in my project i have an abstract class "JmjrstPlugin", from which some other plugins inherit. I'm using javas ServiceLoader to find all of the plugin classes like…
T. Grumser
  • 99
  • 3
  • 18
2
votes
5 answers

Java, Get all classes available to a URLClassLoader that implement a specific interface

I am working on a command line app that loads user specified text translators at runtime (path to class files/jar provided via command line arg). Basically I am taking that argument and using it to create a URLClassLoader. Then I need to find all…
jdc0589
  • 6,972
  • 5
  • 36
  • 39