首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用Maven构建的Springboot父子工程的项目打包部署

使用Maven构建的Springboot父子工程的项目打包部署

作者头像
别先生
发布2020-10-30 10:37:32
1.9K0
发布2020-10-30 10:37:32
举报
文章被收录于专栏:别先生别先生

1、SpringBoot作为微架构的主要实现技术,其发布项目的方式极为简单,只需要在项目中配置好插件,然后打包执行就可以了,并且这个执行不需要特别复杂的配置。

首先,修改pom.xml配置文件,配置SpringBoot的打包插件。

 1 <?xml version="1.0"?>
 2 <project
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
 4     http://maven.apache.org/xsd/maven-4.0.0.xsd"
 5     xmlns="http://maven.apache.org/POM/4.0.0"
 6     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 7     <modelVersion>4.0.0</modelVersion>
 8 
 9     <parent>
10         <groupId>com.bie</groupId>
11         <artifactId>springboot-base</artifactId>
12         <version>0.0.1-SNAPSHOT</version>
13     </parent>
14 
15     <!-- 父项目已经指定,这里可以省略 -->
16     <!-- <groupId>com.bie</groupId> -->
17     <artifactId>springboot-tentent</artifactId>
18     <!-- <version>0.0.1-SNAPSHOT</version> -->
19     <name>springboot-tentent</name>
20     <url>http://maven.apache.org</url>
21 
22     <properties>
23         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24     </properties>
25 
26     <dependencies>
27         <dependency>
28             <groupId>org.springframework.boot</groupId>
29             <artifactId>spring-boot-starter-web</artifactId>
30         </dependency>
31         <dependency>
32             <groupId>org.springframework.boot</groupId>
33             <artifactId>spring-boot-starter-test</artifactId>
34             <scope>test</scope>
35         </dependency>
36         <dependency>
37             <groupId>junit</groupId>
38             <artifactId>junit</artifactId>
39             <scope>test</scope>
40         </dependency>
41         <dependency>
42             <groupId>org.springframework.boot</groupId>
43             <artifactId>spring-boot-starter-jetty</artifactId>
44         </dependency>
45     </dependencies>
46 
47     <build>
48         <plugins>
49             <!-- 该插件的主要功能是进行项目的打包发布处理 -->
50             <plugin>
51                 <groupId>org.springframework.boot</groupId>
52                 <artifactId>spring-boot-maven-plugin</artifactId>
53                 <!-- 设置程序执行的主类 -->
54                 <configuration>
55                     <mainClass>org.springboot.tentent.Springboot01Application</mainClass>
56                 </configuration>
57                 <executions>
58                     <execution>
59                         <goals>
60                             <goal>repackage</goal>
61                         </goals>
62                     </execution>
63                 </executions>
64             </plugin>
65         </plugins>
66     </build>
67 
68 </project>

由于Maven增加了新的插件配置,所以需要对项目进行更新Maven - Update Porject。

将当前项目模块进行打包处理(clean package),打包完成后,会在项目的target目录下生成xxx.jar程序文件,如下所示:

打包完成后,会在项目的target目录下生成xxx.jar程序文件,需要刷新一下项目的哦,就可以看到该jar包了,如下所示:

此时使用java -jar xxx.jar包,此时,SpringBoot项目将以一个独立的*.jar文件的方式执行。

使用浏览器访问,也是正常访问的,如下所示:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-10-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档