5.1.方式1:通过jar包发布
步骤1:在pom中添加一个SpringBoot的构建的插件
XML
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<!--自动检测项目中的 main 函数-->
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
步骤2:在maven视图中,选择"package",在target中会产生xxx.jar包

步骤3:然后在jar包项目文件位置使用cmd终端发布项目
java -jar xxx.jar

5.2.方式2:通过war包发布
步骤1:在pom.xml文件中将jar修改为war
XML
<packaging>war</packaging>
步骤2:设置tomcat启动器依赖范围
maven依赖范围参考:资料/maven依赖作用范围.png
XML
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--tomcat启动器依赖范围-->
<scope>provided</scope>
</dependency>
步骤3:设置war包的名字
XML
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>hello</warName>
</configuration>
</plugin>
步骤4:修改启动类
java
package com.by;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
* @SpringBootApplication:
* 1、标识当前类是springboot的启动类
* 2、并把启动类所在包当作要扫描的包
*/
@SpringBootApplication
public class App extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(App.class);
}
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
步骤5:将打包后的war包放入tomcat的webapps文件中

在tomcat的bin文件中点击startup.bat运行

运行成功后会在tomcat的webapps文件中出现一个相同名字的文件
