美文网首页
maven-assembly-plugin 插件多模块打包实例

maven-assembly-plugin 插件多模块打包实例

作者: 达微 | 来源:发表于2020-03-05 16:46 被阅读0次

    1,项目结构:
    父工程:hdpetl

    子模块:assembly,genhttp,telecomdata

    文件(夹):logs文件夹,README.txt文件

    如下:

    其中assembly 是用来打包的模块,没有任何代码,就两个文件。其他模块为正常业务数据模块

    2,pom文件
    hdpetl.pom

    <modules>
        <module>genhttp</module>
        <module>telecomdata</module>
        <module>assembly</module> <!--打包模块排在最后-->
    </modules>
    

    。。。正常dependency依赖略。。。

    <!--assembly-->
    
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <finalName>hdpetl-${project.version}</finalName>
                        <descriptors>
                            <descriptor>assembly/assembly.xml</descriptor>
                        </descriptors>
                        <outputDirectory>d://</outputDirectory>
                        <appendAssemblyId>true</appendAssemblyId>
    
                    </configuration>
                </plugin>
    

    assembly.pom,注意依赖其他两个业务模块

    <dependencies>
        <dependency>
            <groupId>www.abc.net.cn</groupId>
            <artifactId>genhttp</artifactId>
            <version>5.0</version>
        </dependency>
        <dependency>
            <groupId>www.abc.net.cn</groupId>
            <artifactId>telecomdata</artifactId>
            <version>5.0</version>
        </dependency>
    </dependencies>
    


    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.6</version>
    <executions>
    <execution>
    <phase>package</phase>
    <goals>
    <goal>single</goal>
    </goals>

                        </execution>
                    </executions>
                    <configuration>
                        <descriptors>
                            <descriptor>assembly.xml</descriptor>
                        </descriptors>
                    </configuration>
                </plugin>
    

    其他两个业务模块telecomdata和genhttp pom文件正常有自己特有的dependency,其他无特殊标签依赖等

    assembly.xml

    <?xml version='1.0' encoding='UTF-8'?>
    <assembly xmlns="http://maven.apache.org/ASSEMBLY/1.1.3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/1.1.3
    http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>assembly</id>
    <baseDirectory>hdpetl-${project.version}</baseDirectory>
    <formats>
    <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>../genhttp/target</directory>
            <outputDirectory>jar</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>../telecomdata/target</directory>
            <outputDirectory>jar</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>../genhttp/src/main/conf</directory>
            <outputDirectory>conf</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>../genhttp/src/main/shell</directory>
            <outputDirectory>shell</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>../logs</directory>
            <outputDirectory>logs</outputDirectory>
        </fileSet>
    
        <fileSet>
            <includes>
                <include>../README.txt</include>
            </includes>
            <outputDirectory></outputDirectory>
        </fileSet>
    </fileSets>
    
    
    <!--依赖打包-->
    <dependencySets>
        <dependencySet>
            <unpack>false</unpack>
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <scope>provided</scope>
        </dependencySet>
        <dependencySet>
            <unpack>false</unpack>
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <scope>system</scope>
        </dependencySet>
        <dependencySet>
            <unpack>false</unpack>
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
    
    <moduleSets>
        <moduleSet>
            <useAllReactorProjects>true</useAllReactorProjects>
            <includes>
                <include>hdpetl:genhttp</include>
                <include>hdpetl:telecomdata</include>
            </includes>
    
        </moduleSet>
    </moduleSets>
    

    </assembly>

    执行命令:

    mvn -X clean package assembly:single

    即在 d盘根目录下生成 hdpetl-5.0-assembly.tar.gz 文件

    解压:

    两个业务模块已经打包jar文件到jar中

    父工程的公共依赖和子模块的依赖,上述两个子模块的jar包一起在lib文件夹中

    其他文件正常按配置打包到相应的文件夹中

    ————————————————
    版权声明:本文为CSDN博主「liang家之言」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/xiaoxiaojavacsdn/article/details/89574581

    相关文章

      网友评论

          本文标题:maven-assembly-plugin 插件多模块打包实例

          本文链接:https://www.haomeiwen.com/subject/cdhqrhtx.html