Create plugin with library that uses ServiceLoader

I've got a library that uses ServiceLoader to pull in implementation classes.  Standalone it works great, but I'm trying to run the same code while in a plugin and ServiceLoader returns no instances.  I've tried passing a ClassLoader to ServiceLoader.load (both ClassLoader.getSystemClassLoader() and MyClass.class.getClassLoader()), I've tried setting the context classloader on the thread (Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()), but nothing seems to change the behavior.

Any thoughts, save running this in an entirely separate process?

0
1 comment

The implementations for ServiceLoader are configured in files under META-INF/services directory. Are you sure that these files are copied to the plugin output and available at runtime? You may need to put them under 'resources' root.

 

0

Please sign in to leave a comment.