maven的<includeSystemScope> 打包的第三方lib包

maven的 实现把我们项目中src\main\resources\lib下自己使用的第三方lib打包

在sprinboot项目中pom.xml文件加true,代表maven打包时会将外部引入的jar包(比如在根目录下或resource文件下新加外部jar包)打包到项目jar,在服务器上项目才能运行,不加此配置,本地可以运行,因为本地可以再lib下找到外部包,但是服务器上jar中是没有的。

例子:
我都项目下的\resources\lib下存放了好几个第三方的jar包

在这里插入图片描述

用法:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>zy.opne</groupId>
    <artifactId>zycx</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>zycx</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </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>


结果:解压打出来的jar可以发现:
在这里插入图片描述

### 配置 `spring-boot-maven-plugin` 支持 system 范围依赖 在 Maven 构建工具中,`system` 范围的依赖通常用于指定本地文件系统的库路径。然而,默认情况下,Maven 的构建生命周期不会自动处理这些依赖项。为了使 `spring-boot-maven-plugin` 处理 `system` 范围的依赖,可以通过自定义插件配置来实现。 以下是具体的配置方法以及示例: #### 插件配置示例 通过设置 `<configuration>` 中的参数 `includeSystemScope=true` 来启用对 `system` 范围依赖的支持。需要注意的是,此功能并非默认开启,因此需要显式声明该选项。 ```xml <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <!-- 启用 system 范围依赖 --> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> </plugins> </build> <!-- 定义一个 system 范围的依赖 --> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>example-library</artifactId> <version>1.0.0</version> <scope>system</scope> <systemPath>${project.basedir}/libs/example-library.jar</systemPath> </dependency> </dependencies> ``` 上述配置中,`<includeSystemScope>` 参数被设置为 `true`[^4],从而允许 `spring-boot-maven-plugin` 将 `system` 范围的依赖纳入最终的可执行 JAR 文件中。 #### 使用场景说明 当项目中有某些特定的库无法通过公共仓库获取时(例如公司内部私有库),可以将其放置在项目的某个固定位置,并通过 `system` 范围引入。这种做法虽然不推荐作为长期解决方案,但在特殊需求下非常实用。 #### 打包后的目录结构调整 如果希望进一步调整打包后的目录结构(如将配置文件、第三方依赖等分离到不同子目录),则需结合 `maven-assembly-plugin` 或其他相关插件完成更复杂的定制化操作[^2]。具体实现方式已在引用材料中有所提及。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

超人在良家-阿启

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值