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

java implement dynamic plugins in Java

I developed an application that loads plugins dinamicaly according to this tutorial: http://solitarygeek.com/java/a-simple-pluggable-java-application, but i came across a problem. In my main application i have a class with static methods, how can i…
And Cost
  • 95
  • 8
0
votes
0 answers

How to register a custom ClassLoader with ServiceLoader for a JUnit Launcher?

I would like to use a custom ClassLoader when programmatically running JUnit tests. According to the JUnit 5 User Guide: In order to intercept the creation of instances of Launcher and LauncherSessionListener and calls to the discover and execute…
Ellen Spertus
  • 6,576
  • 9
  • 50
  • 101
0
votes
2 answers

How To Cache Java ServiceLoader.Provider Efficiently

I currently working on a JPMS project and would like to be able to cache the Providers retrieved on ServiceLoader.load() to be able to use their get() method later for a new set of service instances - without a reference to the ServiceLoader…
0
votes
1 answer

Opening service declaration file inside a Jar

List resources = new ArrayList<>(); try { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Enumeration importedResources = classLoader.getResources("META-INF/services"); while (importedResources.hasMoreElements())…
Teddy Tsai
  • 414
  • 1
  • 13
0
votes
0 answers

Can't access ServiceLoader from Flink Taskmanager Node

When I try to obtain an instance of a Class through ServiceLoader on a TaskManager node the class cannot be loaded, basically I cannot access the classes declared in META-INF/services via ServiceLoader at Runtime. I am using ShardignSphere to…
Teddy Tsai
  • 414
  • 1
  • 13
0
votes
0 answers

What's the proper way to isolate plugins loaded via `ServiceLoader`?

I'm using Java's ServiceLoader to load plugins into my app. The plugins are provided as JARs on the classpath when starting the app. Now, if these plugins contain classes or resources with the same name, there may be conflicts. Thus, what's the…
sschuberth
  • 28,386
  • 6
  • 101
  • 146
0
votes
1 answer

Java ServiceLoader wrapper not working, internally using calling class

So, I've been trying to make a small PluginLoader in my library which allows you to load JAR files into a custom ModuleLayer and use the layer to load services using ServiceLoader.load(ModuleLayer, Class). However, when calling…
Wexalian
  • 1
  • 1
0
votes
0 answers

ServiceLoader not loading classes in Bukkit plugin

So I started working on a new Bukkit plugin and did some research on possible ways of automating listener registration. I came across the ServiceLoader class and read its JavaDocs. Basically I'm trying to load all the classes that implement the…
0
votes
1 answer

ServiceLoader does not locate implementation when Gradle javafxplugin is used

I am implementing a program where the core part is separated from the GUI and loaded at runtime as a service. I am struggling for weeks to have the implementation discovered at runtime. To try isolating the problem, I picked up a minimal…
CT95
  • 107
  • 1
  • 11
0
votes
0 answers

Why Java gives ServiceLoader Exception when I have two versions of webservices-rt.jar in same path? ServiceConfigurationError PolicyAssertionValidator

I am facing this ERROR during runtime on Unix environment. java.util.ServiceConfigurationError: com.sun.xml.ws.policy.spi.PolicyAssertionValidator: Provider com.sun.xml.ws.rm.policy.spi_impl.RmAssertionValidator could not be instantiated I have…
N.D.Baba
  • 11
  • 1
0
votes
1 answer

loading classes with different classloaders to unload them from the JVM when not needed

In my application i'm using ServiceLoader to load modules(classes from .jar file) with different ClassLoaders in order to completely unload them when not needed from the context of the application and from the JVM itself. I know maybe is not a…
Wyvern666
  • 633
  • 1
  • 11
  • 26
0
votes
0 answers

ServiceLoader is returning empty list for services on Wildfly-17.0.1

ServiceLoader serviceLoader = ServiceLoader.load(ConnectionLoader.class); My web application has 3 implementations of the ConnectionLoader service and the above API works perfectly fine on almost all the web application servers…
0
votes
1 answer

Launching fragment via ServiceLoader in Dynamic Feature (Android)

I'm trying to launch a fragment in my a dynamic feature module using a ServiceLoader as follows, but I get a crash the first time I try to launch my fragment. After the initial crash, if I try to launch the fragment again, it loads fine. I am…
0
votes
0 answers

java.util.ServiceLoader does not work inside of an AnnotationProcessor

I am using Java 17. I have created a library with a bunch of utility stuff, including a "Service", doing something. This Service is published both the old style (using a file META-INF/services/) and also through the…
tquadrat
  • 3,033
  • 1
  • 16
  • 29
0
votes
1 answer

Modular jars/plugins within a Wildfly Web Application using ServiceLoaders

We extensively use Java ServiceLoaders as a plugin infrastructure for our application components. We define interfaces, and then use the loader to load them at run time. Adding additional jars with extensions and service files are fine for our use…