Search code examples
mavenmaven-war-pluginoverlays

Is it possible to merge 2 web.xml with Maven overlay


I have a web application 'A' defined in a war project. I created an other web application 'B' that import the whole content of 'A' with an overlay.

The file web.xml of application 'B' is the same of application 'A', except for additionnal listeners. Therefore the web.xml of B contains lot of duplicated content with A.

The question is : is it possible to tell maven-war-plugin to merge web.xml of A and B, instead of replacing web.xml of A by web.xml of B ?


Solution

  • In your case - additional listeners - there is simple solution. If your application is Servlet 3.0 or higher, you can register B listeners with annotation:

    @WebListener
    public class BListener implements ServletContextListener {
    
        public void contextInitialized(ServletContextEvent sce) {
            System.out.println("Started BListener");
        }
    

    If impact of B is more complex than extra listener, you may consider web-fragment (requires Servlet 3.0)