Springboot引入外部jar包并打包jar包

发布于:2024-04-19 ⋅ 阅读:(29) ⋅ 点赞:(0)

前言

spring boot项目开发过程中难免需要引入外部jar包,下面将以idea为例说明操作步骤

将需要的jar包导入到项目中

2.在maven中引入jar包

<dependency>
    <groupId>com</groupId><!--随便填的文件夹名称-->
    <artifactId>xxx</artifactId><!--jar包名字-->
    <version>1.8.1</version><!--版本号-->
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/lib/xxx-1.8.1.jar</systemPath><!--路径-->
</dependency>
<dependency>
            <groupId>com.doudian</groupId>
            <artifactId>doudian-sdk-java</artifactId>
            <scope>system</scope>
            <version>1.1.0-20240411151521</version>
            <systemPath>${project.basedir}/src/main/resources/lib/doudian-sdk-java-1.1.0-20240411151521.jar</systemPath>
        </dependency>


<!--注意:重点是systemPath这个路径必须得是你jar的路径。${project.basedir}只是一个系统自己的常量-->
3.项目打包设置pom文件

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!--这里写上main方法所在类的路径-->
                <configuration>
                    <mainClass>com.xxx.xxx.xxxApplication</mainClass>
                    <includeSystemScope>true</includeSystemScope><!--外部进行打包-->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal><!---->
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
 <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.5.15</version>
                <configuration>
                    <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

参考链接:springboot引入外部jar包并打包jar包_springboot 子模块引用外部jar包如何打包-CSDN博客

https://www.cnblogs.com/stm32stm32/p/9973325.html


网站公告

今日签到

点亮在社区的每一天
去签到