SpringBoot 如何手动引入本地的jar包 并利用maven成功打包

背景:

 最近公司需要做一个两个系统之前的桥梁 需要用到 甲方爸爸提供的一些jar包 而这些jar包是甲方爸爸自己公司封装的 没有放在maven上 需要我本地引入  我的项目是SpringBoot构建的   在我本地能跑起来 但是打成jar包部署的时候,项目能跑,但是到关键的调用接口的时候就报Java.ClassNofFoundException错误 很无奈 后面找到了原因  是因为打包的时候 甲方爸爸提供的jar包maven打包的时候 没有打包进去  检查了好久 原来还是SpringBoot的原因 唉 还是太年轻 后面 看了下SpringBoot 引入本地jar包的方法 分享一下

 

新手上路 大神勿喷哈

 

首先

1.在resources下面新建lib文件夹,并把jar包文件放到这个目录下 

 

SpringBoot 如何手动引入本地的jar包 并利用maven成功打包

2.在pom文件定义几个依赖指向刚才引入的文件


          <dependency> 
            <groupId>com.sap.security.api</groupId>  
            <artifactId>secutil</artifactId>  
            <version>0.0.1</version>  
            <scope>system</scope>  
            <systemPath>${project.basedir}/src/main/resources/lib/com.sap.security.api.jar
            </systemPath>
        </dependency>
  
              <dependency> 
            <groupId>com.sap.security.core</groupId>  
            <artifactId>secutil</artifactId>  
            <version>0.0.1</version>  
            <scope>system</scope>  
            <systemPath>${project.basedir}/src/main/resources/lib/com.sap.security.core.jar
            </systemPath>
        </dependency>
        
        <dependency> 
            <groupId>com.sap.sso</groupId>  
            <artifactId>secutil</artifactId>  
            <version>0.0.1</version>  
            <scope>system</scope>  
            <systemPath>${project.basedir}/src/main/resources/lib/com.sap.sso.jar
            </systemPath>
        </dependency>
  
          <dependency> 
            <groupId>iaik_jce</groupId>  
            <artifactId>secutil</artifactId>  
            <version>0.0.1</version>  
            <scope>system</scope>  
            <systemPath>${project.basedir}/src/main/resources/lib/iaik_jce.jar
            </systemPath>
        </dependency>
        
            <dependency> 
            <groupId>sap.logging</groupId>  
            <artifactId>secutil</artifactId>  
            <version>0.0.1</version>  
            <scope>system</scope>  
            <systemPath>${project.basedir}/src/main/resources/lib/sap.logging.jar
            </systemPath>
        </dependency>

注意:重点是systemPath这个路径必须得是你jar的路径。其他的按照套路填就行,要求不是太严格。${project.basedir}只是一个系统自己的常量,不用管它

 

项目打包 同时把本地jar包也引入进去

直接在maven的pom里给springboot的打包插件引入一下参数就行

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

好了 打包完成