Maven: Customize web.xml of web-app project

前端 未结 7 2058
梦如初夏
梦如初夏 2020-11-30 20:27

I have a web application Maven project, and I want to customize the web.xml file depending on the Profile that is running. I am using the Maven-War-plugin, which allows me

7条回答
  •  天涯浪人
    2020-11-30 21:27

    is there a way to have two web.xml files and select the appropriate one depending on the profile?

    Yes, within each profile you can add a configuration of the maven-war-plugin and configure each to point at a different web.xml.

    
        
            profile1
            
                
                    
                        org.apache.maven.plugins
                        maven-war-plugin
                        
                            /path/to/webXml1
                        
                    
                     ...
    

    As an alternative to having to specify the maven-war-plugin configuration in each profile, you can supply a default configuration in the main section of the POM and then just override it for specific profiles.

    Or to be even simpler, in the main of your POM, use a property to refer to the webXml attribute and then just change it's value in different profiles

    
        path/to/default/webXml
    
    
        
            profile1
            
                path/to/custom/webXml
            
        
    
    
        
            
                org.apache.maven.plugins
                maven-war-plugin
                
                    ${webXmlPath}
                
            
            ...
    

提交回复
热议问题