2

I have a webapp using Google Guice modules, deployed to Tomcat 9.

I would like to offer the possibility for a user to dynamically add some modules exposing some bindings without repackaging the webapp to include them.

I use the ModuleLoader from this question: Has anyone used ServiceLoader together with Guice? In my main application, I define a custom interface : PluginModule

public interface PluginModule extends Module {

The plugin module class looks like this:

@AutoService(PluginModule.class)
public class MyPluginModule extends AbstractModule implements PluginModule {

I suppose my plugin is well configured because the webapp can also run as standalone and in this case my plugin is found, the module is installed and the contained bindings are made available.

However, when deployed to Tomcat/webapps, I get this error:

java.util.ServiceConfigurationError: com.mycompany.PluginModule: Provider com.mycompany.MyPluginModule not a subtype

The plugin is in Tomcat/shared/libs (with "shared.loader" configured in catalina.properties)

I supposed it's related to some classloader issue, maybe the loaded interfaces are considered not the same in the webapp and in the plugin, so I tried to put the PluginModule interface into an API jar that I've put into shared/libs too, but I faced the same issue.

I've also tried to put my plugin into an external folder and to set it in the CLASSPATH with a setenv.sh script, but no success.

This looks like a good use case for OSGi unfortunately I cannot (for now) modify the app to make it OSGi ready.

How could I drop some plugin jars somewhere and make them easily loaded by the webapp with a ServiceLoader? I can put them in the webapp/WEB-INF/lib folder and it works, but each re-deploy will remove them and I would ideally like to avoid to have to redeploy the plugin.

Community
  • 1
  • 1

0 Answers0