解压缩程序集并将其复制到给定文件夹的快捷方式?

时间:2013-01-18 21:37:20

标签: maven maven-assembly-plugin

我有一个相当简单的Maven程序集,我想将其部署到文件系统上的文件夹中。我绝对可以使用提取命令链接我的Maven构建,但有没有办法在Maven中通过传递文件部署位置的属性来执行以下操作?

mvn install && tar -C /my/deployment/folder xvzf target/${project.artifactId}-${project.version}-default.tar.gz ${project.artifactId}-${project.version}-default/

有没有办法可以为Maven提供一些配置,所以我可以这样做:

mvn install deploy -DdeploymentDir=/my/deployment/folder

1 个答案:

答案 0 :(得分:0)

使用dir <format>dir</format>获取解压后的目录

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptors>
                    <descriptor>path/to/assembly.xml</descriptor>
                </descriptors>
            </configuration>
        </plugin>

assembly.xml

    <?xml version="1.0" encoding="GBK"?>
    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1">
        <id></id>
        <baseDirectory>${project.artifactId}-${project.version}-default/</baseDirectory>
        <formats>
            <format>dir</format>
        </formats>

        <fileSets>
            <fileSet>
                <directory>../../path/to/${project.artifactId}-${project.version}-default/</directory>
                <outputDirectory></outputDirectory>
                <includes>
                    <include>**/**</include>
                </includes>
            </fileSet>
        </fileSets>
    </assembly>

使用antrun复制到dest目录

    <plugin>   
       <artifactId>maven-antrun-plugin</artifactId>    
         <executions>     
        <execution>
        <phase> ... choose after assembly </phase>        
               <goals>            
                     <goal>run</goal>        
               </goals>             
               <configuration>       
                     <tasks>          
                         <copy todir="/tmp/xx" >        
                        <fileset dir="target/${project.build.finalName}"/>
                </copy>
                     </tasks>          
               </configuration>        
        </execution>    
         </executions>  
    </plugin>