IDEA打包war包并发布到服务器上
1、首先修改pom.xml
1、添加打包方式,打包成war包,否则打包成jar包
<packaging>war</packaging>
2、在spring-boot-starter-web添加tomcat
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.3.1.RELEASE</version><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions></dependency>
3、导入tomcat的版本,注意是服务器的tomcat
<dependency><groupId>org.apache.tomcat</groupId><artifactId>tomcat-servlet-api</artifactId><version>9.0.37</version><scope>provided</scope></dependency>
2、修改启动类
@SpringBootApplication
public class SpringbootCrudApplication extends SpringBootServletInitializer {@Overrideprotected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {return builder.sources(SpringbootCrudApplication.class);}public static void main(String[] args) {SpringApplication.run(SpringbootCrudApplication.class, args);}}
3、删除的项目中target中的内容,这些为历史的东西,不删除不能保证项目打包的是最新的内容。
4、在IDEA中点击右侧的maven,然后双击package
打包好后会在target文件下出现war包