maven项目中引入本地jar包及maven打包

引入

1、在项目选择一个目录用于存放xxx.jar包

2、在pom添加如下配置:

<dependency>
    <groupId>cn.com.sand</groupId>
    <artifactId>hmpay-sdk</artifactId>
    <version>1.1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/lib/hmpay-sdk-1.1.0.jar</systemPath>
</dependency>

groupId、artifactId、version 可以根据情况自行随意配置

scope必须为system

systemPath为项目中jar包存放的相对路径

3、在pom添加包含本地scope的配置

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

打包

在pom文件中添加plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <encoding>UTF-8</encoding>
        <compilerArguments>
            <extdirs>${project.basedir}/src/main/resources/lib</extdirs>
        </compilerArguments>
    </configuration>
</plugin>

extdirs要添加到打包的目录

原文地址:https://www.cnblogs.com/fightingtong/p/14187884.html