Maven 打包(system jar 和微服务父子项目)

jar包使用system

请务必减少使用system的频率,除非这个jar包中央仓库中没有

在文末的build标签下写入

< includeSystemScope >true</ includeSystemScope>即可

bash 复制代码
<?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>
        <artifactId>nxin</artifactId>
        <groupId>com.nxin.framework</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>worker</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencies>
     。。。。。。。。
     </dependencies>
   
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

微服务父子项目

父项目pom文件

父项目pom文件编写格式如下所示,打包后,不需要父项目的jar,因此设置 < packaging>pom</ packaging>

bash 复制代码
<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.wunaiieq</groupId>
    <artifactId>wunaiieq</artifactId>
    <version>1.0-SNAPSHOT</version>
    <modules>
    <!--子项目1-->
        <module>web-server</module>
<!--子项目2-->
        <module>worker</module>
        <!--部分私有的jar库,maven仓库中没有-->
        <module>libs</module>
    </modules>
    <packaging>pom</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/>
    </parent>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
</project>

子项目pom文件

两个子项目类似,需要如下关键代码
关键代码

bash 复制代码
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>

完整子项目pom文件

bash 复制代码
<?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>
        <artifactId>wunaiieq</artifactId>
        <groupId>com.wunaiieq</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>worker</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
 。。。。。。。。。。
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
相关推荐
winfield8211 天前
关于工程实践的面试问题
微服务·面试
invicinble1 天前
jar包在执行的时候需要关注的细节(提供一个解构jvm问题的视角)
java·jvm·jar
浙江第二深情1 天前
前端性能优化终极指南
java·maven
元Y亨H1 天前
【深度解析】Seata 分布式事务:核心作用、原理与实战配置指南
spring cloud·微服务
pengkai火火火1 天前
基于springmvc拓展机制的高性能日志审计框架的设计与实现
spring boot·安全·微服务·架构
拾忆,想起1 天前
设计模式:软件开发的可复用武功秘籍
开发语言·python·算法·微服务·设计模式·性能优化·服务发现
降临-max1 天前
JavaWeb企业级开发---Ajax、
java·ajax·maven
何包蛋H1 天前
Docker Maven 插件深度配置指南:Spotify vs Fabric8
docker·容器·maven
DKunYu1 天前
5.优雅实现远程调用-OpenFeign
spring cloud·微服务