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
50
votes
3 answers

Dynamically loading plugin jars using ServiceLoader

I'm trying to create a plugin system for my application, and I want to start with something simple. Every plugin should be packed in a .jar file and implement the SimplePlugin interface: package plugintest; public interface SimplePlugin { …
MaxArt
  • 22,200
  • 10
  • 82
  • 81
38
votes
5 answers

Java ServiceLoader with multiple Classloaders

What are the best practices for using ServiceLoader in an Environment with multiple ClassLoaders? The documentation recommends to create and save a single service instance at initialization: private static ServiceLoader codecSetLoader =…
Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
25
votes
3 answers

ServiceLoader to find implementations of an interface

I tried to use the Java ServiceLoader to find all classes that implement a specific interface like so: loader = ServiceLoader.load(Operation.class); try { for (Operation o : loader) { operations.add(o); } } catch…
Caroline
  • 381
  • 1
  • 4
  • 13
19
votes
2 answers

When to use ServiceLoader over something like OSGi

Being someone who is allergic to dependencies, when would I use something like OSGi instead of the built in java 6 http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html (I want to let plugin jars just be dropped in). (FYI this is in a…
Michael Neale
  • 19,248
  • 19
  • 77
  • 109
15
votes
2 answers

Unable to derive module descriptor: Provider {class X} not in module

I am getting this error message when I try to compile my new modularized Java 11 application: Error occurred during initialization of boot layer java.lang.module.FindException: Unable to derive module descriptor for…
Wige
  • 3,788
  • 8
  • 37
  • 58
13
votes
5 answers

Using serviceloader on android

I am very new to java and android development and to learn I am trying to start with an application to gather statistics and information like munin does. I am trying to be able to load "plugins" in my application. These plugins are already in the…
silverchris
  • 139
  • 1
  • 4
13
votes
4 answers

In Java, how can I mock a service loaded using ServiceLoader?

I have a legacy Java application that has code something like this ServiceLoader.load(SomeInterface.class) and I want to provide a mock implementation of SomeInterface for this code to use. I use the mockito mocking framework. Unfortunately I am…
Graeme Moss
  • 7,995
  • 4
  • 29
  • 42
13
votes
5 answers

how to override a service provider in java

This is more a general question by example: I'm using xstream and woodstox, woodstox comes with a service provider for javax.xml.stream.XMLOutputFactory in woodstox jar registering com.ctc.wstx.stax.WstxOutputFactory. I want to provide my own…
Shalom938
  • 909
  • 2
  • 10
  • 24
12
votes
1 answer

Java ServiceLoader explanation

I'm trying to understand the Java ServiceLoader concepts, working mechanism and concrete use cases, but find the official documentation too abstract and confusing. First of all, documentation outlines services and service providers. Service is a…
Tuomas Toivonen
  • 21,690
  • 47
  • 129
  • 225
11
votes
2 answers

FactoryFinder performance/bad caching

I've got a rather large java ee application with a huge classpath doing a lot of xml processing. Currently I am trying to speed up some of my functions and locating slow code paths via sampling profilers. One thing I noticed is that especially parts…
Wagner Michael
  • 2,172
  • 1
  • 15
  • 29
8
votes
0 answers

In OSGi, ServiceLoader.load fails to find an implementation

We have been trying to get SPI Fly to work with openstack4j-core and one of the openstack4j connectors (openstack4j-httpclient). It is org.openstack4j.core.transport.HttpExecutorService that require the SPIFly weaving. One quirk: both bundles are…
8
votes
1 answer

ServiceLoader.next causing a NoClassDefFoundError

I'm asking because I'm totally not sure I've done the right thing. I'm using Eclipse for a web project. Let's call it WebProject (duh) in the package com.web.project. I want WebProject to load JAR plugins at runtime, so I thought I could take…
MaxArt
  • 22,200
  • 10
  • 82
  • 81
8
votes
1 answer

ServiceLoader issue in WebLogic12c

I have been trying to refactor our Activiti implementation into using CDI but ran into a number of problems. I've spent way too much time trying to resolve this already, but I just can't let it go...I think I've pinned the problem down now, setting…
7
votes
1 answer

Where to put ServiceLoader config file in a web app

I am writing a web app in Eclipse. I am trying to use the ServiceLoader class to load some plugins. The docs for ServiceLoader say I need to place a file in META-INF/services. I have placed the file in the WebContent/META-INF/service folder but when…
ljbade
  • 4,576
  • 4
  • 30
  • 35
7
votes
1 answer

ServiceLoader doesn't load implementation

I really did a lot of research before asking this, it seems like I'm missing something. I try to implement a ServiceLoader and therefore made an example class: the code is simple: testInterface.java package com.test; public interface testInterface…
Hr. Burtz
  • 73
  • 1
  • 7
1
2 3
10 11