[Maven] maven-assembly-plugin package a variety of styles

http://maven.apache.org/plugins/maven-assembly-plugin/

Production projects bundle, the bundle may contain executable project file, source code, readme, scripting platform and so on. maven-assembly-plugin supports all major formats such as zip, tar.gz, jar and the like war

Support for custom packaging structure, dependencies, etc. can also be customized.

  • maven-jar-plugin, the default packing plug, used to play conventional project JAR package;
  • maven-shade-plugin, to play an executable JAR package, the so-called FAT JAR package;
  • maven-assembly-plugin, support for custom packaging structure, dependencies, etc. can also be customized.
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>${maven-assembly-plugin.version}<version>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- 绑定到package生命周期 -->
                        <Phase > Package </ Phase > 
                        < Goals > 
                            <-! run only once -> 
                            < Goal > SINGLE </ Goal > 
                        </ Goals > 
                    </ Execution > 
                </ Executions > 
                < Configuration > 
                    <-! deployment descriptor file -> 
                    < descriptor > the src / main / Assembly / assembly.xml </ descriptor > 
                    <-! You can also use a pre-configured Maven descriptor
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs> -->
                </configuration>
            </plugin>
        </plugins>
    </build>

a packaging assembly via plug-in descriptor (descriptor) defined.
Maven predefined descriptor has bin, src, project, jar- with-dependencies and the like. More commonly used is jar-with-dependencies, which is all the external dependencies are added to the resulting JAR JAR package, fool comparison.
But to really achieve the effect of a custom package, you need to write your own descriptor file format is XML.

The following is a configuration commonly used in our project.

<assembly>
    <id>assembly</id>

    <formats>
        <format>tar.gz</format>
    </formats>

    <includeBaseDirectory>true</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>src/main/bin</directory>
            <includes>
                <include>*.sh</include>
            </includes>
            <outputDirectory>bin</outputDirectory>
            <fileMode>0755</fileMode>
        </fileSet>
        <fileSet>
            <directory>src/main/conf</directory>
            <outputDirectory>conf</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>src/main/sql</directory>
            <includes>
                <include>*.sql</include>
            </includes>
            <outputDirectory>sql</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>target/classes/</directory>
            <includes>
                <include>*.properties</include>
                <include>*.xml</include>
                <include>*.txt</include>
            </includes>
            <outputDirectory>conf</outputDirectory>
        </fileSet>
    </fileSets>

    <files>
        <file>
            <source>target/${project.artifactId}-${project.version}.jar</source>
            <outputDirectory>.</outputDirectory>
        </file>
    </files>

    <dependencySets>
        <dependencySet>
            <unpack>false</unpack>
            <scope>runtime</scope>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

 

Guess you like

Origin www.cnblogs.com/clarino/p/12089237.html