Files got overwritten in maven project when building a war

后端 未结 4 1784
时光取名叫无心
时光取名叫无心 2020-12-04 02:20

I\'m building a web application project using maven, and packaging is set to \"war\". I also use YUI compressor plugin to compress javascript codes in the webapp directory.

4条回答
  •  悲哀的现实
    2020-12-04 02:40

    As you noticed, the /src/main/webapp dir (aka warSourceDirectory) contents is not copied into the project dir for packaging until the war plugin executes during the package phase. When the war plugin completes the archive is already built; too late to modify those resources. If the .js files you want to compress were moved into another directory (outside of /src/main/webapp) then you could do something like the below.

    To test, I created a ${basedir}/src/play directory with a couple of files in it. I used the resource plugin for the example; you'd replace that config with the YUI compressor plugin config you needed and simply add the element to your war plugin config as shown below; more info in the war plugin examples. My war ended up with the additional files right where I wanted them.

    
      org.apache.maven.plugins
      maven-resources-plugin
      
        
          copy-resources
          process-resources
          copy-resources
          
            ${project.build.directory}/tmpPlay
            
              
                 ${project.basedir}/src/play
                 
                    **/*
                 
              
            
           
        
      
    
    
    
      org.apache.maven.plugins
      maven-war-plugin
      
        
          default-war
          
            
              
                ${project.build.directory}/tmpPlay
                WEB-INF/yourLocationHere
                
                  **/*
                
              
            
          
        
      
    
    

提交回复
热议问题