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>
相关推荐
太阳伞下的阿呆11 小时前
排查定位jar包大文件
java·centos·jar
MyY_DO12 小时前
maven mysql jdk nvm node npm 环境安装
java·mysql·maven
拾忆,想起17 小时前
如何选择Spring AOP的动态代理?JDK与CGLIB的适用场景
spring boot·后端·spring·spring cloud·微服务
zhuyasen17 小时前
多维度详细比较 kratos、go-zero、goframe、sponge 框架
后端·http·微服务·rpc·golang
掘金-我是哪吒19 小时前
分布式微服务系统架构第90集:现代化金融核心系统
分布式·微服务·金融·架构·系统架构
程序猿零零漆1 天前
SpringCloud系列教程:微服务的未来(十九)请求限流、线程隔离、Fallback、服务熔断
java·spring cloud·微服务
刘大浪2 天前
如何获取Springboot项目运行路径 (idea 启动以及打包为jar均可) 针对无服务器容器新建上传文件路径(适用于win 与 linunix)
spring boot·intellij-idea·jar
小小工匠2 天前
DDD - 领域事件_解耦微服务的关键
微服务·领域事件
掘金-我是哪吒2 天前
分布式微服务系统架构第89集:kafka消费者
分布式·微服务·架构·kafka·系统架构
字节全栈_PVK2 天前
微服务配置中心 Apollo解析——Portal 关联 Namespace
java·前端·微服务