Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I will try to explain my question with an example. Let us say that we are writin

ID: 652347 • Letter: I

Question

I will try to explain my question with an example. Let us say that we are writing a hotel reservation system which is web based using Java. We will have different payment methods, say Paypal, Master Card and Visa Card. Different customers of our product will use different payment methods only. (Hotel XYZ, who is our customer, will only want to use Paypal and hotel ABC will only want to show the Master Card and Visa options).

In this kind of scenario, the normal way of doing things would be to have the different payment methods as plugins. And install only the needed plugins in a customer environment.

My question is, how to achieve this in a web application? From my understanding, the folder structure for a Java web application is as shown here. But if we have pluggable payment methods, the plugins themselves should be able to register the user interface components rather than having them in the main application. (For example let us say there is master_card.jsp file which handles the master card payments and visa.jsp etc..). With the above linked kind of folder structure, it seems to me that we would have to put in those jsp files in the webapp even though some customers might not need it.

Can someone please let me know whether

if my above observation is correct
how to have above kind of plugin structure with Java/Java EE?
are there any frameworks in Java that supports above kind of thing?

Explanation / Answer

if my above observation is correct

It depends. You may as well include everything in distribution and only configure each installation to use what it needs. Possible reasons for going with plugins are:

You charge your plugins separately and don't want to give away features for free
Your plugins are "heavy" in some way, e.g. there are lots of them or they have a significant size.
If those reasons do not apply to your case, you may think of a simpler solution.

how to have above kind of plugin structure with Java/Java EE?

If you're OK with rolling your own simplest solution, here is the general scheme:

In app's configuration (which can be *.properties file or a record in DB, whichever works better for your users, because they should be able to change it), add a property which contains a path to plugins directory
Define and expose plugin API - a set of interfaces which a plugin must implement to allow application to invoke this plugin
Write custom ClassLoader which uses the property from #1 and maybe checks if each plugin properly implements your API
Load your plugins' classes and resources using this class loader
Invoke plugins' functions via interfaces of plugin API or, if plugin consists of resources only, include those as needed
are there any frameworks in Java that supports above kind of thing?

Yes. Googling for "java plugin framework" reveals some.