Maven: Customize web.xml of web-app project

前端 未结 7 2047
梦如初夏
梦如初夏 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:20

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

    Other than the approach suggested by matt b, it is useful to think it the other way around, mainly because in many cases you will have to bundle application server specific configurations that are not covered by the maven plugins (afaik). These may very well have differences between profiles.

    Specifically, you can use a parent project that has all the common files between web projects of different profiles. Then child projects can have different web.xml files and the rest id done with profiles and the maven-war-plugin. For example, I have used this layout to achieve unattended builds (other than specifying a profile) for different target environments (development, uat etc.)

    WebPc
    ├── common
    │   ├── css
    │   ├── images
    │   ├── js
    │   └── WEB-INF
    │   └──├── wsdl
    │── pom.xml
    │
    ├── WebPc-DEV
    │   ├── pom.xml
    │   └── src
    │       └── main
    │           └── webapp
    │               └── WEB-INF
    │                   ├── geronimo-web.xml
    │                   ├── ibm-web-bnd.xml
    │                   ├── ibm-web-ext.xml
    │                   └── web.xml
    ├── WebPc-UAT
    │   ├── pom.xml
    │   └── src
    │       └── main
    │           └── webapp
    │               └── WEB-INF
    │                   ├── geronimo-web.xml
    │                   ├── ibm-web-bnd.xml
    │                   ├── ibm-web-ext.xml
    │                   └── web.xml
    

    The pom of WebPc has the following pom

    my.grp
    WebPc
    pom
    
    
        
            DEV
            
                true
            
            
                WebPc-DEV
            
        
        
            UAT
            
                WebPc-UAT
            
        
    
    
    
        
            
    
                
                
                    org.apache.maven.plugins
                    maven-war-plugin
                    2.4
                    
                        ${project.build.sourceEncoding}
                        
                            
                                ../common
                                
                                    WEB-INF/**
                                
                            
                            
                                ../common/WEB-INF
                                
                                    wsdl/*.wsdl
                                    wsdl/*.xsd
                                
                                WEB-INF
                            
                        
                    
                
    
            
        
    
    

    And this is the pom for WebPc-DEV

    
        my.grp
        WebPc
        1.0.0-SNAPSHOT
    
    
    WebPc-DEV
    war
    
        
            
                org.apache.maven.plugins
                maven-war-plugin
            
        
    
    

提交回复
热议问题