I'm trying to load a jar at runtime by URLClassLoader
through Service Provider API. However, it turns out a failure.
Following are what I've done:
- Create a module named
shadow-plugin-api
, which contains interfacecom.github.soiff.shadow.api.Plugin
to be implemented by plugin; - Create a implementation of
shadow-plugin-api
namedshadow-plugin
and packaged asshadow-plugin-0.0.1-SNAPSHOT.jar
, the implementation class iscom.github.soiff.shadow.plugin.SpringPlugin
; - Create spring boot application named
shadow-core
and includeshadow-plugin-api
; - Load
shadow-plugin-0.0.1-SNAPSHOT.jar
byURLClassLoader
dynamically and try to load mycom.github.soiff.shadow.plugin.SpringPlugin
throughServiceLoader
but it gets nothing.
My git repository is : https://github.com/soiff/soiff-shadow.
I've tried following solution, but still could not make it work. Please give me some advice, thanks in advance!
- I've tried abstract class instead of interface of my SPI interface and change it back to interface when I could not achieve my goal;
- I've tried
PathMatchingResourcePatternResolver
to get resource and pass myURLClassLoader
as the input parameter but it did not work; - I've tried
ResourceFinder
implemented by Apache and it could not find proper resource neither;
My question is how could I load resources from an external jar by URLClassLoader
? Could SPI be a possible solution?