maven-assembly-plugin

assembly是把一組文件、目錄、依賴元素組裝成一個歸檔文件. 比如, 假設一個 Maven project定義了一個JAR artifact,它包含控制臺應用程序和Swing應用程序 。這樣一個工程可以定義兩套包含描述符,一套給控制臺應用,另一套給Swing應用程序,它們包含各自的腳本、目錄和依賴。
Assembly Plugin的描述符可以定義任何一個文件或者目錄歸檔方式。舉個例子,如果的你的Maven 2工程包含”src/main/bin”這個目錄,你可以指示Assembly插件復制“src/main/bin”目錄下所有的文件到bin目錄里(歸檔文件里的目錄),并且可以修改它們的權限屬性(UNIX mode)。

Pom 配置

   <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptor>src/main/assembly/assembly.xml</descriptor><!--描述文件路徑-->  
                </configuration>
                <executions> 
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase> <!-- 綁定到package生命周期階段上 -->    
                        <goals>
                            <goal>single</goal><!-- 只運行一次 -->  
                        </goals>
                    </execution>
                </executions>
            </plugin>

assembly.xml

<assembly  
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">  
    <id>release</id>  
    <formats>  
        <format>zip</format>  
    </formats>  
    <fileSets>  
        <fileSet>  
            <directory>${project.basedir}\src\main\config</directory>  
            <!-- 過濾 -->  
            <excludes>  
                <exclude>*.xml</exclude>  
            </excludes>  
            <outputDirectory>\</outputDirectory>  
        </fileSet>  
    </fileSets>  
      
    <dependencySets>  
        <dependencySet>  
            <useProjectArtifact>true</useProjectArtifact>  
            <outputDirectory>lib</outputDirectory><!-- 將scope為runtime的依賴包打包到lib目錄下。 -->  
            <scope>runtime</scope>  
        </dependencySet>  
    </dependencySets>  
</assembly>  

打包的文件格式
可以有:tar.zip war zip
<formats>
<format>zip</format>
</formats>

需要打包的路徑
<directory>${project.basedir}</directory>

打包后輸出的路徑
<outputDirectory>/</outputDirectory>

打包需要包含的文件
<excludes>
<exclude>junit:junit</exclude>
<exclude>commons-lang:commons-lang</exclude>
<exclude>commons-logging:commons-logging</exclude>
</excludes>

當前項目構件是否包含在這個依賴集合里。
<useProjectArtifact>true</useProjectArtifact>

依賴包打包到目錄下
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>runtime</scope>
</dependencySet>
</dependencySets>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容