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
4
votes
0 answers

How do I use the Java ServiceLoader class in Grails?

I've used the JDK's SPI mechanism in numerous other applications without any problem; however, I can't seem to get it to work within Grails. I've tried the usual code (shown below) both from within a static initializer, and from within a class…
mfortner
  • 331
  • 2
  • 6
4
votes
3 answers

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

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…
m_pGladiator
  • 8,462
  • 7
  • 43
  • 61
3
votes
1 answer

JPMS ServiceLoader does not work for me as expected

JPMS ServiceLoader does not work for me as expected. I am trying to provide a desktop program as an executable jar with a default service, that can be overloaded by the individual user. A user provides their own service class and give their name as…
ngong
  • 754
  • 1
  • 8
  • 23
3
votes
0 answers

ServiceLoader does not load implementation jars

I am trying to implement a simple modular application with a self written plugin loader. For that I created a gradle multiproject build. The main project is going to be the started application. In the subproject spi is a module containing the Plugin…
Zeroneca
  • 31
  • 2
3
votes
0 answers

Dynamically (re)load service provider module

I want to load and reload a service provider in a jar which is a module. It is my understanding that this can be achieved by loading the module in a new ModuleLayer. Following the advice in this answer and the example in the docs, I have succeeded…
3
votes
1 answer

Simple ServiceLoader - java.util.ServiceConfigurationError ... Provider ... not found

I am trying to run sample application using ServiceLoader. For this, I have created two JARs: JAR 1) number-service.jar META-INF/ META-INF/MANIFEST.MF ok/ ok/service/ ok/service/NumberService.class ok/main/ ok/main/App.class …
Onkar Kamatkar
  • 212
  • 2
  • 10
3
votes
0 answers

How to add a ExchangeRateProvider to javax.money

I wrote a custom ExchangeRateProvider that needs dependency injection. But for java.money you need to add your custom class in a file under META-INF/services/javax.money.convert.ExchangeRateProvider. The normal ServiceLoader does not use dependency…
Ben Keil
  • 1,050
  • 1
  • 10
  • 30
3
votes
2 answers

Using ServiceLoader within an annotation processor

Is it possible to use ServiceLoader from within the init(ProcessingEnvironment) method of an Annotation Processor? interface Service {} class AnnotationProcessor extends AbstractProcessor { public static void main(String[] args) { …
bnorm
  • 908
  • 1
  • 7
  • 14
3
votes
1 answer

ServiceLoader and META-INF/services generator between different modules in maven?

I would like to use service ServiceLoader between diferrent modules in a maven Project. I have a parent module called iMage. In the parent module there is a module with a name jmjrst.main and it has a public abstract class called JmjrstPlugin. Then…
Armin Beda
  • 109
  • 9
3
votes
1 answer

ServiceLoader not loading new services

My ServiceLoader dont want to load my new service. I think I have everything correctly setted up. Core.Main public class Main { public static void main(String[] args) { System.out.println("Before"); Iterator services =…
medy75
  • 652
  • 11
  • 33
3
votes
0 answers

ServiceLoader load from different packages

I wrote a generic ServiceLocator using the ServiceProviderPattern. public List locateAll(final Class clazz) { final Iterator iterator = ServiceLoader.load(clazz).iterator(); final List services = new ArrayList(); …
user1772306
  • 449
  • 1
  • 7
  • 20
3
votes
1 answer

How to register a SPI implementation when running exec:java

I'm trying to make VertX Mertrics work when running via the exec:java Maven plugin. All works as expected when I package the application into a fatjar and run it with java -jar fat.jar -conf config.json -Dvertx.metrics.options.enabled=true When I…
Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61
3
votes
1 answer

How does Java ServiceLoader work during development time? (Unit test before building JARs?)

Java's ServiceLoader needs those entries to be present inside the JAR file. Is there a way to programatically add those service entries at runtime time for unit testing, when inside the IDE? Especially when the JARs are not built yet.
Ashwin Jayaprakash
  • 2,168
  • 24
  • 29
3
votes
3 answers

How to make the java ServiceLoader work in a NetBeans 6.9 module application

I have troubles using the java ServiceLoader in a NetBeans module application. Here is what I'm trying to do (and it works in a normal java application in Eclipse): I have an interface.jar, which declares the interface. And I have…
m_pGladiator
  • 8,462
  • 7
  • 43
  • 61
3
votes
1 answer

Writing modular Java applications

I have a project with the following structure: +---main | \pom.xml +---module1 | \pom.xml +---module2 | \pom.xml +---module3 | \pom.xml +---module4 | \pom.xml +---pom.xml The modules uses ServiceLoader mechanism to register their…
Boyolame
  • 329
  • 2
  • 13
1 2
3
10 11