I mainly develop a big Web project with Java, Mave开发者_StackOverflown, and Spring. However, there are different flavors of the Web project that are created for specific customer needs. For instance, if one customer wants a Twitter page, but another does not, I need to be able to build a flavor of that Web project with or without that Twitter page.
I have been looking into Maven overlays and OSGi as two options. Maven overlays tend to take a long time to build when copying resources from the base overlay. I was looking at Spring OSGi Web as an option because they seem to be on the right track for modularizing small chuncks (controllers, views, JS/resources/images) for Web projects.
Is OSGi overkill? Is it what I need to use? Is there something better?
OSGI is great if you need to add/remove unforeseen features (and code) at runtime (and not just enable or disable it), but most time this is not needed for web apps.
So in your case I would recommend to use a configuration (file) to enable or disable features as long as this is possible. This also have the advantage, that you need only one WAR.
To handle the problem of: "how to put the configuration file in the WAR", you have several ways ( Different files to be packaged in a Maven war project ):
- use maven environements - (ok then you have several WARs, but the only differn in the config file, and the Build Process becomes not so slow, because only the WAR packaging process is done for each environment)
- store the configuration outside of the WAR
- store the configuration outside of the WAR for example in a Database
You might be interested in Spring Slices. It basically allows you to have fragments of a web application deployed as individual bundles. Depending upon the complexity of your overall offering this may be desirable.
I've not looked at it seriously for a while, so I'm not too sure of it's current status, though I expect it's improved greatly since I last looked.
Anyone with more up to date info please feel free to add links.
http://blog.springsource.com/2009/08/07/slices-menu-bar-screencast/
Matt, as a rule of thumb, try to have only one version of your application and try to manage it with configuration properties. Imagine what happens when you have 10 clients and each one has a couple of features, but not two clients have the same set of features.
https://github.com/griddynamics/banshun which is osgi-less modularity for Spring supports two notions of customization. It can pickup and instantiate modules (children contexts) by wildcard that's called build time customization, implying that maven profile put necessary overlays in WAR. An opposite way is runtime customizatoin, when necessary modules are defined in according to a property.
精彩评论