Maven使用本地jar包(三种方式)

有些项目会用到一些Maven库上没有的jar包,这就需要我们自己引入了

这种情况有两种办法:

第一种方式,在pom文件中引用时使用本地路径:

首先把jar包放到项目中:

然后在pom文件中引入:

        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>sdk.core</artifactId>
            <version>3.3.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/aliyun-java-sdk-core-3.3.1.jar</systemPath>
        </dependency>

注意:

1.添加 <scope>system</scope>

2.systemPath这个路径是jar包的路径。${project.basedir}只是一个系统自己的常量。

3.使用这种方式,在将项目用Maven打包是需要在 <plugin> 标签中加入:

                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>

也就是:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>

第二种方式,使用maven将jar包加入到.m2下的repository路径中

mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -DartifactId=上面的artifactId -Dversion=上面的version -Dpackaging=jar

这种方式需要电脑上安装并配置了maven

第三种方式 使用IDE工具直接添加本地jar包

IDEA:

通过Modules的Dependencies添加

点击右边绿色 + 号

然后选择地址即可

原文地址:https://www.cnblogs.com/jiangwz/p/8808829.html