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
1
vote
2 answers

How do load a Service without using ServiceLoader.Provider class (for J1.8 compatibility)

I'm trying to back-port to J1.8 an application written for J9 (Update4j); it uses ServiceLoader.Provider class and its methods. The original code is: public static T loadService(ModuleLayer layer, ClassLoader classLoader,…
1
vote
0 answers

Java SPI - Choosing a single implementation

Java SPI is simple to use when we want to find all available implementations of an interface or abstract class and perform an action with each: ServiceLoader.load(SomeService.class) .forEach(service -> service.doSomething()); What is the idiom…
Ivan G.
  • 700
  • 8
  • 19
1
vote
0 answers

Java - ServiceLoader - Intellij cannot find implementation class files

Intro I am trying to create multiple services which fuzz the input (for testing purposes. I am using the concept of dependency injection using java.util.ServiceLoader feature. I am using IntelliJ for this project. Github Project Link:…
Abhishek Ghosh
  • 2,593
  • 3
  • 27
  • 60
1
vote
1 answer

Get the same instance of a service provider class that provides more than one service with ServiceLoader

I have a problem and I don't know which way to got about it Say I have two Service Provider Interfaces (SPI) public interface View{ display(); } public interface Logger{ log(String s); } And a Service provider that provides both services…
Yemi Kudaisi
  • 163
  • 1
  • 7
1
vote
1 answer

How to dynamically load class from within a JAR application for use in another JAR?

I have a JAR application, M.jar that supports extensions to be written and loaded dynamically. The application requires that the classes implement interface E and be called NE. Now, the following is what I'm trying to do, Write an extension API1…
1
vote
1 answer

Provider not a subtype inside docker container

Situation I'm developing an application that uses Java's URLClassLoader and ServiceLoader to load jar files. Inside these jar files is the provider that implements my interface. The folder structure is as described in this post by oracle meaning…
Oromë
  • 199
  • 2
  • 16
1
vote
1 answer

Class loaders and Service Loader. Which class loader is used?

I am working on writing an extensible application. Reading the documentation about the ServiceLoader utility class, I was not able to understand the following sentence: The provider must be accessible from the same class loader that was initially…
phil91
  • 81
  • 3
  • 14
1
vote
1 answer

ServiceLoader, URLClassLoader & Spring: java.lang.NoClassDefFoundError

I'm trying to load an external module.jar, which implements an Interface from my main spring application. Therefore I implemented this solution @Override public void onApplicationEvent(ApplicationReadyEvent event) { File loc = new…
mietzekotze
  • 195
  • 13
1
vote
2 answers

ServiceLoader using ClassLoader pointing to different path

Have been trying this since few days and can't get it working! I am trying to build a pluggable java application where I can run it from command line and provide plugins (jars) in a separated folder. It seems the ServiceLoader would fit my…
user1611183
  • 311
  • 1
  • 5
  • 12
1
vote
1 answer

Why does ServiceLoader always re-instantiate a service?

Let's say I have a service interface com.example.Service. For a test, I defined a src/test/resources/META-INF/services/com.example.Service file which contains com.example.sometest.MockServiceImpl the MockServiceImpl implements the interface. Now,…
rabejens
  • 7,594
  • 11
  • 56
  • 104
1
vote
1 answer

ServiceLoader + EJB injection

I would like to know if I can combine the ServiceLoader with EJB and injection from Java EE 6. Imagine I have an interface ServiceI that can be implemented by two EJB stateless beans BeanA and BeanB. If I register these two classes in the…
phoenix7360
  • 2,807
  • 6
  • 30
  • 41
1
vote
1 answer

Guice with Serviceloader Creating class instances for plug ins without using injector

My core application is complete. I am able to successfully load modules but I still cant properly use guice to inject dependencies in my modules. My core app loades modules using service loader and installs them using the install method of guice's…
MykelXIII
  • 1,085
  • 1
  • 8
  • 16
1
vote
2 answers

ServiceLoader issue in Jetty

I am working on a web application which should be able to load plugins during runtime. I am aware that OSGi would be a elegant solution for this, but as GWT is used , I do not see the transition to OSGi happening. To implement the plugin, I have 3…
Tom
  • 31
  • 1
  • 5
1
vote
1 answer

how to use truevfs META-INF/services on glassfish 4

Im trying to use truevfs library from application deployed on glassfish 4. Below code works excelent if used in a standalone java-se app, but it fails to look up the filesystem provider when used from inside glassfish. Is this suposed to work? what…
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
1
vote
0 answers

Where to place META-INF in Android project

I'm writing an app that needs to load dinamically plugins from external libraries. My first idea was -with very little immagination- to use Java's ServiceLoader and googling a little bit I found documentation that states that this kind of action is…
Stefano Cazzola
  • 1,597
  • 1
  • 20
  • 36