Maven项目中引入本地jar(没有坐标)方法

在项目开发中,需要调用第三方接口,第三方公司给了一个sdk(java版)的jar包,说可以引用jar里的类,有了sdk的确方便,但我们maven项目中的jar包都是通过maven坐标引入的,他这个孤零零的jar包如何引入到项目中,有以下两种方案。

方案一:项目中导入jar,pom.xml中添加相关配置

1、在项目中导入jar,我是在/src/main/resources目录新建libs目录,将oop-open-sdk-java-1.0.24.jar复制到该目录。

2、在pom.xml中,添加如下配置

1)引入jar

        <dependency>
            <groupId>com.oop.sdk</groupId>
            <artifactId>oop-sdk-java</artifactId>
            <version>1.0.24</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/libs/oop-open-sdk-java-1.0.24.jar</systemPath>
        </dependency>

2)配置打包时引入该jar。

这里分两种情况,如果项目是打成war包,添加以下红色字体配置

    <build>
        <finalName>erp</finalName>
        <resources>
            <resource>
                <directory>src\main\resources</directory>
                <includes>
                    <include>**</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp</directory>
                            <includes>
                                <include>**/web.xml</include>
                            </includes>
                        </resource>
                        <resource>
                            <directory>${project.basedir}/src/main/resources/libs</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                    <warSourceDirectory>src/main/webapp</warSourceDirectory>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

如果是打成jar包,引入以下配置

        <plugin>
            <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <executions>
                 <execution>
                     <goals>
                         <goal>repackage</goal>
                     </goals>
                 </execution>
             </executions>
             <configuration>
                 <includeSystemScope>true</includeSystemScope>
             </configuration>
        </plugin>

注意:如果项目中很多模块,引入的jar在A模块中使用,而web模块会依赖所有模块的话,确保(1)中配置是在A模块的pom.xml中,而(2)在web模块,并且directory元素要指定到正确的路径,
例如${project.basedir}/../a/src/main/resources/libs

参考文章:https://blog.csdn.net/m0_67391907/article/details/123986803

posted on 2022-11-10 15:59  阿泰555  阅读(279)  评论(0编辑  收藏  举报

导航