But one thing which will be common in all these individual applications would be the application header (i'm not talking about http headers) which shows the page navigation. This header can have multi-level navigation structure. When user click on say Billing tab which is deployed in different app server instance, the request goes to that new server, new session gets created and page will be rendered with its own headers. The look n feel of this Billing page header would be kept same as Overview page, to make this transition unnoticeable to user.
For the above purpose, the developers end up in implementing the same header code in all the projects (each application instance), which has the following concerns:
- Changes to the headers in project has to manually merged into other project header codes also. Which is cumbersome or possibility of forgetting.
We have Maven Overlay to rescue us here.
- The main projects (Overview, Billing etc) doesnt have to have any header code.
- All the header codes are under single project, so either code or code changes does not have to be replicated.
- Compiled once, copied to other projects, means quicker builds.
The same concept can be applied to Footers. For that matter, this can be used in any functionality of the app which remains same in multiple domains.
Enough of theory right, now let us get our hands dirty:
Here is the CommonHeaderProject structure.
This projects contains all the header n footer jsps. Here i used Navigation.xml to define the navigation structure and using XSL to render the html header.
Now let us have a look at the maven pom.xml for this CommonHeaderProject.
Note that this project is built as War.
Here is the pom.xml excerpt from one of the main projects (OverviewWeb).
The overlay tag above instructs maven build to look for project mybiz-header dependency for the given groupId. Maven overlay provides us the option to include and exclude files.
When OverviewWeb is built using maven, maven bring the included files from mybiz-header war and copies them into the OverviewWeb target. Maven retains the same package structure for the files brought.
Here is the OverviewWeb target after maven build. You may see the files from CommonHeaderProject are copied to this target.
Similarly for other projects to use the same header, just have to add overlays to their pom. Thats it, as simple as that.