需求出现背景

联合第三方进行开发时,有部分第三方私有的jar需要引入项目,而在我方maven仓库内并没有

法一 add as library

直接在lib目录上右键
在这里插入图片描述
然后本地第三方的类就不会报错了。

但是,即使你用git提交代码。其他人还需要重复一遍这个操作。麻烦!

法二 maven 打包外部jar包

1.dependency 配置

首先在pom.xml的dependencies目录下添加jar包的依赖信息:

<dependency>
            <groupId>pay-common</groupId> <!--    自定义        -->
            <artifactId>pay-common</artifactId>  <!--    自定义        -->
            <version>1.0</version> <!--    自定义        -->
            <scope>system</scope>  
            <systemPath>${basedir}/lib/third-pay-common.jar</systemPath>
</dependency>
            

但是scope要写system,然后systemPath就是上面jar包的路径
你可以点击 ${basedir} ,以确定目录层级

在这里插入图片描述

2. 配置打包插件

第一种配置方法

    <build>
        <plugins>
            <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}/lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

第二种配置方法

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <!--本地jar包一并打入-->
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>

完美解决!

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐