欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring Boot 引用本地jar包

程序员文章站 2024-02-07 22:35:52
...

        Spring Boot 的项目常用maven管理jar包,并使用maven将项目打成可部署或运行的包,此篇主要介绍在springboot maven项目中如何将自己本地的jar包添加到项目中。

1、与src平级创建文件夹“lib”(后续直接对该文件夹操作,若读者的文件夹不同,则后续篇幅中直接把lib的位置换成你自己的文件夹就可以了)

2、将本地jar包拷贝到lib目录下

3、在工程的Libraries中引入lib目录

Spring Boot 引用本地jar包

Spring Boot 引用本地jar包

Spring Boot 引用本地jar包

4修改maven配置文件pom.xml

<build>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>2.3.2</version>
         <configuration>
            <encoding>UTF-8</encoding>
            <source>1.8</source>
            <target>1.8</target>
            <compilerArguments>
               <extdirs>${project.basedir}/lib</extdirs>
            </compilerArguments>
         </configuration>
      </plugin>
      <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
         <version>3.0.0</version>
      </plugin>
      <plugin>
         <groupId>org.mybatis.generator</groupId>
         <artifactId>mybatis-generator-maven-plugin</artifactId>
         <version>1.3.5</version>
         <configuration>
            <verbose>true</verbose>
            <overwrite>false</overwrite>
         </configuration>
         <executions>
         </executions>
         <dependencies>
            <dependency>
               <groupId>mysql</groupId>
               <artifactId>mysql-connector-java</artifactId>
               <version>5.1.41</version>
            </dependency>
         </dependencies>
      </plugin>
   </plugins>

   <resources>
      <resource>
         <directory>lib</directory>
         <targetPath>BOOT-INF/lib/</targetPath>
         <includes>
            <include>**/*.jar</include>
         </includes>
      </resource>
      <resource>
         <directory>src/main/resources</directory>
         <includes>
            <include>*.yml</include>
            <include>**/*.xml</include>
         </includes>
      </resource>
   </resources>
</build>