How to copy a resource or another in Maven depending on the target environment?

后端 未结 5 1203
有刺的猬
有刺的猬 2020-12-07 15:19

I have to create test war and production war, which will have a different log4j.properties file in the WEB-INF directory. I have these files

5条回答
  •  甜味超标
    2020-12-07 15:39

    The alternative way is to use maven-antrun-plugin

    
        
            
              org.apache.maven.plugins
              maven-antrun-plugin
              1.7
              
                
                  validate
                  
                    run
                  
                  
                    
                      build.env: ${build.env} 
                      
                      
                    
                  
                
              
            
        
    
    

    Assume resource files are in following structure:

    src/
      env/
          dev/
              log4j.properties
          local/
              log4j.properties
          prod/
              log4j.properties
    

    When do maven build, run the following commands per environment:

    mvn package -Dbuild.env=dev
    mvn package -Dbuild.env=local
    mvn package -Dbuild.env=prod
    

提交回复
热议问题