serviceloader

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

泄露秘密 提交于 2019-12-05 21:52:55
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 implementations.jar, which has several implementations of this interface, all specified in the spi/META-INF/services/my.package.name.MyInteface file (this file is in the implemenations.jar). I also have a class ImplementationHandler (in yet another handler.jar), which has the following method to load all implementations: private static List<MyInterface<?>>

ServiceLoader.next causing a NoClassDefFoundError

你离开我真会死。 提交于 2019-12-05 06:22:14
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 advantage of java.util.ServiceLoader . So I created an interface com.web.project.WebProjectPlugin in the WebProject project with all the methods the plugins must implement. Then I created the project PluginProject, adding WebProbject/build/classes in its Build path as a class folder: package com.web.project.plugin; import com.web.project.WebProjectPlugin

When to use ServiceLoader over something like OSGi

两盒软妹~` 提交于 2019-12-03 05:01:04
问题 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 scala app, open to any suggestions, ServiceLoader is pretty damn close to what I want). 回答1: If ServiceLoader mostly fits your needs, that says that you're looking for service discovery via the presence of files on the class path. That's only a

When to use ServiceLoader over something like OSGi

两盒软妹~` 提交于 2019-12-02 19:21:26
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 scala app, open to any suggestions, ServiceLoader is pretty damn close to what I want). If ServiceLoader mostly fits your needs, that says that you're looking for service discovery via the presence of files on the class path. That's only a small part of what OSGi provides. OSGi will let you dynamically install bundles, advertise services, revoke

Where to put ServiceLoader config file in a web app

◇◆丶佛笑我妖孽 提交于 2019-12-01 04:23:13
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 I run the JUnit test via Eclipse it does not find any plugins. Is this the correct location for the file? Also, how can I get more debug info from ServiceLoader such as the folders it is searching for the file in? The META-INF/services should be at the root of the jar file or resource directory in the classpath of the classloader used to locate

ServiceLoader to find implementations of an interface

隐身守侯 提交于 2019-11-30 10:58:22
问题 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 (ServiceConfigurationError e) { LOGGER.log(Level.SEVERE, "Uncaught exception", e); } Unfortunately, when I run Eclipse in debug mode the ServiceLoader doesn't find any classes. I feel like I'm missing a trivial point... 回答1: ServiceLoader cannot do it. In order to expose class as a

ServiceLoader to find implementations of an interface

主宰稳场 提交于 2019-11-29 22:21:09
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 (ServiceConfigurationError e) { LOGGER.log(Level.SEVERE, "Uncaught exception", e); } Unfortunately, when I run Eclipse in debug mode the ServiceLoader doesn't find any classes. I feel like I'm missing a trivial point... axtavt ServiceLoader cannot do it. In order to expose class as a service that can be discovered by ServiceLoader you need to put its name into provider configuration

how to override a service provider in java

白昼怎懂夜的黑 提交于 2019-11-29 09:44:08
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 javax.xml.stream.XMLOutputFactory and still have woodstox jar in the classpath. I know I can provide my own with the system property javax.xml.stream.XMLOutputFactory , but I'm trying to take off the hassle from our dev ops team and do it with a service file in my jar or maybe in my war's META-INF/services folder. looking the code of javax.xml.stream

Dynamically loading plugin jars using ServiceLoader

坚强是说给别人听的谎言 提交于 2019-11-27 10:44:50
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 { public String getName(); } Now I've created an implementation of SimplePlugin , packed in a .jar and put it in the plugin/ subdirectory of the main application: package plugintest; public class PluginTest implements SimplePlugin { public String getName() { return "I'm the plugin!"; } } In the main application, I want to get an instance of PluginTest . I've

Java ServiceLoader with multiple Classloaders

主宰稳场 提交于 2019-11-27 10:14:52
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<CodecSet> codecSetLoader = ServiceLoader.load(CodecSet.class); This would initialize the ServiceLoader using the current context classloader. Now suppose this snippet is contained in a class loaded using a shared classloader in a web container and multiple web applications want to define their own service implementations. These would not get picked up in the above code, it