Springboot项目打包如何将依赖的jar包输出到指定目录
作者:飞翔的佩奇
公司要对springboot项目依赖的jar包进行升级,但是遇到一个问题,项目打包之后,没办法看到他里面依赖的jar包,版本到底是不是升上去了,没办法看到,下面通过本文给大家分享Springboot项目打包如何将依赖的jar包输出到指定目录,感兴趣的朋友一起看看吧
场景
公司要对springboot项目依赖的jar包进行升级,但是遇到一个问题,项目打包之后,没办法看到他里面依赖的jar包,版本到底是不是升上去了,没办法看到。
下面是项目打的jar包
我们通过反编译工具jdgui,来看一下jar包文件内容,我们发现里面根本没有看到依赖的jar包
既然看不到依赖的jar包,那么就没办法确定,jar包版本是否升级成功,那应该怎么办呢?
解决办法
maven有一个办法,就是可以将依赖的jar包输出的指定的目录。具体配置如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.hidata.kafka</groupId> <artifactId>hijob-kafka</artifactId> <version>0.1</version> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.7.18</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <bboss.version>5.8.6</bboss.version> </properties> <dependencies> <!-- spring boot --> <dependency> ..... </dependency> </dependencies> <build> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>static/**</exclude> </excludes> </resource> <resource> <directory>${project.basedir}/src/main/resources</directory> <filtering>false</filtering> <includes> <include>static/**</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.hidata.kafka.HijobKafkaApplication</mainClass> <layout>ZIP</layout> <includes> <include> <groupId>nothing</groupId> <artifactId>nothing</artifactId> </include> </includes> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>7</source> <target>7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依赖jar包的输出目录,根据自己喜好配置--> <outputDirectory>target/lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
重要的事再说一遍,其实核心就是这一句配置
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依赖jar包的输出目录,根据自己喜好配置--> <outputDirectory>target/lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin>
我们再打包一下看看效果:
我们发现target多了一个文件夹lib,其实他就是存放项目所依赖的jar包的。打开lib文件夹,发现里面全部都是jar包
这样就可以知道,jar包的版本到底有没有升级成功了。
到此这篇关于Springboot项目打包:将依赖的jar包输出到指定目录的文章就介绍到这了,更多相关Springboot项目依赖jar包内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!