网站首页 > 博客文章 正文
环境:springboot2.3.10
常规建立springboot项目
依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.10.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
通常建立springboot项目时pom.xml文件中的parent都是上面那样
如果项目是个老项目已经有了parent该如何使用呢?通过如下依赖管理。
依赖管理引用
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.10.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
接下来就可以根据需要引入springboot相关的包了
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
dependency中scope说明
- compile
默认的依赖范围就是compile,没有scope或者scope为comile的依赖表示编译、运行、测试的时候都需要这个依赖的jar包。
- provided
表示环境已经提供了,所以打包的时候就不会将scope为provided的依赖打到输出的jar包中。
- runtime
如果一个依赖的scope为runtime,表示编译的时候不能引用这个依赖的jar包。
还有编译的时候不需要运行的时候需要的jar包?
- test
scope为test的依赖表示,这个包只是在测试阶段使用,打包的时候这些依赖不会打在输出的jar包中。
- system
system主要是为了引入一些没有通过maven发布的私有的三方jar包。
- import
import只能在dependencyManagement的dependency,并且type为pom的依赖中使用。
import主要是为了将依赖管理和依赖定义分开。
例如SpringBoot的dependencyManagement中预定义很多依赖,所以就单独弄了一个spring-boot-dependencies来管理这些依赖。
- optional
optional是用于控制依赖传递的。
optional设置为true,这个依赖不会被传递,假如在A项目中添加了这个依赖,B项目依赖A,但是B项目不会依赖spring-boot-devtools。
打包分离jar包
pom.xml
<build>
<plugins>
<!-- 打jar包的插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
<mainClass>com.pack.SpringBootFeignApplication</mainClass>
</manifest>
<manifestEntries>
<Class-Path>./</Class-Path>
</manifestEntries>
</archive>
<excludes>
<exclude>config/**</exclude>
</excludes>
</configuration>
</plugin>
<!-- 配置将jar包和外部配置等文件整体打包 -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!--jar包名称 -->
<finalName>${project.artifactId}-${project.version}</finalName>
<!--描述文件路径 -->
<descriptors>
<descriptor>src/main/resources/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-zip</id>
<!-- 绑定到package生命周期阶段上 -->
<phase>package</phase>
<goals>
<!-- 只运行一次 -->
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
在src/main/resources新建assembly/assembly.xml文件
执行打包
mvn clean package -Dmaven.test.skip=true
target下生成了
压缩包,解压:
运行jar包是否正常
java -jar spring-boot-feign-1.0.0.jar
一切正常!!
完毕!!!!
给个关注呗谢谢
- 上一篇: 你确定 Maven 相关的东西全部了解吗
- 下一篇: Android6.0运行时权限的处理及解决办法
猜你喜欢
- 2024-10-01 你确定 Maven 相关的东西全部了解吗
- 2024-10-01 史上最详细最清晰的SpringBoot项目打包方法
- 2024-10-01 bundlejs:前端不容错过的 esbuild 在线打包器
- 2024-10-01 深入Spring Boot (十四):打包解决方案
- 2024-10-01 草率了,又一个Maven打包的问题(maven shade打包)
- 2024-10-01 Maven是什么?它打包的三种方式?(maven项目的打包方式)
- 2024-10-01 Spring Boot另类的打包方式(springboot项目打包war包)
你 发表评论:
欢迎- 07-07Xiaomi Enters SUV Market with YU7 Launch, Targeting Tesla with Bold Pricing and High-Tech Features
- 07-07Black Sesame Maps Expansion Into Robotics With New Edge AI Strategy
- 07-07Wuhan's 'Black Tech' Powers China's Cross-Border Push with Niche Electronics and Scientific Firepower
- 07-07Maven 干货 全篇共:28232 字。预计阅读时间:110 分钟。建议收藏!
- 07-07IT运维必会的30个工具(it运维工具软件)
- 07-07开源项目有你需要的吗?(开源项目什么意思)
- 07-07自动化测试早就跑起来了,为什么测试管理还像在走路?
- 07-07Cursor 最强竞争对手来了,专治复杂大项目,免费一个月
- 最近发表
-
- Xiaomi Enters SUV Market with YU7 Launch, Targeting Tesla with Bold Pricing and High-Tech Features
- Black Sesame Maps Expansion Into Robotics With New Edge AI Strategy
- Wuhan's 'Black Tech' Powers China's Cross-Border Push with Niche Electronics and Scientific Firepower
- Maven 干货 全篇共:28232 字。预计阅读时间:110 分钟。建议收藏!
- IT运维必会的30个工具(it运维工具软件)
- 开源项目有你需要的吗?(开源项目什么意思)
- 自动化测试早就跑起来了,为什么测试管理还像在走路?
- Cursor 最强竞争对手来了,专治复杂大项目,免费一个月
- Cursor 太贵?这套「Cline+OpenRouter+Deepseek+Trae」组合拳更香
- 为什么没人真的用好RAG,坑都在哪里? 谈谈RAG技术架构的演进方向
- 标签列表
-
- ifneq (61)
- 字符串长度在线 (61)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)