At work, I encountered a java web project built with the springboot framework that needed to integrate third-party push functions, so I used the Xiaomi push service and downloaded the relevant jar package. Introducing local jars into the project is not a big problem. After writing the code, it is no problem to pass the test class test. Then prepare to package and deploy to the development server. Since the project is deployed through tomcat, the packaging method is into a war package. After packaging, upload it to the development server. After successful startup, I went to test the written push interface and found that it failed.
Through analysis, we found that there are no push-related jar packages introduced locally in the lib directory where the project-dependent jars are stored in the packaged war. After struggling for half an hour, the problem was solved. After solving it, I discovered that I had actually forgotten the basic knowledge of maven. Here is a summary of how the springboot project introduces local jar packages and how to package the jars into the lib folder through maven packaging:
Note: Since the local jar is imported here,
<dependency> ... <!-- 表示当前jar是外部引入的,maven不会在repository查找它 --> <scope>system</scope> <!-- 指定引入的外部jar存放的路径,一般将jar包放在项目的某个目录下,通过相对路径指定 --> <systemPath>...</systemPath> </dependency>
<build> <finalName>xxxxxx</finalName> <plugins> <!--配置将第三方jar打进jar包中,跟<packaging>jar</packaging>配合,如果不写,springboot默认是打成jar包--> <!--<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- 项目中单独引入第三方jar时,includeSystemScope值要为true <includeSystemScope>true</includeSystemScope> </configuration> </plugin>--> <!-- 打war包 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> <configuration> <webResources> <!-- 配置将第三方jar打进war包中,跟<packaging>war</packaging>配合 --> <webResource> <directory>${pom.basedir}/src/main/resources/lib/</directory> <targetPath>WEB-INF/lib/</targetPath> <includes> <include>**/*.jar</include> </includes> </webResource> </webResources> </configuration> </plugin> </plugins> </build>
The above is the detailed content of How to introduce local dependency jar package into springboot project and package it into lib folder. For more information, please follow other related articles on the PHP Chinese website!