SpringBoot引入本地jar包,打包后也可以

i'm Shendi

记录一下,简单的几步

我们将jar包复制到项目中

一般为resources下,在哪都行,只要在项目内,比如项目根目录

在 pom.xml 中引入

<dependency>
    <groupId>随便填</groupId>
    <artifactId>随便填</artifactId>
    <version>随便填</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/你jar在项目中的位置</systemPath>
</dependency>

其中 systemPath是代表 jar 包位置, 里面的 ${project.basedir} 代表项目根目录.

例如我项目 根目录下有lib目录, 并且里面有个jar为 jdbc.jar,那么我systemPath就为

<systemPath>${project.basedir}/lib/jdbc.jar</systemPath>

现在已经可以让项目直接运行了.

但是打包运行还不可以,还需要给 SpringBoot的打包插件配置 includeSystemScope 为  true

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

猜你喜欢

转载自blog.csdn.net/qq_41806966/article/details/106799984