Maven String Replace of Text Web Resources

后端 未结 5 1109
萌比男神i
萌比男神i 2021-02-07 07:38

I have a Maven web application with text files in

src/main/webapp/textfilesdir

As I understand it, during the package phase this te

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 08:33

    You can use maven-replacer-plugin:

    
           com.google.code.maven-replacer-plugin
           maven-replacer-plugin
           1.3.7
           
               
                   prepare-package
                   
                       replace
                                      
               
           
           
               target/${project.artifactId}-${project.version}/WEB-IN/site.xml
               
                   
                       ear.version
                       ${ear.version}-${maven.build.timestamp}
                            
               
           
       
    

    But you need two more tricks. One is adding the explode goal to the war plugin:

    
        org.apache.maven.plugins
        maven-war-plugin
        2.1.1
            .....
            
            
            prepare-package
                
                     exploded
                 
             
        
    
    

    And finally to need to call mvn clean before the package. You can do it from your pom:

                       
                        maven-clean-plugin
                        2.4.1
                        
                          
                            auto-clean
                            initialize
                            
                              clean
                            
                          
                        
                
    

    If you are using a version of the maven-war-plugin newer than 2.0.1, you will need to include true in the configuration of the maven-war-plugin, otherwise the changes to your file(s) will be splotted when the war plugin copies your webapp over a second time. If you are using Hudson/Jenkins, you will have to use a version newer than 2.0.1.

提交回复
热议问题