assembly打包

assembly打包

1 springboot项目 -> 子项目assembly

assembly子项目是微服务中的子项目,专门用来打包的

1.1 springboot项目 -> 子项目assembly -> pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
   <!-- 父级项目 -->
    <parent>
        <groupId>sac-plugin-platform</groupId> <!-- 父级项目-->
        <artifactId>com.cenmingzhong.test</artifactId>
        <version>1.5.7.RELEASE</version>
    </parent>

    <!-- pom模型版本 -->
    <modelVersion>4.0.0</modelVersion>
    
    <artifactId>assembly</artifactId><!-- 项目名 -->
    
    <!-- 属性设置 -->
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    
    <!-- 编译 -->
    <build>
        <!-- 插件 -->
        <plugins>
            <!-- maven插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>${parent.artifactId}</finalName>
                            <descriptors>
                                <descriptor>src/main/resources/assembley/assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

1.2 springboot项目 -> 子项目assembly -> assembly.xml文件

该配置作为maven-assembly-plugin插件的打包配置文件

<?xml version='1.0' encoding='UTF-8'?>
<assembly>
    <id>${parent.version}</id>
    <baseDirectory>${project.artifactId}</baseDirectory>
    <includeBaseDirectory>true</includeBaseDirectory>
    <formats>
        <format>tar.gz</format> <!-- 打包的文件格式:zip、tar、tar.gz、tar.bz2、jar、war等-->
    </formats>
    <moduleSets>
        <moduleSet>
            <includes>
                <!-- 包含的子项目-->
                <include>com.cenmingzhong.test:boot</include> 
            </includes>
        </moduleSet>
    </moduleSets>
     <!-- 用来设置一组文件在打包时的属性-->
    <fileSets>
        <!-- 设置jar-->
        <fileSet>            
            <directory>../boot/target</directory> <!-- 源目录的路径-->
            <outputDirectory>target</outputDirectory>  <!-- 生成目录的路径--> 
            <!-- 设定包含哪些文件,支持通配符-->
            <includes>
                <include>boot.jar</include>
            </includes>
        </fileSet>
         <!-- 设置lib-->
         <fileSet>
            <directory>../boot/target/lib</directory> <!-- 源目录的路径-->
            <outputDirectory>lib</outputDirectory>  <!-- 生成目录的路径--> 
            <!-- 设定包含哪些文件,支持通配符-->
            <includes>
                <include>*.jar</include>	
            </includes>
        </fileSet>
         <!-- 设置bin-->
         <fileSet>
            <directory>src/main/resources</directory> <!-- 源目录的路径-->
            <outputDirectory>/</outputDirectory>  <!-- 生成目录的路径--> 
            <!-- 设定包含哪些文件,支持通配符-->
            <includes>
                <include>/bin/*.sh</include>
            </includes>
            <!-- 设定排除哪些文件,支持通配符-->
            <excludes>
                <exclude>joke.sh</exclude>
            </excludes>
            <fileMode>0755</fileMode>  <!-- 指定该目录下的文件属性,采用Unix八进制描述法,默认值是0644,设置文件权限-->
        </fileSet>
         <!-- 设置conf-->
         <fileSet>
            <directory>../boot/src/main/resource</directory> <!-- 源目录的路径-->
            <outputDirectory>conf</outputDirectory>  <!-- 生成目录的路径--> 
            <!-- 设定包含哪些文件,支持通配符-->
            <includes>
                <include>boot.yml</include>	
            </includes>
        </fileSet>    
    </fileSets>
</assembly>

2 springboot项目 -> 子项目boot

boot子项目是其中一个微服务

2.1 springboot项目 -> 子项目boot -> pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
   <!-- 父级项目 -->
    <parent>
        <groupId>sac-plugin-platform</groupId> <!-- 父级项目-->
        <artifactId>com.cenmingzhong.test</artifactId>
        <version>1.5.7.RELEASE</version>
    </parent>

    <!-- pom模型版本 -->
    <modelVersion>4.0.0</modelVersion>
    
    <artifactId>boot</artifactId><!-- 项目名 -->
    
    <!-- 属性设置 -->
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <!-- 依赖关系 -->
    <dependencies>
        <!-- 测试 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- springmvc -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- jpa(持久层) -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- mysql(数据库) -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    
    <!-- 编译 -->
    <build>
        <finalName>${project.artifactId}</finalName>
        <!-- 插件 -->
        <plugins>
            <!-- maven插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>../lib</classpathPrefix>
                            <!-- 此处修改为应用入口类全路径 -->
                            <mainClass>com.cenmingzhong.test.boot.BootBootStrap</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <!-- 这个插件用来把依赖的jar包复制出来放在编译后的target/lib目录,并且在打包的时候排除内部依赖 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases> <!-- 释放检查 overWriteReleases 值(默认值=假)。如果为真,则将强制覆盖-->
                            <overWriteSnapshots>false</overWriteSnapshots><!-- 快照检查 overWriteSnapshots 值(默认值=假)。如果为真,则将强制覆盖-->
                            <overWriteIfNewer>true</overWriteIfNewer><!-- 如果上面的任何一个都不设置为true,则默认为 overWriteIfNewer 值(默认值=真)。如果该值为真,则仅当源比目标更新(或目标中不存在)时,才会复制该插件-->
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plgin>
                <!-- 这个插件用来生成smart-doc文档 -->
                <groupId>com.github.shalousun</groupId>
                <artifactId>smart-doc-maven-plugin</artifactId>
                <version>${smart-doc-version}</version> <!-- 版本号定义在父级pom.xml中-->
                <configuration>
                    <!-- 指定生成文档的使用的配置文件,配置文件放在自己的子项目中-->
                    <configFile>./src/main/resources/smart-doc.json</configFile>
                    <!-- 指定项目名称-->
                    <projectName>主程序</projectName>
                    <excludes>
                         <!-- 格式为:groupId:artifactId-->
                        <exclude>com.alibaba:fastjson</exclude>
                    </excludes>
                    <includes>
                         <!-- 格式为:groupId:artifactId-->
                        <include>com.alibaba.fastjson</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase><!-- 如果不需要在执行编译时启动smart-doc,则将phase注释掉-->
                        <goals>
                            <goal>html</goal><!-- smart-doc提供了html、openapi、markdown等goal,可按需配置-->
                        </goals>
                    </execution>
                </excutions>
            </plgin>
        </plugins>
    </build>
</project>

2.2springboot项目 -> 子项目boot -> smart-doc.json文件

这个文件用来配置smart-doc插件文档输出内容的

{
    "projectName": "boot",
    "isStrict": false,
    "outPath": "D://smart-doc" #文档输出路径
    "apiConstants":[{
    "constantsClassName": "com.cenmingzhong.test.boot.Api" #项目中的接口类
}]
}

3 springboot项目 -> 父项目parent

3.1springboot项目 -> 父项目parent->pom.xml文件

这个文件是微服务的父级项目的pom.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
    <groupId>sac-plugin-platform</groupId>
    <artifactId>com.cenmingzhong.test</artifactId><!-- 项目名 -->
    <version>1.5.7.RELEASE</version>
    <!-- pom模型版本 -->
    <modelVersion>4.0.0</modelVersion>
    
    <!-- 子项目 -->     
    <modules>
        <module>boot</module>
    </modules>
    
    <!-- 打包方式,微服务父级项目用pom, 指定packing打包类型,maven插件可以自动加载并继承父pom相关配置 -->  
    <packaging>pom</packaging>
    
    <!-- 属性设置 -->
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <smart-doc-version>2.1.9</smart-doc-version> <!-- 配置子项目用到的依赖的版本,如果子项目没有指定版本,则使用父级项目的版本 -->
    </properties>

    <!-- 依赖关系 -->
    <dependencies>
        <!-- 测试 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- springmvc -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- jpa(持久层) -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- mysql(数据库) -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    
    <!-- 编译 -->
    <build>
        <finalName>${project.artifactId}</finalName>
        <!-- 插件 -->
        <plugins>
            <!-- maven插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.8</source> <!-- maven-compiler-plugin父pom中的默认配置如果不符合现有项目要求则要重新设置来覆盖,建议重新配置-->
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <!-- maven-surefire-plugin是maven里执行测试用例的插件,不显示配置就会用默认配置。这个插件的surefire:test命令会默认绑定maven执行的test阶段 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <skipTests>true</skipTests>  <!-- 跳过测试 -->
                </configuration>
            </plugin>
        </plugins>
        <!-- 资源目录 可以将除了resources目录下面的文件打进包里,例如写在src/main/java里面的xml文件,可以打进resources里面,该配置实际上是作用在maven-resources-plugin插件 -->    
        <resources>
            <resource>
                <directory>src/main/java</directory><!-- 设定主资源目录  --> 
                <!-- maven default生命周期,process-resources阶段执行maven-resources-plugin插件的resources目标处理主资源目下的资源文件时,只处理如下配置中包含的资源类型 --> 
                <includes>	
                    <include>**/*.dic</include> <!-- **/*这样的写法,是为了保证各级子目录下的资源文件被打包-->
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                    <include>**/*.sql</include>
                    <include>**/*.key</include>
                </includes>
                <excludes>
                    <exclude>**/*.joke</exclude> <!--过滤joke文件-->
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>
</project>
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值