maven项目如何引入项目本地jar包

目录

背景

由于项目需要,对jar包中的内容进行了一点改变,但是由于不熟悉公司maven仓库发布流程,所以就把jar包放到了项目中,那就需要将本地jar包交给maven管理

操作

在项目中新建目录lib,然后将jar包放在其中,比如我的jar包名称是:spire.doc.free-5.2.0.jar,如下所示:

在这里插入图片描述

然后在pom.xml中的dependencies标签里面添加如下标签即可:

<dependency>
	<!-- 模块原有groupId -->
    <groupId>e-iceblue</groupId>
	<!-- 模块原有artifactId -->
    <artifactId>spire.doc.free</artifactId>
	<!-- 模块原有version -->
    <version>5.2.0</version>
	<!-- 系统依赖范围,往往与本机绑定,不过我本次和项目中的jar包进行了绑定 -->
    <scope>system</scope>
	<!-- 本地jar包绝对路径,${
    
    project.basedir}是项目所在路径,lib是我们新建的目录,spire.doc.free-5.2.0.jar是jar包名称 -->
    <systemPath>${
    
    project.basedir}/lib/spire.doc.free-5.2.0.jar</systemPath>
</dependency>

由于上述依赖的scope属性是system(系统依赖范围),该依赖范围只在编译、测试时有效,但是在运行时无效,详细解释请看:《Maven实战》P64 表5-1“依赖范围与classpath的关系”

对于springboot项目来说,如果在打包时想要将scope属性为system的jar包打包,那就需要在pom.xml中添加以下配置:

注意:以下为pom.xml文件中的配置
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <!-- start 允许引入本地jar包 -->
            <configuration>
                <includeSystemScope>true</includeSystemScope>
            </configuration>
            <!-- end 允许引入本地jar包 -->
        </plugin>
        ……
    </plugins>
    ……
</build>

猜你喜欢

转载自blog.csdn.net/qq_42449963/article/details/131496049