3 Replies Latest reply on Apr 12, 2017 9:43 AM by Klaifer Garcia

    Class-loading issue with Java Service Provider Interface and different deployments

    I K Newbie

      Hi,

       

      I am struggling with the use of Java SPI for implementing a plugin-based web app. The plugins - which all implement a common service interface - shall be deployed as separate WAR files (EAR is also ok) on the Wildfly server. The plugins shall then looked up by the core component of the web app using the Java Service Provider interface (i.e. ServiceLoader.load(...)).

       

      The Plugin WAR files are all structured as follows:

       

      WEB-INF\classes\.... the classes of the plugin implementation

      WEB-INF\classes\META-INF\services\my.plugin.IPluginFactory.... which references the factory in the classes directory

      META-INF\MANIFEST.MF .... containing dependency information as follows

       

      ...

      Dependencies: deployment.pluginA-0.0.1-SNAPSHOT.war export services, deployment.pluginAPI-0.0.1-SNAPSHOT.war

      ...

      In my opinion this should be sufficient to import the pluginAPI WAR (contains all interface classes that have to be implemented by a plugin) and export its own implementation and service definition. However, when I do a lookup of in my core compoenent's WAR I do not find any implementations of the IPluginFactory interface. The implementation and the service file shall be fine since when I just copy them from the plugin WAR to my core WAR everything works fine. So I think this is just a class-loading issue.

       

      • Exporting the implementation as service shall be sufficient for other modules to find and import it - or do I have to do something else?
      • Are there any other means for implementing such a plugin concept on Wildfly where I can add and remove implementations of a certain interface at runtime?
      • How can I debug these class loading issues?

       

      Any ideas?

      Thanks