How to call an external class from a webapp (i.e. – implement a plugin)

I would like my webapp to call an external class, which will be provided (as a name) in an XML file at run time. The external class will be developed by 3rd party, and might include additional JARs. I will refer to the external class and JARs as the “plugin”. My webapp is provided as a WAR, so it is not possible to add the plugin into the same WAR (unless the customer performs it himself). I do not want to put the plugin’s JARs in the common lib of Tomcat, so that it will not affect other webapps (the plugin might include JARs of different versions than the webapps use). I considered putting the plugin in a separate folder, and implement my own class loader that will look at that folder as well. It seems like too much of an effort for a simple task. What is the recommended way to achieve “plugin” capabilities for a webapp? Thanks G.

Leave a comment

2 Comments.

  1. There are 2 issues (not in order of priority): 1. The steps are not straight forward, and may cause the system to stop working (the customer should change the WAR suffix to “zip”, open it, add the files and rename it back) 2. When we provide a new version, we will replace the WAR and all the changes are gone.

    Aren’t there other webapps that have plugin capabilities? How do they implement this capability?

    Thanks G.

  2. so the basic idea is: 1. Define an interface (WSDL or named parameters for a “post” message) 2. Enable specifying the URL of the plugin in the context of the webapp 3. As part of the flow, call that URL with the defined format

    Did I follow your thought?

    It seems like an overhead in terms of performance, but if there is no other possibility – this is what we shall do. Thanks

Leave a Reply