springboot打包成war包

时间:2021-04-05 09:35:06

1.打开pom.xml

2.将<packaging>jar</packaging> 改成 <packaging>war</packaging>

3.添加以下依赖,让打成war包的过程中不包含这个jar包

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>

</dependency>

4.添加一个类:

public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(MyspringbootdemoApplication.class);//这是你的Application类
    }

}

5.在pom.xml同一目录下打包

mvn clean package  -Dmaven.test.skip=true

最后在target目录下生成:项目名+版本号.war文件。