0

I am using java.util.ServiceLoader to create a lightweight plugin framework.

I am currently wrestling with how to have multiple implementing classes with the same FQN. I would like to have two copies of the same plugin on the classpath and have access to both implementing classes given in the META-INF/services directory.

Here are some simple eclipse projects that illustrate what I mean: https://docs.google.com/open?id=0B4MxFm-ACB3IUmswN0dpMExTVms

ServiceLoaderIntf has the simple interface that is implemented by the plugins. ProjectOne and ProjectTwo represent the plugins. ServiceLoader has the Tester class which iterates through the implementors and calls the init() method on them.

How can I get it to recognize all implementors, even if the implementing classes have the same FQNs? Right now it just recognizes the plugin class in ProjectOne.

mainstringargs
  • 13,563
  • 35
  • 109
  • 174

1 Answers1

0

Since the service classes are being loaded by the same shared class loader you may not use the same FQNs for the implementation classes.

Additionally, it doesn't make sense to share the same FQN between various implementations as the class name should at least hint its purpose.

JB-
  • 2,615
  • 18
  • 17