个人技术分享

springboot项目中,如果手动引入了jar包,打包时不会将手动引入的第三方jar包打包进价包里,如何处理?

若第三方的jar包的lib和src同级,则maven打包时默认不会将lib下的jar包打包进jar包,处理方式有两种:

方式一:

1.pom.xml文件中引入lib下的第三方jar包的依赖

其中groupId、artifactId、version自己随意填的。scope需要填写system,systemPath需要填写你项目中第三方Jar的位置。${basedir}代表了你这个项目的根目录。

<dependency>
        <groupId>your_organization</groupId>
        <artifactId>your_project_name</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/spring-swing-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>

2.还需在pom.xml里的build之中加入plugin。plugin的groupId和artifactId如下面所示。要加入configuration,里面加入includeSystemScope,值为true,就是要包含scope为system的第三方Jar包。如果不加,则scope为system的第三方Jar包,只会在编译环节起作用,运行时则找不到依赖,system的scope类似于provided,所以必须要加

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

                        <configuration>
                                <includeSystemScope>true</includeSystemScope>
                        </configuration>
                </plugin>
        </plugins>
</build>

方式二:

将第三方jar包的lib目录放在resources下,maven打包时就会将lib下的jar包打包进jar包